daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Jan 19th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Universe_model extends CI_Model {
  4.  
  5.     public function __construct()
  6.     {
  7.         parent::__construct();
  8.     }
  9.  
  10.  
  11.  
  12.     public function get_space()
  13.     {
  14.         $this->load->library('block_cache');
  15.  
  16.         $this->block_cache->set_id('universe');
  17.         $this->block_cache->expires_in(800); // Minutes
  18.  
  19.         if($c = $this->block_cache->get())
  20.         {
  21.             // We can use the cached version, we're done
  22.             return unserialize($c);
  23.         }
  24.         else
  25.         {
  26.             $d = $this->db
  27.                 ->select('
  28.                     g.type,
  29.                     g.description,
  30.                     e.*
  31.                 ')
  32.                 //->select('(SELECT COUNT(id) FROM entities x WHERE x.parent = g.entity_id) AS child_count', FALSE)
  33.                 ->from('galaxies g')
  34.                 ->join('entities e', 'g.entity_id = e.id')
  35.                 ->get()->result_array();
  36.  
  37.             // >:| Stupid subqueries won't work with AR
  38.             foreach($d as $key => $i)
  39.             {
  40.                 $kid_check = $this->db
  41.                                 ->select('COUNT(id) as child_count')
  42.                                 ->from('entities')
  43.                                 ->where('parent', $i['id'])
  44.                                 ->get()->result_array();
  45.  
  46.                 $d[$key]['child_count'] = $kid_check[0]['child_count'];
  47.             }
  48.  
  49.             // Cache this mess
  50.             $this->block_cache->set(serialize($d));
  51.         }
  52.  
  53.         return $d;
  54.     }
  55.  
  56. }
  57.  
  58. // EOF
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top