コード例 #1
0
ファイル: Edit.php プロジェクト: rmaiwald/MUBoard
 /**
  * Initialize form handler.
  *
  * This method takes care of all necessary initialisation of our data and form states.
  *
  * @return boolean False in case of initialization errors, otherwise true.
  */
 public function initialize(Zikula_Form_View $view)
 {
     $this->inlineUsage = UserUtil::getTheme() == 'Printer' ? true : false;
     $this->idPrefix = $this->request->getGet()->filter('idp', '', FILTER_SANITIZE_STRING);
     // initialise redirect goal
     $this->returnTo = $this->request->getGet()->filter('returnTo', null, FILTER_SANITIZE_STRING);
     // store current uri for repeated creations
     $this->repeatReturnUrl = System::getCurrentURI();
     $this->permissionComponent = $this->name . ':' . $this->objectTypeCapital . ':';
     $entityClass = $this->name . '_Entity_' . ucfirst($this->objectType);
     $objectTemp = new $entityClass();
     $this->idFields = $objectTemp->get_idFields();
     // retrieve identifier of the object we wish to view
     $this->idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, array(), $this->objectType, $this->idFields);
     $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($this->idValues);
     $entity = null;
     $this->mode = $hasIdentifier ? 'edit' : 'create';
     if ($this->mode == 'edit') {
         if (!SecurityUtil::checkPermission($this->permissionComponent, '::', ACCESS_EDIT)) {
             // set an error message and return false
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForEdit();
         if ($this->hasPageLockSupport === true && ModUtil::available('PageLock')) {
             // try to guarantee that only one person at a time can be editing this entity
             /*  ModUtil::apiFunc('PageLock', 'user', 'pageLock',
                 array('lockName'  => $this->name . $this->objectTypeCapital . $this->createCompositeIdentifier(),
                         'returnUrl' => $this->getRedirectUrl(null, $entity))); */
         }
     } else {
         if (!SecurityUtil::checkPermission($this->permissionComponent, '::', ACCESS_ADD)) {
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForCreation($entityClass);
     }
     $this->view->assign('mode', $this->mode)->assign('inlineUsage', $this->inlineUsage);
     // We set text field to empty if entity class is posting
     if ($this->request->query->filter('ot', 'category', FILTER_SANITIZE_STRING) == 'posting' && $this->request->query->filter('func', 'main', FILTER_SANITIZE_STRING) == 'display') {
         $entity['text'] = '';
     }
     $entityData = $entity->toArray();
     // assign data to template as array (makes translatable support easier)
     $this->view->assign($this->objectTypeLower, $entityData);
     // save entity reference for later reuse
     $this->entityRef = $entity;
     $this->initializeAdditions();
     // everything okay, no initialization errors occured
     return true;
 }
コード例 #2
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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.'));
     // build ModUrl instance for display hooks
     $currentUrlArgs = array('ot' => $objectType);
     foreach ($idFields as $idField) {
         $currentUrlArgs[$idField] = $idValues[$idField];
     }
     $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs);
     // assign output data to view object.
     $this->view->assign($objectType, $entity)->assign('currentUrlObject', $currentUrlObject)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // fetch and return the appropriate template
     return MUBoard_Util_View::processTemplate($this->view, 'user', $objectType, 'display', $args);
 }
コード例 #3
0
ファイル: Admin.php プロジェクト: rmaiwald/MUBoard
 /**
  * This method provides a generic handling of simple delete requests.
  *
  * @param string  $ot           Treated object type.
  * @param int     $id           Identifier of entity to be deleted.
  * @param boolean $confirmation Confirm the deletion, else a confirmation page is displayed.
  * @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 delete($args)
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_ADMIN));
     // 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' => 'admin', 'action' => 'delete');
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to delete
     $idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, $args, $objectType, $idFields);
     $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($idValues);
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues));
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     $confirmation = (bool) (isset($args['confirmation']) && !empty($args['confirmation'])) ? $args['confirmation'] : $this->request->getPost()->filter('confirmation', false, FILTER_VALIDATE_BOOLEAN);
     if ($confirmation) {
         $this->checkCsrfToken();
         // TODO call pre delete validation hooks
         $this->entityManager->remove($entity);
         $this->entityManager->flush();
         $this->registerStatus($this->__('Done! Item deleted.'));
         // TODO call post delete process hooks
         // clear view cache to reflect our changes
         $this->view->clear_cache();
         // redirect to the list of the current object type
         $this->redirect(ModUtil::url($this->name, 'admin', 'view', array('ot' => $objectType)));
     }
     $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     // assign the object we loaded above
     $this->view->assign($objectType, $entity)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // fetch and return the appropriate template
     return MUBoard_Util_View::processTemplate($this->view, 'admin', $objectType, 'delete', $args);
 }
コード例 #4
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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);
 }