/** * view items * * @return string HTML output */ public function view() { // Security check if (!SecurityUtil::checkPermission('Reviews::', '::', ACCESS_OVERVIEW)) { return LogUtil::registerPermissionError(); } $controllerHelper = new Reviews_Util_Controller($this->serviceManager); // parameter specifying which type of objects we are treating $objectType = $this->request->query->filter('ot', 'review', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'view'); if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) { $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs); } $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', ACCESS_READ), LogUtil::getErrorMsgPermission()); $entityClass = $this->name . '_Entity_' . ucwords($objectType); $repository = $this->entityManager->getRepository($entityClass); $repository->setControllerArguments(array()); $viewHelper = new Reviews_Util_View($this->serviceManager); // parameter for used sorting field $sort = $this->request->query->filter('sort', '', FILTER_SANITIZE_STRING); if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) { $sort = $repository->getDefaultSortingField(); } // parameter for used sort order $sdir = $this->request->query->filter('sortdir', '', FILTER_SANITIZE_STRING); $sdir = strtolower($sdir); if ($sdir != 'asc' && $sdir != 'desc') { $sdir = 'asc'; } // convenience vars to make code clearer $currentUrlArgs = array('ot' => $objectType); $where = ''; // we check for letter $letter = $this->request->query->filter('letter', NULL); if ($letter != NULL) { $where = 'tbl.title LIKE \'' . DataUtil::formatForStore($letter) . '%\''; } $selectionArgs = array('ot' => $objectType, 'where' => $where, 'orderBy' => $sort . ' ' . $sdir); $showOwnEntries = (int) $this->request->query->filter('own', $this->getVar('showOnlyOwnEntries', 0), FILTER_VALIDATE_INT); $showAllEntries = (int) $this->request->query->filter('all', 0, FILTER_VALIDATE_INT); if (!$showAllEntries) { $csv = (int) $this->request->query->filter('usecsvext', 0, FILTER_VALIDATE_INT); if ($csv == 1) { $showAllEntries = 1; } } $this->view->assign('showOwnEntries', $showOwnEntries)->assign('showAllEntries', $showAllEntries); if ($showOwnEntries == 1) { $currentUrlArgs['own'] = 1; } if ($showAllEntries == 1) { $currentUrlArgs['all'] = 1; } // prepare access level for cache id $accessLevel = ACCESS_READ; $component = 'Reviews:' . ucwords($objectType) . ':'; $instance = '::'; if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) { $accessLevel = ACCESS_COMMENT; } if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) { $accessLevel = ACCESS_EDIT; } $templateFile = $viewHelper->getViewTemplate($this->view, 'user', $objectType, 'view', array()); $cacheId = 'view|ot_' . $objectType . '_sort_' . $sort . '_' . $sdir; $resultsPerPage = 0; if ($showAllEntries == 1) { // set cache id $this->view->setCacheId($cacheId . '_all_1_own_' . $showOwnEntries . '_' . $accessLevel); // if page is cached return cached content if ($this->view->is_cached($templateFile)) { return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); } // retrieve item list without pagination $entities = ModUtil::apiFunc($this->name, 'selection', 'getEntities', $selectionArgs); } else { // the current offset which is used to calculate the pagination $currentPage = (int) $this->request->query->filter('pos', 1, FILTER_VALIDATE_INT); // the number of items displayed on a page for pagination $resultsPerPage = (int) $this->request->query->filter('num', 0, FILTER_VALIDATE_INT); if ($resultsPerPage == 0) { $resultsPerPage = $this->getVar('pagesize', 10); } // set cache id $this->view->setCacheId($cacheId . '_amount_' . $resultsPerPage . '_page_' . $currentPage . '_own_' . $showOwnEntries . '_' . $accessLevel); // if page is cached return cached content if ($this->view->is_cached($templateFile)) { return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); } // retrieve item list with pagination $selectionArgs['currentPage'] = $currentPage; $selectionArgs['resultsPerPage'] = $resultsPerPage; list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs); $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage)); } foreach ($entities as $k => $entity) { $entity->initWorkflow(); } // build ModUrl instance for display hooks $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'view', ZLanguage::getLanguageCode(), $currentUrlArgs); // assign the object data, sorting information and details for creating the pager $this->view->assign('items', $entities)->assign('sort', $sort)->assign('sdir', $sdir)->assign('pageSize', $resultsPerPage)->assign('currentUrlObject', $currentUrlObject)->assign('shorturls', System::getVar('shorturls'))->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs)); $modelHelper = new Reviews_Util_Model($this->serviceManager); $this->view->assign('canBeCreated', $modelHelper->canBeCreated($objectType)); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); ///////////////////////Alter Code // Get parameters from whatever input we need $cat = (string) FormUtil::getPassedValue('cat', isset($args['cat']) ? $args['cat'] : null, 'GET'); $prop = (string) FormUtil::getPassedValue('prop', isset($args['prop']) ? $args['prop'] : null, 'GET'); $letter = (string) FormUtil::getPassedValue('letter', null, 'REQUEST'); $page = (int) FormUtil::getPassedValue('page', isset($args['page']) ? $args['page'] : 1, 'GET'); // get all module vars for later use $modvars = ModUtil::getVar('Reviews'); // defaults and input validation if (!is_numeric($page) || $page < 0) { $page = 1; } $startnum = ($page - 1) * $modvars['itemsperpage'] + 1; // check if categorisation is enabled if ($modvars['enablecategorization']) { // get the categories registered for Reviews $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Reviews', 'reviews'); $properties = array_keys($catregistry); // validate the property // and build the category filter - mateo if (!empty($properties) && in_array($prop, $properties)) { // if the property and the category are specified // means that we'll list the reviews that belongs to that category if (!empty($cat)) { if (!is_numeric($cat)) { $rootCat = CategoryUtil::getCategoryByID($catregistry[$prop]); $cat = CategoryUtil::getCategoryByPath($rootCat['path'] . '/' . $cat); } else { $cat = CategoryUtil::getCategoryByID($cat); } if (!empty($cat) && isset($cat['path'])) { // include all it's subcategories and build the filter $categories = categoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $catFilter = array($prop => $catstofilter); } else { LogUtil::registerError($this->__('Invalid category passed.')); } } } } // Get all matching reviews /*$items = ModUtil::apiFunc('Reviews', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'letter' => $letter, 'category' => isset($catFilter) ? $catFilter : null, 'catregistry' => isset($catregistry) ? $catregistry : null)); // assign all the necessary template variables $this->view->assign('items', $items); $this->view->assign('category', $cat); $this->view->assign('lang', ZLanguage::getLanguageCode()); $this->view->assign($modvars); $this->view->assign('shorturls', System::getVar('shorturls')); $this->view->assign('shorturlstype', System::getVar('shorturlstype')); // Assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Reviews', 'user', 'countitems', array('letter' => $letter, 'category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $modvars['itemsperpage'])); // fetch and return the appropriate template return $viewHelper->processTemplate($this->view, 'user', $objectType, 'view', array(), $templateFile); */ }
/** * view items * * @return string html string */ public function view($args) { $this->throwForbiddenUnless(SecurityUtil::checkPermission('Pages::', '::', ACCESS_OVERVIEW), LogUtil::getErrorMsgPermission()); $lang = ZLanguage::getLanguageCode(); $startnum = (int)FormUtil::getPassedValue('startnum', isset($args['startnum']) ? $args['startnum'] : 1, 'GET'); $prop = (string)FormUtil::getPassedValue('prop', isset($args['prop']) ? $args['prop'] : null, 'GET'); $cat = (string)FormUtil::getPassedValue('cat', isset($args['cat']) ? $args['cat'] : null, 'GET'); $catparam = $cat; // defaults and input validation if (!is_numeric($startnum) || $startnum < 0) { $startnum = 1; } // get all module vars for later use $modvars = $this->getVars(); // check if categorization is enabled if ($modvars['enablecategorization']) { // get the categories registered for the Pages $catregistry = CategoryRegistryUtil::getRegisteredModuleCategories('Pages', 'pages'); $properties = array_keys($catregistry); // validate the property // and build the category filter - mateo if (!empty($prop) && in_array($prop, $properties)) { // TODO [Perform a category permission check here] // if the property and the category are specified // means that we'll list the pages that belongs to that category if (!empty($cat)) { if (!is_numeric($cat)) { $rootCat = CategoryUtil::getCategoryByID($catregistry[$prop]); $cat = CategoryUtil::getCategoryByPath($rootCat['path'].'/'.$cat); } else { $cat = CategoryUtil::getCategoryByID($cat); } if (!empty($cat) && isset($cat['path'])) { // include all it's subcategories and build the filter $categories = categoryUtil::getCategoriesByPath($cat['path'], '', 'path'); $catstofilter = array(); foreach ($categories as $category) { $catstofilter[] = $category['id']; } $catFilter = array($prop => $catstofilter); } else { LogUtil::registerError($this->__('Invalid category passed.')); } } } // if nothing or only property is specified // means that we'll list the subcategories available on a property - mateo if (!isset($catFilter)) { $listproperties = array(); // list all the available properties if (empty($prop) || !in_array($prop, $properties)) { $listproperties = $properties; } else { $listproperties[] = $prop; } $listrootcats = array(); $listcategories = array(); $categorylisted = array(); foreach (array_keys($listproperties) as $i) { $listrootcats[$i] = CategoryUtil::getCategoryByID($catregistry[$listproperties[$i]]); if (in_array($listrootcats[$i]['id'], $categorylisted)) { continue; } // mark the root category as already listed $categorylisted[] = $listrootcats[$i]['id']; // add a final / to make the easy the relative paths build in the template - mateo $listrootcats[$i]['path'] .= '/'; // gets all the subcategories to list $listcategories[$i] = CategoryUtil::getCategoriesByParentID($listrootcats[$i]['id']); } unset($categorylisted); } } // assign various useful template variables $this->view->assign('startnum', $startnum); $this->view->assign('lang', $lang); // If categorization is enabled, show a // list of subcategories of an specific property if ($modvars['enablecategorization'] && !isset($catFilter)) { // Assign the current action to the template $this->view->assign('action', 'subcatslist'); $this->view->assign('listrootcats', $listrootcats); $this->view->assign('listproperties', $listproperties); $this->view->assign('listcategories', $listcategories); // List of Pages // of an specific category if categorization is enabled } else { // Assign the current action to the template $this->view->assign('action', 'pageslist'); // Assign the categories information if ($modvars['enablecategorization']) { $this->view->assign('properties', $properties); $this->view->assign('category', $cat); } // Get all matching pages $items = ModUtil::apiFunc('Pages', 'user', 'getall', array('startnum' => $startnum, 'numitems' => $modvars['itemsperpage'], 'category' => isset($catFilter) ? $catFilter : null, 'catregistry' => isset($catregistry) ? $catregistry : null, 'language' => $lang)); if ($items == false) { LogUtil::registerStatus($this->__('No pages found.')); } // Loop through each item and display it. $pages = array(); foreach ($items as $item) { if (SecurityUtil::checkPermission('Pages::', "{$item['title']}::{$item['pageid']}", ACCESS_OVERVIEW)) { $this->view->assign('item', $item); if (SecurityUtil::checkPermission('Pages::', "{$item['title']}::{$item['pageid']}", ACCESS_READ)) { $pages[] = $this->view->fetch('user/rowread.tpl', $item['pageid']); } else { $pages[] = $this->view->fetch('user/rowoverview.tpl', $item['pageid']); } } } unset($items); // assign the values for the smarty plugin to produce a pager $this->view->assign('pager', array('numitems' => ModUtil::apiFunc('Pages', 'user', 'countitems', array('category' => isset($catFilter) ? $catFilter : null)), 'itemsperpage' => $modvars['itemsperpage'])); // assign the item output to the template $this->view->assign('pages', $pages); } // Return the output that has been generated by this function // is not practical to check for is_cached earlier in this method. $this->view->setCacheId('view|prop_'.$prop.'_cat_'.$catparam . '|stnum_'.$startnum.'_'.$modvars['itemsperpage']); return $this->view->fetch('user/view.tpl'); }