Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Universe_model extends CI_Model {
- public function __construct()
- {
- parent::__construct();
- }
- public function get_space()
- {
- $this->load->library('block_cache');
- $this->block_cache->set_id('universe');
- $this->block_cache->expires_in(800); // Minutes
- if($c = $this->block_cache->get())
- {
- // We can use the cached version, we're done
- return unserialize($c);
- }
- else
- {
- $d = $this->db
- ->select('
- g.type,
- g.description,
- e.*
- ')
- //->select('(SELECT COUNT(id) FROM entities x WHERE x.parent = g.entity_id) AS child_count', FALSE)
- ->from('galaxies g')
- ->join('entities e', 'g.entity_id = e.id')
- ->get()->result_array();
- // >:| Stupid subqueries won't work with AR
- foreach($d as $key => $i)
- {
- $kid_check = $this->db
- ->select('COUNT(id) as child_count')
- ->from('entities')
- ->where('parent', $i['id'])
- ->get()->result_array();
- $d[$key]['child_count'] = $kid_check[0]['child_count'];
- }
- // Cache this mess
- $this->block_cache->set(serialize($d));
- }
- return $d;
- }
- }
- // EOF
Add Comment
Please, Sign In to add comment