Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function get_titles($params = array())
- {
- if ( ! isset($params['titles_ids']))
- {
- $this->db->select('titles.title_id');
- }
- if ( ! isset($params['title_names']))
- {
- $this->db->select('titles.title_name');
- }
- if ( ! isset($params['title_directory_names']))
- {
- $this->db->select('titles.title_directory_name');
- }
- if ( ! isset($params['title_status_ids']))
- {
- $this->db->select('titles.title_status_id');
- }
- if ( ! isset($params['title_sort_order_ids']))
- {
- $this->db->select('titles.title_sort_order');
- }
- $this->db->from('titles');
- //checking to see if any $params are attempting to be passed
- if(count($params) > 0)
- {
- //start title specific selection
- if (isset($params['title_ds']))
- {
- //passed multiple ids.
- //eg $params['title_ids'] = array(0, 2);
- if (is_array($params['title_ids']))
- {
- $a = 0;
- foreach($params['title_ids'] as $title_id)
- {
- if ($a == 0)
- {
- $this->db->where('titles.title_id', $title_id);
- }
- else
- {
- $this->db->or_where('titles.title_id', $title_id);
- }
- $a++;
- }
- }
- else
- {
- //if you only used a string with a single digit.
- if (is_numeric($params['title_ids']))
- {
- $this->db->where('titles.title_id', $params['title_ids']);
- }
- }
- }
- //end title specific selection
- //start title status types specific selection
- if (isset($params['title_status_ids']))
- {
- //passed multiple title status ids.
- //eg $params['title_status_ids'] = array(0, 2);
- if (is_array($params['title_status_ids']))
- {
- $a = 0;
- foreach($params['title_status_ids'] as $status_id)
- {
- if ($a == 0)
- {
- $this->db->where('titles.title_status_id', $status_id);
- }
- else
- {
- $this->db->or_where('titles.title_status_id', $status_id);
- }
- $a++;
- }
- }
- else
- {
- //if you only used a string with a single digit.
- if (is_numeric($params['title_status_ids']))
- {
- $this->db->where('titles.title_status_id', $params['title_status_ids']);
- }
- }
- }
- //end title status types specific selection
- //start titles sort_order specific selection
- if (isset($params['title_sort_order_ids']))
- {
- //passed multiple title sort_order ids.
- //eg $params['title_sort_ordder_ids'] = array(0, 2);
- if (is_array($params['title_sort_order_ids']))
- {
- foreach ($params['title_sort_order_ids'] as $title_sort_order_id)
- {
- $this->db->where('titles.title_sort_order', $title_sort_order_id);
- }
- }
- else
- {
- //if you only used a string with a single digit.
- if (is_numeric($params['title_sort_order_ids']))
- {
- $this->db->where('titles.title_sort_order', $params['title_sort_order_ids']);
- }
- }
- }
- //end titles sort_order specific selection
- //start title name specific selection
- if (isset($params['title_names']))
- {
- //passed multiple title names.
- //eg $params['title_names'] = array('Undisputed Title', 'Outlaw Title');
- if (is_array($params['title_names']))
- {
- foreach ($params['title_names'] as $title_name)
- {
- $this->db->where('titles.title_name', $title_name);
- }
- }
- else
- {
- //if you only used a string with a single value.
- if (is_string($params['title_names']))
- {
- $this->db->where('titles.title_name', $params['title_names']);
- }
- }
- }
- //end titles names specific selection
- //start title directory names specific selection
- if (isset($params['title_directory_names']))
- {
- //passed multiple title directory names.
- //eg $params['title_names'] = array('undisputed', 'outlaw');
- if (is_array($params['title_directory_names']))
- {
- foreach ($params['title_directory_names'] as $title_directory_name)
- {
- $this->db->where('titles.title_directory_name', $title_directory_name);
- }
- }
- else
- {
- //if you only used a string with a single value.
- if (is_string($params['title_directory_names']))
- {
- $this->db->where('titles.title_directory_name', $params['title_directory_names']);
- }
- }
- }
- //end title directory names specific selection
- }
- //if no params are found query will be made for all titles in the DB regardless it would be like
- // SELECT * FROM titles;
- $query = $this->db->get();
- if ($query->num_rows() > 0)
- {
- return $query->result();
- }
- else
- {
- return false;
- }
- }
- public function get_title_statuses($params = array())
- {
- if ( ! isset($params['title_statuses']))
- {
- $this->db->select('titles.title_id');
- }
- if ( ! isset($params['title_statuses']))
- {
- $this->db->select('titles.title_id');
- }
- $this->db->select('title_statuses.title_status_id');
- $this->db->select('title_statuses.title_status_name');
- $this->db->from('title_statuses');
- //checking to see if any $params are attempting to be passed
- if(count($params) > 0)
- {
- //start title status specific selection
- if (isset($params['title_status_ids']))
- {
- if (is_array($params['title_status_ids']))
- {
- $a = 0;
- foreach($params['title_status_ids'] as $title_status_id)
- {
- $this->db->where('title_statuses.title_status_id', $title_status_id);
- }
- }
- else
- {
- //if you only used a string with a single digit.
- if (is_numeric($params['title_status_ids']))
- {
- $this->db->where('title_statuses.title_status_id', $params['title_status_ids']);
- }
- }
- }
- //end title status specific selection
- //start title status names specific selection
- if (isset($params['title_status_names']))
- {
- if (is_array($params['title_status_names']))
- {
- $a = 0;
- foreach($params['title_status_names'] as $title_status_name)
- {
- $this->db->where('title_statuses.title_status_name', $title_status_name);
- }
- }
- else
- {
- //if you only used a string with a single value.
- if (is_string($params['title_status_names']))
- {
- $this->db->where('title_statuses.title_status_names', $params['title_status_names']);
- }
- }
- }
- //end title status names specific selection
- }
- //if no params are found query will be made for all titles in the DB regardless it would be like
- // SELECT * FROM title_statuses;
- $query = $this->db->get();
- if ($query->num_rows() > 0)
- {
- return $query->result();
- }
- else
- {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement