/** * 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) { $result = parent::initialize($view); if ($result === false) { return $result; } if ($this->mode == 'create') { $modelHelper = new MUVideo_Util_Model($this->view->getServiceManager()); if (!$modelHelper->canBeCreated($this->objectType)) { LogUtil::registerError($this->__('Sorry, but you can not create the collection yet as other items are required which must be created before!')); return $this->view->redirect($this->getRedirectUrl(null)); } } $entity = $this->entityRef; // save entity reference for later reuse $this->entityRef = $entity; $entityData = $entity->toArray(); if (count($this->listFields) > 0) { $helper = new MUVideo_Util_ListEntries($this->view->getServiceManager()); foreach ($this->listFields as $listField => $isMultiple) { $entityData[$listField . 'Items'] = $helper->getEntries($this->objectType, $listField); if ($isMultiple) { $entityData[$listField] = $helper->extractMultiList($entityData[$listField]); } } } // assign data to template as array (makes translatable support easier) $this->view->assign($this->objectTypeLower, $entityData); if ($this->mode == 'edit') { // assign formatted title $this->view->assign('formattedEntityTitle', $entity->getTitleFromDisplayPattern()); } // everything okay, no initialization errors occured return true; }
/** * The muvideoGetListEntry modifier displays the name * or names for a given list item. * * @param string $value The dropdown value to process. * @param string $objectType The treated object type. * @param string $fieldName The list field's name. * @param string $delimiter String used as separator for multiple selections. * * @return string List item name. */ function smarty_modifier_muvideoGetListEntry($value, $objectType = '', $fieldName = '', $delimiter = ', ') { if (empty($value) || empty($objectType) || empty($fieldName)) { return $value; } $serviceManager = ServiceUtil::getManager(); $helper = new MUVideo_Util_ListEntries($serviceManager); return $helper->resolve($value, $objectType, $fieldName, $delimiter); }
/** * 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) { $result = parent::initialize($view); if ($result === false) { return $result; } if ($this->mode == 'create') { $modelHelper = new MUVideo_Util_Model($this->view->getServiceManager()); if (!$modelHelper->canBeCreated($this->objectType)) { LogUtil::registerError($this->__('Sorry, but you can not create the movie yet as other items are required which must be created before!')); return $this->view->redirect($this->getRedirectUrl(null)); } } $entity = $this->entityRef; // assign identifiers of predefined incoming relationships // editable relation, we store the id and assign it now to show it in UI $this->relationPresets['collection'] = FormUtil::getPassedValue('collection', '', 'GET'); if (!empty($this->relationPresets['collection'])) { $relObj = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => 'collection', 'id' => $this->relationPresets['collection'])); if ($relObj != null) { $relObj->addMovie($entity); } } // save entity reference for later reuse $this->entityRef = $entity; $entityData = $entity->toArray(); if (count($this->listFields) > 0) { $helper = new MUVideo_Util_ListEntries($this->view->getServiceManager()); foreach ($this->listFields as $listField => $isMultiple) { $entityData[$listField . 'Items'] = $helper->getEntries($this->objectType, $listField); if ($isMultiple) { $entityData[$listField] = $helper->extractMultiList($entityData[$listField]); } } } // assign data to template as array (makes translatable support easier) $this->view->assign($this->objectTypeLower, $entityData); if ($this->mode == 'edit') { // assign formatted title $this->view->assign('formattedEntityTitle', $entity->getTitleFromDisplayPattern()); } // everything okay, no initialization errors occured return true; }
/** * Returns an array of additional template variables which are specific to the object type treated by this repository. * * @param string $context Usage context (allowed values: controllerAction, api, actionHandler, block, contentType). * @param array $args Additional arguments. * * @return array List of template variables to be assigned. */ public function getAdditionalTemplateParameters($context = '', $args = array()) { if (!in_array($context, array('controllerAction', 'api', 'actionHandler', 'block', 'contentType'))) { $context = 'controllerAction'; } $templateParameters = array(); if ($context == 'controllerAction') { $serviceManager = ServiceUtil::getManager(); if (!isset($args['action'])) { $args['action'] = FormUtil::getPassedValue('func', 'main', 'GETPOST'); } if (in_array($args['action'], array('main', 'view'))) { $templateParameters = $this->getViewQuickNavParameters($context, $args); $listHelper = new MUVideo_Util_ListEntries(ServiceUtil::getManager()); $templateParameters['workflowStateItems'] = $listHelper->getEntries('movie', 'workflowState'); } // initialise Imagine preset instances $imageHelper = new MUVideo_Util_Image($serviceManager); $objectType = 'movie'; $templateParameters[$objectType . 'ThumbPresetUploadOfMovie'] = $imageHelper->getPreset($objectType, 'uploadOfMovie', $context, $args); $templateParameters[$objectType . 'ThumbPresetPoster'] = $imageHelper->getPreset($objectType, 'poster', $context, $args); if (in_array($args['action'], array('display', 'view'))) { // use separate preset for images in related items $templateParameters['relationThumbPreset'] = $imageHelper->getCustomPreset('', '', 'MUVideo_relateditem', $context, $args); } } // in the concrete child class you could do something like // $parameters = parent::getAdditionalTemplateParameters($context, $args); // $parameters['myvar'] = 'myvalue'; // return $parameters; return $templateParameters; }
/** * Retrieve the available actions for a given entity object. * * @param \Zikula_EntityAccess $entity The given entity instance. * * @return array List of available workflow actions. */ public function getActionsForObject($entity) { // get possible actions for this object in it's current workflow state $objectType = $entity['_objectType']; // ensure the correct module name is set, even if another page is called by the user if (!isset($entity['__WORKFLOW__']['module'])) { $workflow = $entity['__WORKFLOW__']; $workflow['module'] = $this->name; $entity['__WORKFLOW__'] = $workflow; } $idColumn = $entity['__WORKFLOW__']['obj_idcolumn']; $wfActions = Zikula_Workflow_Util::getActionsForObject($entity, $objectType, $idColumn, $this->name); // as we use the workflows for multiple object types we must maybe filter out some actions $listHelper = new MUVideo_Util_ListEntries($this->serviceManager); $states = $listHelper->getEntries($objectType, 'workflowState'); $allowedStates = array(); foreach ($states as $state) { $allowedStates[] = $state['value']; } $actions = array(); foreach ($wfActions as $actionId => $action) { $nextState = isset($action['nextState']) ? $action['nextState'] : ''; if ($nextState != '' && !in_array($nextState, $allowedStates)) { continue; } $actions[$actionId] = $action; $actions[$actionId]['buttonClass'] = $this->getButtonClassForAction($actionId); } return $actions; }