/** * Initialize form handler. * * This method takes care of all necessary initialisation of our data and form states. * * @param Zikula_Form_View $view The form view instance. * * @return boolean False in case of initialization errors, otherwise true. */ public function initialize(Zikula_Form_View $view) { parent::initialize($view); if ($this->mode == 'create') { $modelHelper = new Reviews_Util_Model($this->view->getServiceManager()); if (!$modelHelper->canBeCreated($this->objectType)) { LogUtil::registerError($this->__('Sorry, but you can not create the review yet as other items are required which must be created before!')); return $this->view->redirect($this->getRedirectUrl(null)); } } $entity = $this->entityRef; // save entity reference for later reuse $this->entityRef = $entity; $entityData = $entity->toArray(); if (count($this->listFields) > 0) { $helper = new Reviews_Util_ListEntries($this->view->getServiceManager()); foreach ($this->listFields as $listField => $isMultiple) { $entityData[$listField . 'Items'] = $helper->getEntries($this->objectType, $listField); if ($isMultiple) { $entityData[$listField] = $helper->extractMultiList($entityData[$listField]); } } } // assign data to template as array (makes translatable support easier) $this->view->assign($this->objectTypeLower, $entityData); if ($this->mode == 'edit') { // assign formatted title $this->view->assign('formattedEntityTitle', $entity->getTitleFromDisplayPattern()); } // everything okay, no initialization errors occured return true; }
/** * 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); */ }
/** * This method provides a generic item list overview. * * @param string $ot Treated object type. * @param string $sort Sorting field. * @param string $sortdir Sorting direction. * @param int $pos Current pager position. * @param int $num Amount of entries to display. * @param string $tpl Name of alternative template (for alternative display options, feeds and xml output) * @param boolean $raw Optional way to display a template instead of fetching it (needed for standalone output) * * @return mixed Output. */ public function view() { $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 = ''; $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($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); }