/** * 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); }
/** * 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()); }