Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

Commit

Permalink
refactor to eliminate Api class
Browse files Browse the repository at this point in the history
  • Loading branch information
craigh committed Sep 1, 2015
1 parent 571215f commit f92f021
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 86 deletions.
85 changes: 0 additions & 85 deletions Api/UserApi.php

This file was deleted.

58 changes: 57 additions & 1 deletion Controller/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function categoriesAction(Request $request)
}

// get the registered categories
list($properties, $propertiesdata) = ModUtil::apiFunc($this->name, 'user', 'getCategories');
list($properties, $propertiesdata) = $this->getCategories();

$request->attributes->set('_legacy', true); // forces template to render inside old theme

Expand Down Expand Up @@ -220,4 +220,60 @@ private function getAccessLevel(PageEntity $page)
return $accessLevel;
}

/**
* Get the categories registered for the Pages
*
* @return array
*/
private function getCategories()
{
$categoryRegistry = \CategoryRegistryUtil::getRegisteredModuleCategories('ZikulaPagesModule', 'PageEntity');
$properties = array_keys($categoryRegistry);
$propertiesdata = array();
foreach ($properties as $property) {
$rootcat = CategoryUtil::getCategoryByID($categoryRegistry[$property]);
if (!empty($rootcat)) {
$rootcat['path'] .= '/';
// add this to make the relative paths of the subcategories with ease - mateo
$subcategories = CategoryUtil::getCategoriesByParentID($rootcat['id']);
foreach ($subcategories as $k => $category) {
$subcategories[$k]['count'] = $this->countItems(array('category' => $category['id'], 'property' => $property));
}
$propertiesdata[] = array('name' => $property, 'rootcat' => $rootcat, 'subcategories' => $subcategories);
}
}

return array($properties, $propertiesdata);
}

/**
* utility function to count the number of items held by this module
*
* @param array $args Arguments.
*
* @return integer number of items held by this module
*/
private function countItems($args)
{
/** @var \Doctrine\ORM\EntityManager $em */
$em = $this->get('doctrine.entitymanager');

if (isset($args['category']) && !empty($args['category'])) {
if (is_array($args['category'])) {
$args['category'] = $args['category']['Main'][0];
}
$qb = $em->createQueryBuilder();
$qb->select('count(p)')
->from('Zikula\PagesModule\Entity\PageEntity', 'p')
->join('p.categories', 'c')
->where('c.category = :categories')
->setParameter('categories', $args['category']);

return $qb->getQuery()->getSingleScalarResult();
}
$qb = $em->createQueryBuilder();
$qb->select('count(p)')->from('Zikula\PagesModule\Entity\PageEntity', 'p');

return $qb->getQuery()->getSingleScalarResult();
}
}

0 comments on commit f92f021

Please sign in to comment.