Advertisement
Guest User

Untitled

a guest
Nov 7th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.55 KB | None | 0 0
  1. public function get_titles($params = array())
  2.     {
  3.         if ( ! isset($params['titles_ids']))
  4.         {
  5.             $this->db->select('titles.title_id');
  6.         }
  7.         if ( ! isset($params['title_names']))
  8.         {
  9.             $this->db->select('titles.title_name');
  10.         }
  11.         if ( ! isset($params['title_directory_names']))
  12.         {
  13.             $this->db->select('titles.title_directory_name');
  14.         }
  15.         if ( ! isset($params['title_status_ids']))
  16.         {
  17.             $this->db->select('titles.title_status_id');
  18.         }
  19.         if ( ! isset($params['title_sort_order_ids']))
  20.         {
  21.             $this->db->select('titles.title_sort_order');
  22.         }
  23.         $this->db->from('titles');
  24.  
  25.         //checking to see if any $params are attempting to be passed
  26.         if(count($params) > 0)
  27.         {
  28.             //start title specific selection
  29.             if (isset($params['title_ds']))
  30.             {
  31.                 //passed multiple ids.
  32.                 //eg $params['title_ids'] = array(0, 2);
  33.                 if (is_array($params['title_ids']))
  34.                 {
  35.                     $a = 0;
  36.                     foreach($params['title_ids'] as $title_id)
  37.                     {
  38.                         if ($a == 0)
  39.                         {
  40.                             $this->db->where('titles.title_id', $title_id);
  41.                         }
  42.                         else
  43.                         {
  44.                             $this->db->or_where('titles.title_id', $title_id);
  45.                         }
  46.                         $a++;
  47.                     }
  48.                 }
  49.                 else
  50.                 {
  51.                     //if you only used a string with a single digit.
  52.                     if (is_numeric($params['title_ids']))
  53.                     {
  54.                         $this->db->where('titles.title_id', $params['title_ids']);
  55.                     }
  56.                 }
  57.             }
  58.             //end title specific selection
  59.            
  60.             //start title status types specific selection
  61.             if (isset($params['title_status_ids']))
  62.             {
  63.                 //passed multiple title status ids.
  64.                 //eg $params['title_status_ids'] = array(0, 2);
  65.                 if (is_array($params['title_status_ids']))
  66.                 {
  67.                     $a = 0;
  68.                     foreach($params['title_status_ids'] as $status_id)
  69.                     {
  70.                         if ($a == 0)
  71.                         {
  72.                             $this->db->where('titles.title_status_id', $status_id);
  73.                         }
  74.                         else
  75.                         {
  76.                             $this->db->or_where('titles.title_status_id', $status_id);
  77.                         }
  78.                         $a++;
  79.                     }
  80.                 }
  81.                 else
  82.                 {
  83.                     //if you only used a string with a single digit.
  84.                     if (is_numeric($params['title_status_ids']))
  85.                     {
  86.                         $this->db->where('titles.title_status_id', $params['title_status_ids']);
  87.                     }
  88.                 }
  89.             }
  90.             //end title status types specific selection
  91.            
  92.             //start titles sort_order specific selection
  93.             if (isset($params['title_sort_order_ids']))
  94.             {
  95.                 //passed multiple title sort_order ids.
  96.                 //eg $params['title_sort_ordder_ids'] = array(0, 2);
  97.                 if (is_array($params['title_sort_order_ids']))
  98.                 {
  99.                     foreach ($params['title_sort_order_ids'] as $title_sort_order_id)
  100.                     {
  101.                         $this->db->where('titles.title_sort_order', $title_sort_order_id);
  102.                     }
  103.                 }
  104.                 else
  105.                 {
  106.                     //if you only used a string with a single digit.
  107.                     if (is_numeric($params['title_sort_order_ids']))
  108.                     {
  109.                         $this->db->where('titles.title_sort_order', $params['title_sort_order_ids']);
  110.                     }
  111.                 }
  112.             }
  113.             //end titles sort_order specific selection
  114.  
  115.             //start title name specific selection
  116.             if (isset($params['title_names']))
  117.             {
  118.                 //passed multiple title names.
  119.                 //eg $params['title_names'] = array('Undisputed Title', 'Outlaw Title');
  120.                 if (is_array($params['title_names']))
  121.                 {
  122.                     foreach ($params['title_names'] as $title_name)
  123.                     {
  124.                         $this->db->where('titles.title_name', $title_name);
  125.                     }
  126.                 }
  127.                 else
  128.                 {
  129.                     //if you only used a string with a single value.
  130.                     if (is_string($params['title_names']))
  131.                     {
  132.                         $this->db->where('titles.title_name', $params['title_names']);
  133.                     }
  134.                 }
  135.             }
  136.             //end titles names specific selection
  137.            
  138.             //start title directory names specific selection
  139.             if (isset($params['title_directory_names']))
  140.             {
  141.                 //passed multiple title directory names.
  142.                 //eg $params['title_names'] = array('undisputed', 'outlaw');
  143.                 if (is_array($params['title_directory_names']))
  144.                 {
  145.                     foreach ($params['title_directory_names'] as $title_directory_name)
  146.                     {
  147.                         $this->db->where('titles.title_directory_name', $title_directory_name);
  148.                     }
  149.                 }
  150.                 else
  151.                 {
  152.                     //if you only used a string with a single value.
  153.                     if (is_string($params['title_directory_names']))
  154.                     {
  155.                         $this->db->where('titles.title_directory_name', $params['title_directory_names']);
  156.                     }
  157.                 }
  158.             }
  159.             //end title directory names specific selection
  160.         }
  161.  
  162.         //if no params are found query will be made for all titles in the DB regardless it would be like
  163.         // SELECT * FROM titles;
  164.  
  165.         $query = $this->db->get();
  166.         if ($query->num_rows() > 0)
  167.         {
  168.             return $query->result();
  169.         }
  170.         else
  171.         {
  172.             return false;
  173.         }
  174.     }
  175.  
  176.     public function get_title_statuses($params = array())
  177.     {
  178.         if ( ! isset($params['title_statuses']))
  179.         {
  180.             $this->db->select('titles.title_id');
  181.         }
  182.         if ( ! isset($params['title_statuses']))
  183.         {
  184.             $this->db->select('titles.title_id');
  185.         }
  186.         $this->db->select('title_statuses.title_status_id');
  187.         $this->db->select('title_statuses.title_status_name');
  188.         $this->db->from('title_statuses');
  189.         //checking to see if any $params are attempting to be passed
  190.         if(count($params) > 0)
  191.         {
  192.             //start title status specific selection
  193.             if (isset($params['title_status_ids']))
  194.             {
  195.                 if (is_array($params['title_status_ids']))
  196.                 {
  197.                     $a = 0;
  198.                     foreach($params['title_status_ids'] as $title_status_id)
  199.                     {
  200.                         $this->db->where('title_statuses.title_status_id', $title_status_id);
  201.                     }
  202.                 }
  203.                 else
  204.                 {
  205.                     //if you only used a string with a single digit.
  206.                     if (is_numeric($params['title_status_ids']))
  207.                     {
  208.                         $this->db->where('title_statuses.title_status_id', $params['title_status_ids']);
  209.                     }
  210.                 }
  211.             }
  212.             //end title status specific selection
  213.            
  214.             //start title status names specific selection
  215.             if (isset($params['title_status_names']))
  216.             {
  217.                 if (is_array($params['title_status_names']))
  218.                 {
  219.                     $a = 0;
  220.                     foreach($params['title_status_names'] as $title_status_name)
  221.                     {
  222.                         $this->db->where('title_statuses.title_status_name', $title_status_name);
  223.                     }
  224.                 }
  225.                 else
  226.                 {
  227.                     //if you only used a string with a single value.
  228.                     if (is_string($params['title_status_names']))
  229.                     {
  230.                         $this->db->where('title_statuses.title_status_names', $params['title_status_names']);
  231.                     }
  232.                 }
  233.             }
  234.             //end title status names specific selection
  235.         }
  236.  
  237.         //if no params are found query will be made for all titles in the DB regardless it would be like
  238.         // SELECT * FROM title_statuses;
  239.  
  240.         $query = $this->db->get();
  241.         if ($query->num_rows() > 0)
  242.         {
  243.             return $query->result();
  244.         }
  245.         else
  246.         {
  247.             return false;
  248.         }
  249.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement