Exemple #1
0
 /**
  * This method provides a item detail view.
  *
  * @param string  $tpl          Name of alternative template (to be used instead of the default template).
  * @param boolean $raw          Optional way to display a template instead of fetching it (required for standalone output).
  *
  * @return mixed Output.
  */
 public function display()
 {
     $legacyControllerType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING);
     System::queryStringSetVar('type', $legacyControllerType);
     $this->request->query->set('type', $legacyControllerType);
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // parameter specifying which type of objects we are treating
     $objectType = 'movie';
     $utilArgs = array('controller' => 'movie', 'action' => 'display');
     $permLevel = $legacyControllerType == 'admin' ? ACCESS_ADMIN : ACCESS_READ;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission());
     $entityClass = $this->name . '_Entity_' . ucwords($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $repository->setControllerArguments(array());
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to view
     $idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $objectType, $idFields);
     $hasIdentifier = $controllerHelper->isValidIdentifier($idValues);
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $selectionArgs = array('ot' => $objectType, 'id' => $idValues);
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', $selectionArgs);
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     unset($idValues);
     $entity->initWorkflow();
     // build ModUrl instance for display hooks; also create identifier for permission check
     $currentUrlArgs = $entity->createUrlArgs();
     $instanceId = $entity->createCompositeIdentifier();
     $currentUrlArgs['id'] = $instanceId;
     // TODO remove this
     $currentUrlObject = new Zikula_ModUrl($this->name, 'movie', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs);
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucwords($objectType) . ':', $instanceId . '::', $permLevel), LogUtil::getErrorMsgPermission());
     $viewHelper = new MUVideo_Util_View($this->serviceManager);
     $templateFile = $viewHelper->getViewTemplate($this->view, $objectType, 'display', array());
     // set cache id
     $component = $this->name . ':' . ucwords($objectType) . ':';
     $instance = $instanceId . '::';
     $accessLevel = ACCESS_READ;
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) {
         $accessLevel = ACCESS_COMMENT;
     }
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) {
         $accessLevel = ACCESS_EDIT;
     }
     $this->view->setCacheId($objectType . '|' . $instanceId . '|a' . $accessLevel);
     // assign output data to view object.
     $this->view->assign($objectType, $entity)->assign('currentUrlObject', $currentUrlObject)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // initialize
     $youtubeId = '';
     // we get the id from the url
     $youtubeId = explode('=', $entity['urlOfYoutube']);
     // assign to template
     $this->view->assign('youtubeId', $youtubeId[1]);
     // fetch and return the appropriate template
     return $viewHelper->processTemplate($this->view, $objectType, 'display', array(), $templateFile);
 }
