Exemplo n.º 1
0
 /**
  * Display the block.
  *
  * @param array $blockinfo the blockinfo structure
  *
  * @return string output of the rendered block
  */
 public function display($blockinfo)
 {
     // only show block content if the user has the required permissions
     if (!SecurityUtil::checkPermission('Reviews:ModerationBlock:', "{$blockinfo['title']}::", ACCESS_OVERVIEW)) {
         return false;
     }
     // check if the module is available at all
     if (!ModUtil::available('Reviews')) {
         return false;
     }
     if (!UserUtil::isLoggedIn()) {
         return false;
     }
     ModUtil::initOOModule('Reviews');
     $this->view->setCaching(Zikula_View::CACHE_DISABLED);
     $template = $this->getDisplayTemplate($vars);
     $workflowHelper = new Reviews_Util_Workflow($this->serviceManager);
     $amounts = $workflowHelper->collectAmountOfModerationItems();
     // assign block vars and fetched data
     $this->view->assign('moderationObjects', $amounts);
     // set a block title
     if (empty($blockinfo['title'])) {
         $blockinfo['title'] = $this->__('Moderation');
     }
     $blockinfo['content'] = $this->view->fetch($template);
     // return the block to the theme
     return BlockUtil::themeBlock($blockinfo);
 }
/**
 * The reviewsObjectState modifier displays the name of a given object's workflow state.
 * Examples:
 *    {$item.workflowState|reviewsObjectState}       {* with visual feedback *}
 *    {$item.workflowState|reviewsObjectState: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_reviewsObjectState($state = 'initial', $uiFeedback = true)
{
    $serviceManager = ServiceUtil::getManager();
    $workflowHelper = new Reviews_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;
}
/**
 * The reviewsModerationObjects plugin determines the amount of unapproved objects.
 * It uses the same logic as the moderation block and the pending content listener.
 *
 * @param  array       $params All attributes passed to this function from the template.
 * @param  Zikula_View $view   Reference to the view object.
 */
function smarty_function_reviewsModerationObjects($params, $view)
{
    if (!isset($params['assign']) || empty($params['assign'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('reviewsModerationObjects', 'assign')));
        return false;
    }
    $serviceManager = $view->getServiceManager();
    $workflowHelper = new Reviews_Util_Workflow($serviceManager);
    $result = $workflowHelper->collectAmountOfModerationItems();
    $view->assign($params['assign'], $result);
}
Exemplo n.º 4
0
 /**
  * Listener for the 'get.pending_content' event with registration requests and
  * other submitted data pending approval.
  *
  * When a 'get.pending_content' event is fired, the Users module will respond with the
  * number of registration requests that are pending administrator approval. The number
  * pending may not equal the total number of outstanding registration requests, depending
  * on how the 'moderation_order' module configuration variable is set, and whether e-mail
  * address verification is required.
  * If the 'moderation_order' variable is set to require approval after e-mail verification
  * (and e-mail verification is also required) then the number of pending registration
  * requests will equal the number of registration requested that have completed the
  * verification process but have not yet been approved. For other values of
  * 'moderation_order', the number should equal the number of registration requests that
  * have not yet been approved, without regard to their current e-mail verification state.
  * If moderation of registrations is not enabled, then the value will always be 0.
  * In accordance with the 'get_pending_content' conventions, the count of pending
  * registrations, along with information necessary to access the detailed list, is
  * assemped as a {@link Zikula_Provider_AggregateItem} and added to the event
  * subject's collection.
  *
  * @param Zikula_Event $event The event instance.
  */
 public static function pendingContentListener(Zikula_Event $event)
 {
     $serviceManager = ServiceUtil::getManager();
     $workflowHelper = new Reviews_Util_Workflow($serviceManager);
     $modname = 'Reviews';
     $useJoins = false;
     $collection = new Zikula_Collection_Container($modname);
     $amounts = $workflowHelper->collectAmountOfModerationItems();
     if (count($amounts) > 0) {
         foreach ($amounts as $amountInfo) {
             $aggregateType = $amountInfo['aggregateType'];
             $description = $amountInfo['description'];
             $amount = $amountInfo['amount'];
             $viewArgs = array('ot' => $amountInfo['objectType'], 'workflowState' => $amountInfo['state']);
             $aggregateItem = new Zikula_Provider_AggregateItem($aggregateType, $description, $amount, 'admin', 'view', $viewArgs);
             $collection->add($aggregateItem);
         }
         // add collected items for pending content
         if ($collection->count() > 0) {
             $event->getSubject()->add($collection);
         }
     }
 }
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 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;
 }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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 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;
 }
Exemplo n.º 8
0
 /**
  * Resets workflow data back to initial state.
  * To be used after cloning an entity object.
  */
 public function resetWorkflow()
 {
     $this->setWorkflowState('initial');
     $workflowHelper = new Reviews_Util_Workflow(ServiceUtil::getManager());
     $schemaName = $workflowHelper->getWorkflowName($this['_objectType']);
     $this['__WORKFLOW__'] = array('module' => 'Reviews', 'state' => $this['workflowState'], 'obj_table' => $this['_objectType'], 'obj_idcolumn' => 'id', 'obj_id' => 0, 'schemaname' => $schemaName);
 }