public function get_all($include_slider_items = FALSE) { $this->db->select($this->_table_prefix . '.*,u.first_name,u.last_name,u.profile_img,u.gender,ue.email'); $this->db->join(NAILS_DB_PREFIX . 'user u', $this->_table_prefix . '.modified_by = u.id'); $this->db->join(NAILS_DB_PREFIX . 'user_email ue', $this->_table_prefix . '.modified_by = ue.user_id AND ue.is_primary = 1'); $_sliders = parent::get_all(); foreach ($_sliders as $m) { if ($include_slider_items) { // Fetch the nested slider items $m->items = $this->get_slider_items($m->id); } } // -------------------------------------------------------------------------- return $_sliders; }
/** * Fetches all objects * * @access public * @param int $page The page number of the results, if NULL then no pagination * @param int $per_page How many items per page of paginated results * @param mixed $data Any data to pass to _getcount_common() * @param bool $include_deleted If non-destructive delete is enabled then this flag allows you to include deleted items * @param string $_caller Internal flag to pass to _getcount_common(), contains the calling method * @return array **/ public function get_all($page = NULL, $per_page = NULL, $data = NULL, $include_deleted = FALSE, $_caller = 'GET_ALL') { $_posts = parent::get_all($page, $per_page, $data, $include_deleted, 'GET_ALL'); foreach ($_posts as $post) { // Fetch associated categories if (!empty($data['include_categories'])) { $this->db->select('c.id,c.slug,c.label'); $this->db->join(NAILS_DB_PREFIX . 'blog_category c', 'c.id = pc.category_id'); $this->db->where('pc.post_id', $post->id); $this->db->group_by('c.id'); $this->db->order_by('c.label'); $post->categories = $this->db->get(NAILS_DB_PREFIX . 'blog_post_category pc')->result(); foreach ($post->categories as $c) { $c->url = $this->blog_category_model->format_url($c->slug); } } else { $post->categories = array(); } // -------------------------------------------------------------------------- // Fetch associated tags if (!empty($data['include_tags'])) { // Fetch associated tags $this->db->select('t.id,t.slug,t.label'); $this->db->join(NAILS_DB_PREFIX . 'blog_tag t', 't.id = pt.tag_id'); $this->db->where('pt.post_id', $post->id); $this->db->group_by('t.id'); $this->db->order_by('t.label'); $post->tags = $this->db->get(NAILS_DB_PREFIX . 'blog_post_tag pt')->result(); foreach ($post->tags as $t) { $t->url = $this->blog_tag_model->format_url($t->slug); } } else { $post->tags = array(); } // -------------------------------------------------------------------------- // Fetch other associations $_associations = $this->config->item('blog_post_associations'); if (!empty($data['include_associations']) && $_associations) { foreach ($_associations as $index => $assoc) { $post->associations[$index] = $assoc; // Fetch the association data from the source, fail ungracefully - the dev should have this configured correctly. $this->db->select('src.' . $assoc->source->id . ' id, src.' . $assoc->source->label . ' label'); $this->db->join($assoc->source->table . ' src', 'src.' . $assoc->source->id . '=target.associated_id', 'LEFT'); $this->db->where('target.post_id', $post->id); $post->associations[$index]->current = $this->db->get($assoc->target . ' target')->result(); } } else { $post->associations = array(); } // -------------------------------------------------------------------------- // Fetch associated images if (!empty($data['include_gallery'])) { $this->db->where('post_id', $post->id); $this->db->order_by('order'); $post->gallery = $this->db->get(NAILS_DB_PREFIX . 'blog_post_image')->result(); } else { $post->gallery = array(); } } // -------------------------------------------------------------------------- return $_posts; }