Exemple #2
0
 /**
  * This method provides a handling of simple delete requests.
  *
  * @param int     $id           Identifier of entity to be shown.
  * @param boolean $confirmation Confirm the deletion, else a confirmation page is displayed.
  * @param string  $tpl          Name of alternative template (to be used instead of the default template).
  * @param boolean $raw          Optional way to display a template instead of fetching it (required for standalone output).
  *
  * @return mixed Output.
  */
 public function delete()
 {
     $legacyControllerType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING);
     System::queryStringSetVar('type', $legacyControllerType);
     $this->request->query->set('type', $legacyControllerType);
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // parameter specifying which type of objects we are treating
     $objectType = 'movie';
     $utilArgs = array('controller' => 'movie', 'action' => 'delete');
     $permLevel = $legacyControllerType == 'admin' ? ACCESS_ADMIN : ACCESS_DELETE;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission());
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to delete
     $idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $objectType, $idFields);
     $hasIdentifier = $controllerHelper->isValidIdentifier($idValues);
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $selectionArgs = array('ot' => $objectType, 'id' => $idValues);
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', $selectionArgs);
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     $entity->initWorkflow();
     // determine available workflow actions
     $workflowHelper = new MUVideo_Util_Workflow($this->serviceManager);
     $actions = $workflowHelper->getActionsForObject($entity);
     if ($actions === false || !is_array($actions)) {
         return LogUtil::registerError($this->__('Error! Could not determine workflow actions.'));
     }
     // check whether deletion is allowed
     $deleteActionId = 'delete';
     $deleteAllowed = false;
     foreach ($actions as $actionId => $action) {
         if ($actionId != $deleteActionId) {
             continue;
         }
         $deleteAllowed = true;
         break;
     }
     if (!$deleteAllowed) {
         return LogUtil::registerError($this->__('Error! It is not allowed to delete this movie.'));
     }
     $confirmation = (bool) $this->request->request->filter('confirmation', false, FILTER_VALIDATE_BOOLEAN);
     if ($confirmation && $deleteAllowed) {
         $this->checkCsrfToken();
         $hookAreaPrefix = $entity->getHookAreaPrefix();
         $hookType = 'validate_delete';
         // Let any hooks perform additional validation actions
         $hook = new Zikula_ValidationHook($hookAreaPrefix . '.' . $hookType, new Zikula_Hook_ValidationProviders());
         $validators = $this->notifyHooks($hook)->getValidators();
         if (!$validators->hasErrors()) {
             // execute the workflow action
             $success = $workflowHelper->executeAction($entity, $deleteActionId);
             if ($success) {
                 $this->registerStatus($this->__('Done! Item deleted.'));
             }
             // Let any hooks know that we have created, updated or deleted the movie
             $hookType = 'process_delete';
             $hook = new Zikula_ProcessHook($hookAreaPrefix . '.' . $hookType, $entity->createCompositeIdentifier());
             $this->notifyHooks($hook);
             // The movie was deleted, so we clear all cached pages this item.
             $cacheArgs = array('ot' => $objectType, 'item' => $entity);
             ModUtil::apiFunc($this->name, 'cache', 'clearItemCache', $cacheArgs);
             if ($legacyControllerType == 'admin') {
                 // redirect to the list of movies
                 $redirectUrl = ModUtil::url($this->name, 'movie', 'view', array('lct' => $legacyControllerType));
             } else {
                 // redirect to the list of movies
                 $redirectUrl = ModUtil::url($this->name, 'movie', 'view', array('lct' => $legacyControllerType));
             }
             return $this->redirect($redirectUrl);
         }
     }
     $entityClass = $this->name . '_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     // set caching id
     $this->view->setCaching(Zikula_View::CACHE_DISABLED);
     // assign the object we loaded above
     $this->view->assign($objectType, $entity)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // fetch and return the appropriate template
     $viewHelper = new MUVideo_Util_View($this->serviceManager);
     return $viewHelper->processTemplate($this->view, $objectType, 'delete', array());
 }
Exemple #3
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)
 {
     $this->inlineUsage = UserUtil::getTheme() == 'Printer' ? true : false;
     $this->idPrefix = $this->request->query->filter('idp', '', FILTER_SANITIZE_STRING);
     // initialise redirect goal
     $this->returnTo = $this->request->query->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);
     $this->idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $this->objectType));
     // retrieve identifier of the object we wish to view
     $controllerHelper = new MUVideo_Util_Controller($this->view->getServiceManager());
     $this->idValues = $controllerHelper->retrieveIdentifier($this->request, array(), $this->objectType, $this->idFields);
     $hasIdentifier = $controllerHelper->isValidIdentifier($this->idValues);
     $entity = null;
     $this->mode = $hasIdentifier ? 'edit' : 'create';
     if ($this->mode == 'edit') {
         if (!SecurityUtil::checkPermission($this->permissionComponent, $this->createCompositeIdentifier() . '::', ACCESS_EDIT)) {
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForEdit();
         if (!is_object($entity)) {
             return false;
         }
         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)));
         }
     } else {
         if (!SecurityUtil::checkPermission($this->permissionComponent, '::', ACCESS_EDIT)) {
             return LogUtil::registerPermissionError();
         }
         $entity = $this->initEntityForCreation();
     }
     $this->view->assign('mode', $this->mode)->assign('inlineUsage', $this->inlineUsage);
     // save entity reference for later reuse
     $this->entityRef = $entity;
     if ($this->hasCategories === true) {
         $this->initCategoriesForEdit();
     }
     $workflowHelper = new MUVideo_Util_Workflow($this->view->getServiceManager());
     $actions = $workflowHelper->getActionsForObject($entity);
     if ($actions === false || !is_array($actions)) {
         return LogUtil::registerError($this->__('Error! Could not determine workflow actions.'));
     }
     // assign list of allowed actions to the view for further processing
     $this->view->assign('actions', $actions);
     // everything okay, no initialization errors occured
     return true;
 }