/** * This method provides a generic item detail view. * * @param string $ot Treated object type. * @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 display($args) { // DEBUG: permission check aspect starts $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_READ)); // DEBUG: permission check aspect ends // parameter specifying which type of objects we are treating $objectType = isset($args['ot']) && !empty($args['ot']) ? $args['ot'] : $this->request->getGet()->filter('ot', 'category', FILTER_SANITIZE_STRING); $utilArgs = array('controller' => 'user', 'action' => 'display'); if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) { $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs); } $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType)); $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType)); // retrieve identifier of the object we wish to view $idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, $args, $objectType, $idFields); $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($idValues); // check for unique permalinks (without id) $hasSlug = false; $slugTitle = ''; if ($hasIdentifier === false) { $entityClass = 'MUBoard_Entity_' . ucfirst($objectType); $objectTemp = new $entityClass(); $hasSlug = $objectTemp->get_hasUniqueSlug(); if ($hasSlug) { $slugTitle = isset($args['title']) && !empty($args['title']) ? $args['title'] : $this->request->getGet()->filter('title', '', FILTER_SANITIZE_STRING); $hasSlug = !empty($slugTitle); } } $hasIdentifier |= $hasSlug; $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.')); $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues, 'slug' => $slugTitle)); $this->throwNotFoundUnless($entity != null, $this->__('No such item.')); // we take the children postings of the parent issue if ($objectType == 'posting') { $postingid = $entity['id']; $postingsWhere = 'tbl.parent = \'' . DataUtil::formatForStore($postingid) . '\''; $order = ModUtil::getVar($this->name, 'sortingPostings'); if ($order == 'descending') { $sdir = 'desc'; } else { $sdir = 'asc'; } $selectionArgs = array('ot' => 'posting', 'where' => $postingsWhere, 'orderBy' => 'createdDate' . ' ' . $sdir); // the current offset which is used to calculate the pagination $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT); // the number of items displayed on a page for pagination $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT); if ($resultsPerPage == 0) { $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT); $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10); } $selectionArgs['currentPage'] = $currentPage; $selectionArgs['resultsPerPage'] = $resultsPerPage; list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs); // we check if the user may see the form to answer to posting $mayEdit = MUBoard_Util_Controller::mayEdit($id); $this->view->assign('mayEdit', $mayEdit); } if ($objectType == 'forum') { $forumid = $entity['id']; $parentWhere = 'tbl.parent_id IS NULL'; $parentWhere .= ' AND '; $parentWhere .= 'tbl.forum = \'' . DataUtil::formatForStore($forumid) . '\''; $order = ModUtil::getVar($this->name, 'sortingPostings'); if ($order == 'descending') { $sdir = 'desc'; } else { $sdir = 'asc'; } $selectionArgs = array('ot' => 'posting', 'where' => $parentWhere, 'orderBy' => 'createdDate' . ' ' . $sdir); // the current offset which is used to calculate the pagination $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT); // the number of items displayed on a page for pagination $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT); if ($resultsPerPage == 0) { $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT); $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10); } $selectionArgs['currentPage'] = $currentPage; $selectionArgs['resultsPerPage'] = $resultsPerPage; list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs); } // build ModUrl instance for display hooks $currentUrlArgs = array('ot' => $objectType); foreach ($idFields as $idField) { $currentUrlArgs[$idField] = $idValues[$idField]; } // add a call to the posting if ($objectType == 'posting') { MUBoard_Util_Model::addView($idValues); } // get actual time $nowtime = DateUtil::getDatetime(); // set sessionvar with calling time SessionUtil::setVar('muboardonline', $nowtime); $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs); $type = $this->request->getGet()->filter('type', 'admin', FILTER_SANITIZE_STRING); $func = $this->request->getGet()->filter('func', 'view', FILTER_SANITIZE_STRING); $editPostings = ModUtil::getVar($this->name, 'editPostings'); // assign output data to view object. $this->view->assign($objectType, $entity)->assign('postings', $entities)->assign('currentUrlObject', $currentUrlObject)->assign('func', $func)->assign('editPostings', $editPostings)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs)); $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage)); $dom = ZLanguage::getModuleDomain($this->name); // we set Pagetitle $sitename = ModUtil::getVar('ZConfig', 'sitename'); if ($objectType == 'category') { $titletobject = __('Forum - Category: ', $dom); } if ($objectType == 'forum') { $titletobject = __('Forum - Category: ', $dom) . ' ' . $entity['category']['title'] . ' - ' . __('Forum: ', $dom); } if ($objectType == 'posting') { $titletobject = 'Forum: ' . ' ' . $entity['forum']['title'] . ' - ' . __('Issue: ', $dom); } PageUtil::setVar('title', $sitename . ' - ' . $titletobject . ' ' . $entity['title']); // we set description if ($objectType == 'category' || $objectType == 'forum') { $descriptionobject = $entity['description']; } if ($objectType == 'posting') { $descriptionobject = $entity['text']; $descriptionobject = substr($descriptionobject, 0, 160) . '...'; } PageUtil::setVar('description', $descriptionobject); // fetch and return the appropriate template return MUBoard_Util_View::processTemplate($this->view, 'user', $objectType, 'display', $args); }