Esempio 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)
 {
     $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 Reviews_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 LogUtil::registerError($this->__('No such item.'));
         }
         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 Reviews_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;
 }
Esempio n. 2
0
 /**
  * Process status changes for multiple items.
  *
  * This function processes the items selected in the admin view page.
  * Multiple items may have their state changed or be deleted.
  *
  * @param string $ot     Name of currently used object type.
  * @param string $action The action to be executed.
  * @param array  $items  Identifier list of the items to be processed.
  *
  * @return bool true on sucess, false on failure.
  */
 public function handleSelectedEntries()
 {
     $this->checkCsrfToken();
     $returnUrl = ModUtil::url($this->name, 'admin', 'main');
     // Determine object type
     $objectType = $this->request->request->get('ot', '');
     if (!$objectType) {
         return System::redirect($returnUrl);
     }
     $returnUrl = ModUtil::url($this->name, 'admin', 'view', array('ot' => $objectType));
     // Get other parameters
     $action = $this->request->request->get('action', null);
     $action = strtolower($action);
     $items = $this->request->request->get('items', null);
     $workflowHelper = new Reviews_Util_Workflow($this->serviceManager);
     // process each item
     foreach ($items as $itemid) {
         // check if item exists, and get record instance
         $selectionArgs = array('ot' => $objectType, 'id' => $itemid, 'useJoins' => false);
         $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', $selectionArgs);
         $entity->initWorkflow();
         // check if $action can be applied to this entity (may depend on it's current workflow state)
         $allowedActions = $workflowHelper->getActionsForObject($entity);
         $actionIds = array_keys($allowedActions);
         if (!in_array($action, $actionIds)) {
             // action not allowed, skip this object
             continue;
         }
         $hookAreaPrefix = $entity->getHookAreaPrefix();
         // Let any hooks perform additional validation actions
         $hookType = $action == 'delete' ? 'validate_delete' : 'validate_edit';
         $hook = new Zikula_ValidationHook($hookAreaPrefix . '.' . $hookType, new Zikula_Hook_ValidationProviders());
         $validators = $this->notifyHooks($hook)->getValidators();
         if ($validators->hasErrors()) {
             continue;
         }
         $success = false;
         try {
             // execute the workflow action
             $success = $workflowHelper->executeAction($entity, $action);
         } catch (\Exception $e) {
             LogUtil::registerError($this->__f('Sorry, but an unknown error occured during the %s action. Please apply the changes again!', array($action)));
         }
         if (!$success) {
             continue;
         }
         if ($action == 'delete') {
             LogUtil::registerStatus($this->__('Done! Item deleted.'));
         } else {
             LogUtil::registerStatus($this->__('Done! Item updated.'));
         }
         // Let any hooks know that we have updated or deleted an item
         $hookType = $action == 'delete' ? 'process_delete' : 'process_edit';
         $url = null;
         if ($action != 'delete') {
             $urlArgs = $entity->createUrlArgs();
             $url = new Zikula_ModUrl($this->name, 'admin', 'display', ZLanguage::getLanguageCode(), $urlArgs);
         }
         $hook = new Zikula_ProcessHook($hookAreaPrefix . '.' . $hookType, $entity->createCompositeIdentifier(), $url);
         $this->notifyHooks($hook);
         // An item was updated or deleted, so we clear all cached pages for this item.
         $cacheArgs = array('ot' => $objectType, 'item' => $entity);
         ModUtil::apiFunc($this->name, 'cache', 'clearItemCache', $cacheArgs);
     }
     // clear view cache to reflect our changes
     $this->view->clear_cache();
     return System::redirect($returnUrl);
 }