Advertisement
Guest User

Untitled

a guest
Nov 12th, 2012
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1. /**
  2.      * get_titles function.
  3.      *
  4.      * @access public
  5.      * @param array $params (default: array();)
  6.      * possible array keys:  
  7.      * titles - either an array of titles or single title (can be title ids or title names)
  8.      * title_statuses - either an array of title statuses or a single status (can be title status_id or title status name)
  9.      *
  10.      * @return object/row/specific field value if only one title is requested
  11.      * Should return title_id, title_name, title_directory_name, title_sort_order, title_status_name for each title retrieved
  12.      */
  13.     public function get_titles($params = array())
  14.     {
  15.         $this->db->select('titles.title_id');
  16.         $this->db->select('titles.title_name');
  17.         $this->db->select('titles.title_directory_name');
  18.         $this->db->select('titles.title_sort_order');
  19.         $this->db->select('title_statuses.title_status_name');
  20.  
  21.         $this->db->from('titles');
  22.         $this->db->join('title_statuses', 'titles.title_status_id = title_statuses.title_status_id');
  23.        
  24.         //checking to see if any $params are attempting to be passed
  25.         if (count($params) > 0)
  26.         {
  27.             //start title specific selection
  28.             if (isset($params['title_ids']))
  29.             {
  30.                 //if you only have one integer.
  31.                 if (is_integer($params['title_ids']))
  32.                 {
  33.                     $this->db->where('titles.title_id', $params['title_ids']);
  34.                 }
  35.             }
  36.             else
  37.             {
  38.                 if (is_array($params['title_ids']))
  39.                 {
  40.                     foreach($params['title_ids'] as $title_id)
  41.                     {
  42.                         $this->db->where('title_id', $title_id);
  43.                     }
  44.                 }  
  45.             }
  46.         }
  47.        
  48.         $query = $this->db->get();
  49.         if ($query->num_rows() > 0)
  50.         {
  51.             return $query->row();
  52.         }
  53.         else
  54.         {
  55.             return false;
  56.         }
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement