Ejemplo n.º 1
0
 /**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * This function increment the page view if the user is not the creator
  */
 public static function addView($id)
 {
     $serviceManager = ServiceUtil::getManager();
     $modelHelper = new Reviews_Util_Model($serviceManager);
     // build review repository
     $repository = $modelHelper->getReviewRepository();
     $entity = $repository->selectById($id);
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     if ($entity->getCreatedUserId() != UserUtil::getVar('uid')) {
         $hits = $entity->getHits();
         $entity->setHits($hits + 1);
         $email = $entity->getEmail();
         $email = html_entity_decode($email);
         $entity->setEmail($email);
         $entityManager->flush();
     }
     return true;
 }
Ejemplo n.º 3
0
 /**
  * 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);
             */
 }
Ejemplo n.º 4
0
 /**
  * form custom url string
  *
  * @author Mark West
  * @return string custom url string
  */
 public function encodeurl($args)
 {
     // check if we have the required input
     if (!isset($args['modname']) || !isset($args['func'])) {
         throw new \InvalidArgumentException(__('Invalid arguments array received.'));
     }
     // set default values
     if (!isset($args['type'])) {
         $args['type'] = 'user';
     }
     if (!isset($args['args'])) {
         $args['args'] = array();
     }
     // return if function url scheme is not being customised
     $customFuncs = array('view', 'display');
     if (!in_array($args['func'], $customFuncs)) {
         return false;
     }
     // initialise url routing rules
     $routerFacade = new Reviews_RouterFacade();
     // get router itself for convenience
     $router = $routerFacade->getRouter();
     // initialise object type
     $controllerHelper = new Reviews_Util_Controller($this->serviceManager);
     $utilArgs = array('controller' => 'user', 'action' => 'encodeurl');
     $allowedObjectTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $objectType = isset($args['args']['ot']) && in_array($args['args']['ot'], $allowedObjectTypes) ? $args['args']['ot'] : $controllerHelper->getDefaultObjectType('api', $utilArgs);
     // initialise group folder
     $groupFolder = $routerFacade->getGroupingFolderFromObjectType($objectType, $args['func'], $args['args']);
     // start pre processing
     // convert object type to group folder
     $args['args']['ot'] = $groupFolder;
     // handle special templates
     $displayDefaultEnding = System::getVar('shorturlsext', '');
     $endingPrefix = $args['func'] == 'view' ? '.' : '';
     foreach (array('csv', 'rss', 'atom', 'xml', 'pdf', 'json', 'kml') as $ending) {
         if (!isset($args['args']['use' . $ending . 'ext'])) {
             continue;
         }
         if ($args['args']['use' . $ending . 'ext'] == '1') {
             $args['args'][$args['func'] . 'ending'] = $endingPrefix . $ending;
         }
         unset($args['args']['use' . $ending . 'ext']);
     }
     // fallback to default templates
     if (!isset($args['args'][$args['func'] . 'ending'])) {
         if ($args['func'] == 'view') {
             // category list
             /* if (isset($args['args']['prop'])) {
                 $vars = $args['args']['prop'];
                if (isset($args['args']['cat'])) {
                $vars .= '/'.$args['args']['cat'];
                }
                // letter list
                } elseif (isset($args['args']['letter'])) {
                $vars = 'letter/'.$args['args']['letter'];
                }
                if (isset($args['args']['page']) && $args['args']['page'] != 1) {
                $vars .= (empty($vars) ? '' : '/').'page/'.$args['args']['page'];
                }*/
             $args['args'][$args['func'] . 'ending'] = '';
             //'/';
         } else {
             if ($args['func'] == 'display') {
                 $args['args'][$args['func'] . 'ending'] = $displayDefaultEnding;
             }
         }
     }
     if ($args['func'] == 'view') {
         // TODO filter views (e.g. /orders/customer/mr-smith.csv)
         /**
         $filterEntities = array('customer', 'region', 'federalstate', 'country');
         foreach ($filterEntities as $filterEntity) {
         $filterField = $filterEntity . 'id';
         if (!isset($args['args'][$filterField]) || !$args['args'][$filterField]) {
         continue;
         }
         $filterId = $args['args'][$filterField];
         unset($args['args'][$filterField]);
         
         $filterGroupFolder = $routerFacade->getGroupingFolderFromObjectType($filterEntity, 'display', $args['args']);
         $filterSlug = $routerFacade->getFormattedSlug($filterEntity, 'display', $args['args'], $filterId);
         $result .= $filterGroupFolder . '/' . $filterSlug .'/';
         break;
         }
         */
     } elseif ($args['func'] == 'display') {
         // determine given id
         $id = 0;
         foreach (array('id', strtolower($objectType) . 'id', 'objectid') as $idFieldName) {
             if (isset($args['args'][$idFieldName])) {
                 $id = $args['args'][$idFieldName];
                 unset($args['args'][$idFieldName]);
             }
         }
         if (ModUtil::getVar('Reviews', 'addcategorytitletopermalink') == 1 && ModUtil::getVar('Reviews', 'enablecategorization') == 1) {
             if ($id > 0) {
                 $modelHelper = new Reviews_Util_Model($this->serviceManager);
                 $repository = $modelHelper->getReviewRepository();
                 $thisreview = $repository->selectById($id);
                 $categories = $thisreview->getCategories();
                 $name = $categories[0]->getCategory()->getName();
                 $displayname = $categories[0]->getCategory()->getDisplayName();
             }
             $lang = ZLanguage::getLanguageCode();
             $cat = '';
             if ($name != '') {
                 $cat = $name;
             }
             if ($displayname != '') {
                 $cat = $displayname[$lang];
             }
             $args['args']['cat'] = $cat;
         }
         // check if we have a valid slug given
         if (isset($args['args']['slug']) && (!$args['args']['slug'] || $args['args']['slug'] == $id)) {
             unset($args['args']['slug']);
         }
         // try to determine missing slug
         if (!isset($args['args']['slug'])) {
             $slug = '';
             if ($id > 0) {
                 $slug = $routerFacade->getFormattedSlug($objectType, $args['func'], $args['args'], $id);
             }
             if (!empty($slug) && $slug != $id) {
                 // add slug expression
                 $args['args']['slug'] = $slug;
             }
         }
         // check if we have one now
         if (!isset($args['args']['slug'])) {
             // readd id as fallback
             $args['args']['id'] = $id;
         }
     }
     // add func as first argument
     $routerArgs = array_merge(array('func' => $args['func']), $args['args']);
     // now create url based on params
     $result = $router->generate(null, $routerArgs);
     // post processing
     if ($args['func'] == 'view' && !empty($args['args']['viewending']) || $args['func'] == 'display') {
         // check if url ends with a trailing slash
         if (substr($result, -1) == '/') {
             // remove the trailing slash
             $result = substr($result, 0, strlen($result) - 1);
         }
     }
     // enforce url name of the module, but do only 1 replacement to avoid changing other params
     $modInfo = ModUtil::getInfoFromName('Reviews');
     $result = preg_replace('/' . $modInfo['name'] . '/', $modInfo['url'], $result, 1);
     $result = preg_replace('#' . 'review/' . '#', '', $result, 1);
     $result = preg_replace('=' . '\\+' . '=', ' ', $result);
     return $result;
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }