$category_description = html::escape(Category_Lang_Model::category_description($category)); $color_css = 'class="category-icon swatch" style="background-color:#' . $category_color . '"'; if ($category_info[2] != NULL) { $category_image = html::image(array('src' => $category_image)); $color_css = 'class="category-icon"'; } echo '<li>' . '<a href="#" id="cat_' . $category . '" title="' . $category_description . '">' . '<span ' . $color_css . '>' . $category_image . '</span>' . '<span class="category-title">' . $category_title . '</span>' . '</a>'; // Get Children echo '<div class="hide" id="child_' . $category . '">'; if (sizeof($category_info[3]) != 0) { echo '<ul>'; foreach ($category_info[3] as $child => $child_info) { $child_title = html::escape($child_info[0]); $child_color = $child_info[1]; $child_image = $child_info[2] != NULL ? url::convert_uploaded_to_abs($child_info[2]) : NULL; $child_description = html::escape(Category_Lang_Model::category_description($child)); $color_css = 'class="category-icon swatch" style="background-color:#' . $child_color . '"'; if ($child_info[2] != NULL) { $child_image = html::image(array('src' => $child_image)); $color_css = 'class="category-icon"'; } echo '<li>' . '<a href="#" id="cat_' . $child . '" title="' . $child_description . '">' . '<span ' . $color_css . '>' . $child_image . '</span>' . '<span class="category-title">' . $child_title . '</span>' . '</a>' . '</li>'; } echo '</ul>'; } echo '</div></li>'; } ?> </ul> <?php }
} ?> </div> <?php } ?> </td> </tr> <?php // Get All Category Children foreach ($category->children as $child) { $category_id = $child->id; $parent_id = $child->parent_id; $category_title = Category_Lang_Model::category_title($category_id); $category_description = substr(Category_Lang_Model::category_description($category_id), 0, 150); $category_color = $child->category_color; $category_image = $child->category_image != NULL ? url::convert_uploaded_to_abs($child->category_image) : NULL; $category_visible = $child->category_visible; $fillFields = array(); $fillFields['category_id'] = $child->id; $fillFields['parent_id'] = $child->parent_id; $fillFields['category_title'] = $child->category_title; $fillFields['category_description'] = $child->category_description; $fillFields['category_color'] = $child->category_color; $fillFields['category_image'] = $child->category_image; $fillFields['locale'] = $category->locale; $fillFields['category_langs'] = array(); foreach ($child->category_lang as $category_lang) { $fillFields['category_langs'][$category_lang->locale] = array('category_title' => $category_lang->category_title, 'category_description' => $category_lang->category_description); }
foreach ($incident_category as $category) { // don't show hidden categoies if ($category->category->category_visible == 0) { continue; } if ($category->category->category_image_thumb) { $style = "background:transparent url(" . url::convert_uploaded_to_abs($category->category->category_image_thumb) . ") 0 0 no-repeat"; } else { $style = "background-color:#" . $category->category->category_color; } ?> <a href="<?php echo url::site() . "reports/?c=" . $category->category->id; ?> " title="<?php echo Category_Lang_Model::category_description($category->category_id); ?> "> <span class="r_cat-box" style="<?php echo $style; ?> "> </span> <?php echo Category_Lang_Model::category_title($category->category_id); ?> </a> <?php } ?> </p> <?php
/** * Get categories as an tree array * @param bool Get category count? * @param bool Include hidden categories * @return array **/ public static function get_category_tree_data($count = FALSE, $include_hidden = FALSE) { // To hold the category data $category_data = array(); // Database table prefix $table_prefix = Kohana::config('database.default.table_prefix'); // Database instance $db = new Database(); // Fetch the other categories if ($count) { $sql = "SELECT c.id, c.parent_id, c.category_title, c.category_color, c.category_image, c.category_image_thumb, COUNT(i.id) report_count " . "FROM " . $table_prefix . "category c " . "LEFT JOIN " . $table_prefix . "category c_parent ON (c.parent_id = c_parent.id) " . "LEFT JOIN " . $table_prefix . "incident_category ic ON (ic.category_id = c.id) " . "LEFT JOIN " . $table_prefix . "incident i ON (ic.incident_id = i.id AND i.incident_active = 1 ) " . "WHERE 1=1 " . (!$include_hidden ? "AND c.category_visible = 1 " : "") . (!$include_hidden ? "AND (c_parent.category_visible = 1 OR c.parent_id = 0)" : "") . "GROUP BY c.id " . "ORDER BY c.category_position ASC"; } else { $sql = "SELECT c.id, c.parent_id, c.category_title, c.category_color, c.category_image, c.category_image_thumb " . "FROM " . $table_prefix . "category c " . "LEFT JOIN " . $table_prefix . "category c_parent ON (c.parent_id = c_parent.id) " . "WHERE 1=1 " . (!$include_hidden ? "AND c.category_visible = 1 " : "") . (!$include_hidden ? "AND (c_parent.category_visible = 1 OR c.parent_id = 0)" : "") . "ORDER BY c.category_position ASC"; } // Create nested array - all in one pass foreach ($db->query($sql) as $category) { // If we didn't fetch report_count set fake value if (!$count) { $category->report_count = 0; } // If this is a parent category, just add it to the array if ($category->parent_id == 0) { // save children and report_count if already been created. $children = isset($category_data[$category->id]['children']) ? $category_data[$category->id]['children'] : array(); $report_count = isset($category_data[$category->id]['report_count']) ? $category_data[$category->id]['report_count'] : 0; $category_data[$category->id] = array('category_id' => $category->id, 'category_title' => html::escape(Category_Lang_Model::category_title($category->id)), 'category_description' => html::escape(Category_Lang_Model::category_description($category->id)), 'category_color' => $category->category_color, 'category_image' => $category->category_image, 'children' => $children, 'category_image_thumb' => $category->category_image_thumb, 'parent_id' => $category->parent_id, 'report_count' => $category->report_count + $report_count); } else { // If we haven't processed the parent yet, add placeholder parent category if (!array_key_exists($category->parent_id, $category_data)) { $category_data[$category->parent_id] = array('category_id' => $category->parent_id, 'category_title' => '', 'category_description' => '', 'parent_id' => 0, 'category_color' => '', 'category_image' => '', 'category_image_thumb' => '', 'children' => array(), 'report_count' => 0); } // Add children $category_data[$category->parent_id]['children'][$category->id] = array('category_id' => $category->id, 'category_title' => html::escape(Category_Lang_Model::category_title($category->id)), 'category_description' => html::escape(Category_Lang_Model::category_description($category->id)), 'parent_id' => $category->parent_id, 'category_color' => $category->category_color, 'category_image' => $category->category_image, 'category_image_thumb' => $category->category_image_thumb, 'report_count' => $category->report_count, 'children' => array()); // Add to parent report count too $category_data[$category->parent_id]['report_count'] += $category->report_count; } } return $category_data; }
$category_description = htmlentities(Category_Lang_Model::category_description($category), ENT_QUOTES, "UTF-8"); $color_css = 'class="category-icon swatch" style="background-color:#' . $category_color . '"'; if ($category_info[2] != NULL) { $category_image = html::image(array('src' => $category_image)); $color_css = 'class="category-icon"'; } echo '<li>' . '<a href="#" id="cat_' . $category . '" title="' . $category_description . '">' . '<span ' . $color_css . '>' . $category_image . '</span>' . '<span class="category-title">' . $category_title . '</span>' . '</a>'; // Get Children echo '<div class="hide" id="child_' . $category . '">'; if (sizeof($category_info[3]) != 0) { echo '<ul>'; foreach ($category_info[3] as $child => $child_info) { $child_title = htmlentities($child_info[0], ENT_QUOTES, "UTF-8"); $child_color = $child_info[1]; $child_image = $child_info[2] != NULL ? url::convert_uploaded_to_abs($child_info[2]) : NULL; $child_description = htmlentities(Category_Lang_Model::category_description($child), ENT_QUOTES, "UTF-8"); $color_css = 'class="category-icon swatch" style="background-color:#' . $child_color . '"'; if ($child_info[2] != NULL) { $child_image = html::image(array('src' => $child_image)); $color_css = 'class="category-icon"'; } echo '<li>' . '<a href="#" id="cat_' . $child . '" title="' . $child_description . '">' . '<span ' . $color_css . '>' . $child_image . '</span>' . '<span class="category-title">' . $child_title . '</span>' . '</a>' . '</li>'; } echo '</ul>'; } echo '</div></li>'; } ?> </ul> <!-- / category filters -->