/** * Get labels for category * @param type $parent_id * @param type $level * @return type */ function getHierarchicalCategories($parent_id, $level) { $CI =& get_instance(); $cats = getCategoriesByParentId($parent_id); if (!empty($cats)) { foreach ($cats as $cat) { $dash = ''; for ($j = 0; $j < $level; $j++) { $dash .= '—'; } $CI->node[$cat->id] = $dash . $cat->category_name; getHierarchicalCategories($cat->id, $level + 1); } } if (!empty($CI->node)) { return $CI->node; } else { return ''; } }
/** * Return feeds data by limit and offset * @param type $limit * @param type $offset * @return type */ public function getAllData($limit, $offset, $feed_user_category) { $parent_cat = getHierarchicalCategories($feed_user_category, 0); // pri($parent_cat); // die(); $array = array(); if (!empty($parent_cat)) { foreach ($parent_cat as $key => $value) { $array[$key] = $key; } $list_id = join(',', $array); $categoryIn = $list_id . ',' . $feed_user_category; $sql = "SELECT * FROM (`feeds`) WHERE `feed_user_category` IN ({$categoryIn}) AND `feed_filter_type` != 'news' LIMIT {$limit} OFFSET {$offset}"; $query = $this->db->query($sql); return $query->result(); } else { $this->db->select('*'); $this->db->from($this->feed_table); $this->db->limit($limit, $offset); $this->db->where('feed_user_category', $feed_user_category); $this->db->where('feed_filter_type !=', 'news'); $this->db->order_by('feed_date', 'desc'); $query = $this->db->get(); return $query->result(); } }
?> <span class="help-block"><?php echo $this->lang->line('admin_cat_eg'); ?> </span> <!--/controls--></div> <!-- control group---></div> <div class="control-group"> <label class="control-label" for="category_name"><?php echo $this->lang->line('admin_cat_parent'); ?> </label> <div class="controls"> <?php echo '<select id="category_parent" class="form-control category_parent" name="category_parent">'; $parent_cat = getHierarchicalCategories(0, 0); if (!empty($parent_cat)) { foreach ($parent_cat as $key => $value) { if ($key == $category->parent_id) { $selected = "selected='selected'"; } else { $selected = ""; } echo '<option ' . $selected . ' value="' . $key . '">' . $value . '</option>'; } } echo '</select>'; ?> <?php echo form_error('category_parent', '<div class="error">', '</div>'); ?>