예제 #1
0
파일: Admin.php 프로젝트: rmaiwald/Reviews
 /**
  * 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);
 }
예제 #2
0
파일: Edit.php 프로젝트: rmaiwald/Reviews
 /**
  * This method executes a certain workflow action.
  *
  * @param Array $args Arguments from handleCommand method.
  *
  * @return bool Whether everything worked well or not.
  */
 public function applyAction(array $args = array())
 {
     // get treated entity reference from persisted member var
     $entity = $this->entityRef;
     $action = $args['commandName'];
     try {
         // execute the workflow action
         $workflowHelper = new Reviews_Util_Workflow($this->view->getServiceManager());
         $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)));
     }
     $this->addDefaultMessage($args, $success);
     if ($success && $this->mode == 'create') {
         // store new identifier
         foreach ($this->idFields as $idField) {
             $this->idValues[$idField] = $entity[$idField];
         }
     }
     return $success;
 }