/**
 * The muvideoObjectState modifier displays the name of a given object's workflow state.
 * Examples:
 *    {$item.workflowState|muvideoObjectState}       {* with visual feedback *}
 *    {$item.workflowState|muvideoObjectState:false} {* no ui feedback *}
 *
 * @param string  $state      Name of given workflow state.
 * @param boolean $uiFeedback Whether the output should include some visual feedback about the state.
 *
 * @return string Enriched and translated workflow state ready for display.
 */
function smarty_modifier_muvideoObjectState($state = 'initial', $uiFeedback = true)
{
    $serviceManager = ServiceUtil::getManager();
    $workflowHelper = new MUVideo_Util_Workflow($serviceManager);
    $stateInfo = $workflowHelper->getStateInfo($state);
    $result = $stateInfo['text'];
    if ($uiFeedback === true) {
        $result = '<img src="' . System::getBaseUrl() . 'images/icons/extrasmall/' . $stateInfo['ui'] . 'led.png" width="16" height="16" alt="' . $result . '" />&nbsp;&nbsp;' . $result;
    }
    return $result;
}
Exemplo n.º 2
0
 /**
  * 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 MUVideo_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;
 }
Exemplo n.º 3
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 $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();
     $redirectUrl = ModUtil::url($this->name, 'admin', 'main', array('ot' => 'movie'));
     $objectType = 'movie';
     // Get parameters
     $action = $this->request->request->get('action', null);
     $items = $this->request->request->get('items', null);
     $action = strtolower($action);
     $workflowHelper = new MUVideo_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, 'movie', '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 $this->redirect($redirectUrl);
 }
Exemplo n.º 4
0
 /**
  * Resets workflow data back to initial state.
  * To be used after cloning an entity object.
  */
 public function resetWorkflow()
 {
     $this->setWorkflowState('initial');
     $serviceManager = ServiceUtil::getManager();
     $workflowHelper = new MUVideo_Util_Workflow($serviceManager);
     $schemaName = $workflowHelper->getWorkflowName($this['_objectType']);
     $this['__WORKFLOW__'] = array('module' => 'MUVideo', 'state' => $this['workflowState'], 'obj_table' => $this['_objectType'], 'obj_idcolumn' => 'id', 'obj_id' => 0, 'schemaname' => $schemaName);
 }
Exemplo n.º 5
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;
 }