pickles/common/modules/store/admin/categories.php
Josh Sherman 56d4f60a6c Building the orders section.
git-svn-id: http://svn.cleancode.org/svn/pickles@117 4d10bc64-7434-11dc-a737-d2d0f8310089
2009-05-12 03:42:24 +00:00

34 lines
894 B
PHP

<?php
class store_admin_categories extends store_admin {
public function __default() {
// Pulls all the categories and product counts in hierarchial and alphabetical order
$all_categories = $this->db->getArray('
SELECT c.*, COUNT(xref.category_id) AS product_count
FROM categories AS c
LEFT JOIN category_xref AS xref
ON xref.category_id = c.id
GROUP BY c.id
ORDER BY c.parent_id, c.name;
');
// Loops through the categories and builds an array of parents and children
$categories = array();
if (is_array($all_categories)) {
foreach ($all_categories as $category) {
if ($category['parent_id'] == null) {
$categories[$category['id']] = $category;
}
else {
$categories[$category['parent_id']]['children'][] = $category;
}
}
}
// Passes the categories to the template
$this->setPublic('categories', $categories);
}
}
?>