Skip to content

Instantly share code, notes, and snippets.

@deanputney
Created April 25, 2013 00:37
Show Gist options
  • Save deanputney/5456705 to your computer and use it in GitHub Desktop.
Save deanputney/5456705 to your computer and use it in GitHub Desktop.
// Get all active top level categories
$parent_categories = array();
$all_parents = ORM::factory('category')
->where('category_visible', '1')
->where('parent_id', '0')
->find_all();
foreach ($all_parents as $category)
{
// Get The Children
$children = array();
foreach ($category->children as $child)
{
$child_visible = $child->category_visible;
if ($child_visible)
{
// Check for localization of child category
$display_title = Category_Lang_Model::category_title($child->id,$l);
$ca_img = ($child->category_image != NULL)
? url::convert_uploaded_to_abs($child->category_image)
: NULL;
$children[$child->id] = array(
$display_title,
$child->category_color,
$ca_img
);
}
}
// Check for localization of parent category
$display_title = Category_Lang_Model::category_title($category->id,$l);
// Put it all together
$ca_img = ($category->category_image != NULL)
? url::convert_uploaded_to_abs($category->category_image)
: NULL;
$parent_categories[$category->id] = array(
$display_title,
$category->category_color,
$ca_img,
$children
);
}
$this->template->content->categories = $parent_categories;
// Get all active and hidden top level categories
$categories = array();
$all_parents = ORM::factory('category')
->where('parent_id', '0')
->find_all();
foreach ($all_parents as $category)
{
// Get The Children
$children = array();
foreach ($category->children as $child)
{
// Check for localization of child category
$display_title = Category_Lang_Model::category_title($child->id,$l);
$ca_img = ($child->category_image != NULL)
? url::convert_uploaded_to_abs($child->category_image)
: NULL;
$categories[$child->id] = array(
$display_title,
$child->category_color,
$ca_img
);
}
// Check for localization of parent category
$display_title = Category_Lang_Model::category_title($category->id,$l);
// Put it all together
$ca_img = ($category->category_image != NULL)
? url::convert_uploaded_to_abs($category->category_image)
: NULL;
// $parent_categories[$category->id] = array(
// $display_title,
// $category->category_color,
// $ca_img,
// $children
// );
}
$this->template->content->all_categories = $categories;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment