Beispiel #1
0
 /**
  * Loads the data.
  *
  * @param array $data Data array with parameters.
  */
 public function loadData(&$data)
 {
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     $utilArgs = array('name' => 'detail');
     if (!isset($data['objectType']) || !in_array($data['objectType'], $controllerHelper->getObjectTypes('contentType', $utilArgs))) {
         $data['objectType'] = $controllerHelper->getDefaultObjectType('contentType', $utilArgs);
     }
     $this->objectType = $data['objectType'];
     if (!isset($data['id'])) {
         $data['id'] = null;
     }
     if (!isset($data['moviewidth'])) {
         $data['moviewidth'] = 400;
     }
     $this->moviewidth = $data['moviewidth'];
     if (!isset($data['movieheight'])) {
         $data['movieheight'] = 300;
     }
     $this->movieheight = $data['movieheight'];
     if (!isset($data['displayMode'])) {
         $data['displayMode'] = 'embed';
     }
     $this->id = $data['id'];
     $this->displayMode = $data['displayMode'];
 }
Beispiel #2
0
 /**
  * Determines whether there exist at least one instance of a certain object type in the database.
  *
  * @param string $objectType Name of treated entity type.
  *
  * @return boolean Whether at least one instance exists or not.
  */
 protected function hasExistingInstances($objectType)
 {
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     if (!in_array($objectType, $controllerHelper->getObjectTypes('util', array('util' => 'model', 'action' => 'hasExistingInstances')))) {
         throw new \Exception('Error! Invalid object type received.');
     }
     $entityClass = 'MUVideo_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     return $repository->selectCount() > 0;
 }
Beispiel #3
0
 /**
  * This method provides a handling of edit requests.
  *
  * @param string  $ot           Treated object type.
  * @param string  $tpl          Name of alternative template (to be used instead of the default template).
  * @param boolean $raw          Optional way to display a template instead of fetching it (required for standalone output).
  *
  * @return mixed Output.
  */
 public function getVideos()
 {
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     // parameter specifying which type of objects we are treating
     $objectType = $this->request->query->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'getVideos');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs);
     }
     $permLevel = ACCESS_EDIT;
     $this->throwForbiddenUnless(SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', '::', $permLevel), LogUtil::getErrorMsgPermission());
     // redirect to entity controller
     System::queryStringSetVar('lct', 'user');
     $this->request->query->set('lct', 'user');
     return ModUtil::func($this->name, $objectType, 'getVideos', array('lct' => 'user'));
 }
Beispiel #4
0
 /**
  * This method takes care of the application configuration.
  *
  * @return string Output
  */
 public function getVideos()
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUVideo::', '::', ACCESS_EDIT));
     // DEBUG: permission check aspect ends
     // parameter specifying which type of objects we are treating
     $objectType = isset($args['ot']) && !empty($args['ot']) ? $args['ot'] : $this->request->getGet()->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'getVideos');
     if (!in_array($objectType, MUVideo_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUVideo_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     // create new Form reference
     $view = FormUtil::newForm($this->name, $this);
     // build form handler class name
     $handlerClass = 'MUVideo_Form_Handler_' . ucfirst($objectType) . '_GetVideos';
     // determine the output template
     $viewHelper = new MUVideo_Util_View($this->serviceManager);
     $template = $viewHelper->getViewTemplate($this->view, $objectType, 'getVideos', array());
     // execute form using supplied template and page event handler
     return $view->execute($template, new $handlerClass());
 }
Beispiel #5
0
 /**
  * Returns available admin panel links.
  *
  * @return array Array of admin links.
  */
 public function getLinks()
 {
     $links = array();
     if (SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_READ)) {
         $links[] = array('url' => ModUtil::url($this->name, 'user', 'main'), 'text' => $this->__('Frontend'), 'title' => $this->__('Switch to user area.'), 'class' => 'z-icon-es-home');
     }
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'admin', 'action' => 'getLinks');
     $allowedObjectTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $currentType = $this->request->query->filter('type', 'collection', FILTER_SANITIZE_STRING);
     $currentLegacyType = $this->request->query->filter('lct', 'user', FILTER_SANITIZE_STRING);
     $permLevel = in_array('admin', array($currentType, $currentLegacyType)) ? ACCESS_ADMIN : ACCESS_READ;
     if (in_array('collection', $allowedObjectTypes) && SecurityUtil::checkPermission($this->name . ':Collection:', '::', $permLevel)) {
         $links[] = array('url' => ModUtil::url($this->name, 'admin', 'view', array('ot' => 'collection')), 'text' => $this->__('Collections'), 'title' => $this->__('Collection list'));
     }
     if (in_array('movie', $allowedObjectTypes) && SecurityUtil::checkPermission($this->name . ':Movie:', '::', $permLevel)) {
         $links[] = array('url' => ModUtil::url($this->name, 'admin', 'view', array('ot' => 'movie')), 'text' => $this->__('Movies'), 'title' => $this->__('Movie list'));
     }
     if (SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_ADMIN)) {
         $links[] = array('url' => ModUtil::url($this->name, 'admin', 'config'), 'text' => $this->__('Configuration'), 'title' => $this->__('Manage settings for this application'));
     }
     return $links;
 }
Beispiel #6
0
 /**
  * Displays one item of a certain object type using a separate template for external usages.
  *
  * @param string $ot          The currently treated object type.
  * @param int    $id          Identifier of the entity to be shown.
  * @param string $source      Source of this call (contentType or scribite).
  * @param string $displayMode Display mode (link or embed).
  *
  * @return string Desired data output.
  */
 public function display(array $args = array())
 {
     $getData = $this->request->query;
     $getPostData = $this->request->request;
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $objectType = isset($args['objectType']) ? $args['objectType'] : $getData->filter('ot', '', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'external', 'action' => 'display');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controller', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerType', $utilArgs);
     }
     $id = isset($args['id']) ? $args['id'] : $getData->filter('id', null, FILTER_SANITIZE_STRING);
     $component = $this->name . ':' . ucwords($objectType) . ':';
     /* if (!SecurityUtil::checkPermission($component, $id . '::', ACCESS_READ)) {
            return '';
        }*/
     if (!SecurityUtil::checkPermission('MUVideoContentPlugin::', '::', ACCESS_READ)) {
         return '';
     }
     $source = isset($args['source']) ? $args['source'] : $getData->filter('source', '', FILTER_SANITIZE_STRING);
     if (!in_array($source, array('contentType', 'scribite'))) {
         $source = 'contentType';
     }
     $moviewidth = isset($args['moviewidth']) ? $args['moviewidth'] : $getPostData->filter('moviewidth', '', FILTER_SANITIZE_STRING);
     $movieheight = isset($args['movieheight']) ? $args['movieheight'] : $getPostData->filter('movieheight', '', FILTER_SANITIZE_STRING);
     $displayMode = isset($args['displayMode']) ? $args['displayMode'] : $getData->filter('displayMode', 'embed', FILTER_SANITIZE_STRING);
     if (!in_array($displayMode, array('link', 'embed'))) {
         $displayMode = 'embed';
     }
     $entityClass = 'MUVideo_Entity_' . ucwords($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $repository->setControllerArguments(array());
     $idFields = ModUtil::apiFunc('MUVideo', 'selection', 'getIdFields', array('ot' => $objectType));
     $idValues = array('id' => $id);
     $hasIdentifier = $controllerHelper->isValidIdentifier($idValues);
     if (!$hasIdentifier) {
         return $this->__('Error! Invalid identifier received.');
     }
     // assign object data fetched from the database
     $entity = $repository->selectById($idValues);
     if (!is_array($entity) && !is_object($entity) || !isset($entity[$idFields[0]])) {
         return $this->__('No such item.');
     }
     $entity->initWorkflow();
     $instance = $entity->createCompositeIdentifier() . '::';
     $this->view->setCaching(Zikula_View::CACHE_ENABLED);
     // set cache id
     $accessLevel = ACCESS_READ;
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_COMMENT)) {
         $accessLevel = ACCESS_COMMENT;
     }
     if (SecurityUtil::checkPermission($component, $instance, ACCESS_EDIT)) {
         $accessLevel = ACCESS_EDIT;
     }
     $this->view->setCacheId($objectType . '|' . $id . '|a' . $accessLevel);
     $this->view->assign('objectType', $objectType)->assign('source', $source)->assign($objectType, $entity)->assign('moviewidth', $moviewidth)->assign('movieheight', $movieheight)->assign('displayMode', $displayMode);
     // initialize
     $youtubeId = '';
     // we get the id from the url
     $youtubeId = explode('=', $entity['urlOfYoutube']);
     // assign to template
     $this->view->assign('youtubeId', $youtubeId[1]);
     return $this->view->fetch('external/' . $objectType . '/display.tpl');
 }
Beispiel #7
0
 /**
  * Popup selector for Scribite plugins.
  * Finds items of a certain object type.
  *
  * @param string $objectType The object type.
  * @param string $editor     Name of used Scribite editor.
  * @param string $sort       Sorting field.
  * @param string $sortdir    Sorting direction.
  * @param int    $pos        Current pager position.
  * @param int    $num        Amount of entries to display.
  *
  * @return output The external item finder page
  */
 public function finder()
 {
     PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet('MUVideo'));
     $getData = $this->request->query;
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $objectType = $getData->filter('objectType', 'collection', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'external', 'action' => 'finder');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controller', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerType', $utilArgs);
     }
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUVideo:' . ucfirst($objectType) . ':', '::', ACCESS_COMMENT), LogUtil::getErrorMsgPermission());
     $entityClass = 'MUVideo_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $repository->setControllerArguments(array());
     $editor = $getData->filter('editor', '', FILTER_SANITIZE_STRING);
     if (empty($editor) || !in_array($editor, array('xinha', 'tinymce', 'ckeditor'))) {
         return $this->__('Error: Invalid editor context given for external controller action.');
     }
     // fetch selected categories to reselect them in the output
     // the actual filtering is done inside the repository class
     $categoryIds = ModUtil::apiFunc('MUVideo', 'category', 'retrieveCategoriesFromRequest', array('ot' => $objectType, 'source' => 'GET'));
     $sort = $getData->filter('sort', '', FILTER_SANITIZE_STRING);
     if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) {
         $sort = $repository->getDefaultSortingField();
     }
     $sortdir = $getData->filter('sortdir', '', FILTER_SANITIZE_STRING);
     $sdir = strtolower($sortdir);
     if ($sdir != 'asc' && $sdir != 'desc') {
         $sdir = 'asc';
     }
     $sortParam = $sort . ' ' . $sdir;
     // the current offset which is used to calculate the pagination
     $currentPage = (int) $getData->filter('pos', 1, FILTER_VALIDATE_INT);
     // the number of items displayed on a page for pagination
     $resultsPerPage = (int) $getData->filter('num', 0, FILTER_VALIDATE_INT);
     if ($resultsPerPage == 0) {
         $resultsPerPage = $this->getVar('pageSize', 20);
     }
     $where = '';
     list($entities, $objectCount) = $repository->selectWherePaginated($where, $sortParam, $currentPage, $resultsPerPage);
     foreach ($entities as $k => $entity) {
         $entity->initWorkflow();
     }
     $view = Zikula_View::getInstance('MUVideo', false);
     $view->assign('editorName', $editor)->assign('objectType', $objectType)->assign('items', $entities)->assign('sort', $sort)->assign('sortdir', $sdir)->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage));
     // assign category properties
     $properties = null;
     if (in_array($objectType, $this->categorisableObjectTypes)) {
         $properties = ModUtil::apiFunc('MUVideo', 'category', 'getAllProperties', array('ot' => $objectType));
     }
     $view->assign('properties', $properties)->assign('catIds', $categoryIds);
     return $view->display('external/' . $objectType . '/find.tpl');
 }
Beispiel #8
0
 /**
  * Executes the actual search process.
  *
  * @param array $args List of arguments.
  *
  * @return boolean
  *
  * @throws RuntimeException Thrown if search results can not be saved
  */
 public function search(array $args = array())
 {
     if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_READ)) {
         return '';
     }
     // ensure that database information of Search module is loaded
     ModUtil::dbInfoLoad('Search');
     // save session id as it is used when inserting search results below
     $sessionId = session_id();
     // retrieve list of activated object types
     $searchTypes = isset($args['objectTypes']) ? (array) $args['objectTypes'] : (array) FormUtil::getPassedValue('mUVideoSearchTypes', array(), 'GETPOST');
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'search', 'action' => 'search');
     $allowedTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $entityManager = ServiceUtil::getService('doctrine.entitymanager');
     $currentPage = 1;
     $resultsPerPage = 50;
     foreach ($searchTypes as $objectType) {
         if (!in_array($objectType, $allowedTypes)) {
             continue;
         }
         $whereArray = array();
         $languageField = null;
         switch ($objectType) {
             case 'collection':
                 $whereArray[] = 'tbl.workflowState';
                 $whereArray[] = 'tbl.title';
                 $whereArray[] = 'tbl.description';
                 break;
             case 'movie':
                 $whereArray[] = 'tbl.workflowState';
                 $whereArray[] = 'tbl.title';
                 $whereArray[] = 'tbl.description';
                 $whereArray[] = 'tbl.uploadOfMovie';
                 $whereArray[] = 'tbl.urlOfYoutube';
                 $whereArray[] = 'tbl.poster';
                 break;
         }
         $where = Search_Api_User::construct_where($args, $whereArray, $languageField);
         $entityClass = $this->name . '_Entity_' . ucfirst($objectType);
         $repository = $entityManager->getRepository($entityClass);
         // get objects from database
         list($entities, $objectCount) = $repository->selectWherePaginated($where, '', $currentPage, $resultsPerPage, false);
         if ($objectCount == 0) {
             continue;
         }
         $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
         $descriptionField = $repository->getDescriptionFieldName();
         $entitiesWithDisplayAction = array('collection', 'movie');
         foreach ($entities as $entity) {
             $urlArgs = $entity->createUrlArgs();
             $hasDisplayAction = in_array($objectType, $entitiesWithDisplayAction);
             if ($hasDisplayAction) {
                 $urlArgs['type'] = $objectType;
                 // slug could exceed the maximum length of the 'extra' field, improved in 1.4.0
                 if (isset($urlArgs['slug'])) {
                     unset($urlArgs['slug']);
                 }
             }
             $instanceId = $entity->createCompositeIdentifier();
             // perform permission check
             if (!SecurityUtil::checkPermission($this->name . ':' . ucfirst($objectType) . ':', $instanceId . '::', ACCESS_OVERVIEW)) {
                 continue;
             }
             $title = $entity->getTitleFromDisplayPattern();
             $description = !empty($descriptionField) ? $entity[$descriptionField] : '';
             $created = isset($entity['createdDate']) ? $entity['createdDate']->format('Y-m-d H:i:s') : '';
             $searchItemData = array('title' => $title, 'text' => $description, 'extra' => $hasDisplayAction ? serialize($urlArgs) : '', 'created' => $created, 'module' => $this->name, 'session' => $sessionId);
             if (!DBUtil::insertObject($searchItemData, 'search_result')) {
                 return LogUtil::registerError($this->__('Error! Could not save the search results.'));
             }
         }
     }
     return true;
 }
Beispiel #9
0
 /**
  * Forms custom url string.
  *
  * @param array $args List of arguments.
  *
  * @return string custom url string
  */
 public function encodeurl(array $args = array())
 {
     // check if we have the required input
     if (!isset($args['modname']) || !isset($args['func'])) {
         throw new \InvalidArgumentException(__('Invalid arguments array received.'));
     }
     // set default values
     if (!isset($args['type'])) {
         $args['type'] = 'user';
     }
     if (!isset($args['args'])) {
         $args['args'] = array();
     }
     // return if function url scheme is not being customised
     $customFuncs = array('view', 'display');
     if (!in_array($args['func'], $customFuncs)) {
         return false;
     }
     // initialise url routing rules
     $routerFacade = new MUVideo_RouterFacade();
     // get router itself for convenience
     $router = $routerFacade->getRouter();
     // initialise object type
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('controller' => 'user', 'action' => 'encodeurl');
     $allowedObjectTypes = $controllerHelper->getObjectTypes('api', $utilArgs);
     $objectType = isset($args['args']['ot']) && in_array($args['args']['ot'], $allowedObjectTypes) ? $args['args']['ot'] : $controllerHelper->getDefaultObjectType('api', $utilArgs);
     // initialise group folder
     $groupFolder = $routerFacade->getGroupingFolderFromObjectType($objectType, $args['func'], $args['args']);
     // start pre processing
     // convert object type to group folder
     $args['args']['ot'] = $groupFolder;
     // handle special templates
     $displayDefaultEnding = System::getVar('shorturlsext', 'html');
     $endingPrefix = $args['func'] == 'view' ? '.' : '';
     foreach (array('csv', 'rss', 'atom', 'xml', 'pdf', 'json', 'kml') as $ending) {
         if (!isset($args['args']['use' . $ending . 'ext'])) {
             continue;
         }
         if ($args['args']['use' . $ending . 'ext'] == '1') {
             $args['args'][$args['func'] . 'ending'] = $endingPrefix . $ending;
         }
         unset($args['args']['use' . $ending . 'ext']);
     }
     // fallback to default templates
     if (!isset($args['args'][$args['func'] . 'ending'])) {
         if ($args['func'] == 'view') {
             $args['args'][$args['func'] . 'ending'] = '';
             //'/';
         } else {
             if ($args['func'] == 'display') {
                 $args['args'][$args['func'] . 'ending'] = $displayDefaultEnding;
             }
         }
     }
     if ($args['func'] == 'view') {
         // TODO filter views (e.g. /orders/customer/mr-smith.csv)
         /**
         $filterEntities = array('customer', 'region', 'federalstate', 'country');
         foreach ($filterEntities as $filterEntity) {
             $filterField = $filterEntity . 'id';
             if (!isset($args['args'][$filterField]) || !$args['args'][$filterField]) {
                 continue;
             }
             $filterId = $args['args'][$filterField];
             unset($args['args'][$filterField]);
             
             $filterGroupFolder = $routerFacade->getGroupingFolderFromObjectType($filterEntity, 'display', $args['args']);
             $filterSlug = $routerFacade->getFormattedSlug($filterEntity, 'display', $args['args'], $filterId);
             $result .= $filterGroupFolder . '/' . $filterSlug .'/';
             break;
         }
         */
     } elseif ($args['func'] == 'display') {
         // determine given id
         $id = 0;
         foreach (array('id', strtolower($objectType) . 'id', 'objectid') as $idFieldName) {
             if (isset($args['args'][$idFieldName])) {
                 $id = $args['args'][$idFieldName];
                 unset($args['args'][$idFieldName]);
             }
         }
         // check if we have a valid slug given
         if (isset($args['args']['slug']) && (!$args['args']['slug'] || $args['args']['slug'] == $id)) {
             unset($args['args']['slug']);
         }
         // try to determine missing slug
         if (!isset($args['args']['slug'])) {
             $slug = '';
             if ($id > 0) {
                 $slug = $routerFacade->getFormattedSlug($objectType, $args['func'], $args['args'], $id);
             }
             if (!empty($slug) && $slug != $id) {
                 // add slug expression
                 $args['args']['slug'] = $slug;
             }
         }
         // check if we have one now
         if (!isset($args['args']['slug'])) {
             // readd id as fallback
             $args['args']['id'] = $id;
         }
     }
     // add func as first argument
     $routerArgs = array_merge(array('func' => $args['func']), $args['args']);
     // now create url based on params
     $result = $router->generate(null, $routerArgs);
     // post processing
     if ($args['func'] == 'view' && !empty($args['args']['viewending']) || $args['func'] == 'display') {
         // check if url ends with a trailing slash
         if (substr($result, -1) == '/') {
             // remove the trailing slash
             $result = substr($result, 0, strlen($result) - 1);
         }
     }
     // enforce url name of the module, but do only 1 replacement to avoid changing other params
     $modInfo = ModUtil::getInfoFromName('MUVideo');
     $result = preg_replace('/' . $modInfo['name'] . '/', $modInfo['url'], $result, 1);
     return $result;
 }
Beispiel #10
0
 /**
  * Loads the data.
  *
  * @param array $data Data array with parameters.
  */
 public function loadData(&$data)
 {
     $serviceManager = ServiceUtil::getManager();
     $controllerHelper = new MUVideo_Util_Controller($serviceManager);
     $utilArgs = array('name' => 'list');
     if (!isset($data['objectType']) || !in_array($data['objectType'], $controllerHelper->getObjectTypes('contentType', $utilArgs))) {
         $data['objectType'] = $controllerHelper->getDefaultObjectType('contentType', $utilArgs);
     }
     $this->objectType = $data['objectType'];
     if (!isset($data['sorting'])) {
         $data['sorting'] = 'default';
     }
     if (!isset($data['amount'])) {
         $data['amount'] = 1;
     }
     if (!isset($data['template'])) {
         $data['template'] = 'itemlist_' . $this->objectType . '_display.tpl';
     }
     if (!isset($data['customTemplate'])) {
         $data['customTemplate'] = '';
     }
     if (!isset($data['filter'])) {
         $data['filter'] = '';
     }
     $this->sorting = $data['sorting'];
     $this->amount = $data['amount'];
     $this->template = $data['template'];
     $this->customTemplate = $data['customTemplate'];
     $this->filter = $data['filter'];
     $this->categorisableObjectTypes = array('collection', 'movie');
     // fetch category properties
     $this->catRegistries = array();
     $this->catProperties = array();
     if (in_array($this->objectType, $this->categorisableObjectTypes)) {
         $idFields = ModUtil::apiFunc('MUVideo', 'selection', 'getIdFields', array('ot' => $this->objectType));
         $this->catRegistries = ModUtil::apiFunc('MUVideo', 'category', 'getAllPropertiesWithMainCat', array('ot' => $this->objectType, 'arraykey' => $idFields[0]));
         $this->catProperties = ModUtil::apiFunc('MUVideo', 'category', 'getAllProperties', array('ot' => $this->objectType));
     }
     if (!isset($data['catIds'])) {
         $primaryRegistry = ModUtil::apiFunc('MUVideo', 'category', 'getPrimaryProperty', array('ot' => $this->objectType));
         $data['catIds'] = array($primaryRegistry => array());
         // backwards compatibility
         if (isset($data['catId'])) {
             $data['catIds'][$primaryRegistry][] = $data['catId'];
             unset($data['catId']);
         }
     } elseif (!is_array($data['catIds'])) {
         $data['catIds'] = explode(',', $data['catIds']);
     }
     foreach ($this->catRegistries as $registryId => $registryCid) {
         $propName = '';
         foreach ($this->catProperties as $propertyName => $propertyId) {
             if ($propertyId == $registryId) {
                 $propName = $propertyName;
                 break;
             }
         }
         if (isset($data['catids' . $propName])) {
             $data['catIds'][$propName] = $data['catids' . $propName];
         }
         if (!is_array($data['catIds'][$propName])) {
             if ($data['catIds'][$propName]) {
                 $data['catIds'][$propName] = array($data['catIds'][$propName]);
             } else {
                 $data['catIds'][$propName] = array();
             }
         }
     }
     $this->catIds = $data['catIds'];
 }
Beispiel #11
0
 /**
  * Determines object type using controller util methods.
  *
  * @param string $args['ot'] The object type to retrieve (optional).
  * @param string $methodName Name of calling method.
  *
  * @return string the object type.
  */
 protected function determineObjectType(array $args = array(), $methodName = '')
 {
     $objectType = isset($args['ot']) ? $args['ot'] : '';
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'selection', 'action' => $methodName);
     if (!in_array($objectType, $controllerHelper->getObjectTypes('api', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('api', $utilArgs);
     }
     return $objectType;
 }
Beispiel #12
0
 /**
  * Clear cache for given item. Can be called from other modules to clear an item cache.
  *
  * @param $args['ot']   the treated object type
  * @param $args['item'] the actual object
  */
 public function clearItemCache(array $args = array())
 {
     if (!isset($args['ot']) || !isset($args['item'])) {
         return;
     }
     $objectType = $args['ot'];
     $item = $args['item'];
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('api' => 'cache', 'action' => 'clearItemCache');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) {
         return;
     }
     if ($item && !is_array($item) && !is_object($item)) {
         $item = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $item, 'useJoins' => false, 'slimMode' => true));
     }
     if (!$item) {
         return;
     }
     $instanceId = $item->createCompositeIdentifier();
     // Clear View_cache
     $cacheIds = array();
     $cacheIds[] = 'user_main';
     switch ($objectType) {
         case 'collection':
             $cacheIds[] = 'collection_main';
             $cacheIds[] = $objectType . '_view';
             $cacheIds[] = $objectType . '_display|' . $instanceId;
             break;
         case 'movie':
             $cacheIds[] = 'movie_main';
             $cacheIds[] = $objectType . '_view';
             $cacheIds[] = $objectType . '_display|' . $instanceId;
             break;
     }
     $view = Zikula_View::getInstance('MUVideo');
     foreach ($cacheIds as $cacheId) {
         $view->clear_cache(null, $cacheId);
     }
     // Clear Theme_cache
     $cacheIds = array();
     $cacheIds[] = 'homepage';
     // for homepage (can be assigned in the Settings module)
     $cacheIds[] = 'MUVideo/user/main';
     // main function
     switch ($objectType) {
         case 'collection':
             $cacheIdPrefix = 'MUVideo/' . $objectType . '/';
             $cacheIds[] = $cacheIdPrefix . 'main';
             // main function
             $cacheIds[] = $cacheIdPrefix . 'view/';
             // view function (list views)
             $cacheIds[] = $cacheIdPrefix . 'display/' . $instanceId;
             // display function (detail views)
             break;
         case 'movie':
             $cacheIdPrefix = 'MUVideo/' . $objectType . '/';
             $cacheIds[] = $cacheIdPrefix . 'main';
             // main function
             $cacheIds[] = $cacheIdPrefix . 'view/';
             // view function (list views)
             $cacheIds[] = $cacheIdPrefix . 'display/' . $instanceId;
             // display function (detail views)
             break;
     }
     $theme = Zikula_View_Theme::getInstance();
     $theme->clear_cacheid_allthemes($cacheIds);
 }
Beispiel #13
0
 /**
  * Update block settings.
  *
  * @param array $blockinfo the blockinfo structure
  *
  * @return array the modified blockinfo structure.
  */
 public function update($blockinfo)
 {
     // Get current content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $vars['objectType'] = $this->request->request->filter('objecttype', 'collection', FILTER_SANITIZE_STRING);
     $vars['sorting'] = $this->request->request->filter('sorting', 'default', FILTER_SANITIZE_STRING);
     $vars['amount'] = (int) $this->request->request->filter('amount', 5, FILTER_VALIDATE_INT);
     $vars['template'] = $this->request->request->get('template', '');
     $vars['customTemplate'] = $this->request->request->get('customtemplate', '');
     $vars['filter'] = $this->request->request->get('filter', '');
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     if (!in_array($vars['objectType'], $controllerHelper->getObjectTypes('block'))) {
         $vars['objectType'] = $controllerHelper->getDefaultObjectType('block');
     }
     $primaryRegistry = ModUtil::apiFunc('MUVideo', 'category', 'getPrimaryProperty', array('ot' => $vars['objectType']));
     $vars['catIds'] = array($primaryRegistry => array());
     if (in_array($vars['objectType'], $this->categorisableObjectTypes)) {
         $vars['catIds'] = ModUtil::apiFunc('MUVideo', 'category', 'retrieveCategoriesFromRequest', array('ot' => $vars['objectType']));
     }
     // write back the new contents
     $blockinfo['content'] = BlockUtil::varsToContent($vars);
     // clear the block cache
     $this->view->clear_cache('block/itemlist_display.tpl');
     $this->view->clear_cache('block/itemlist_' . ucfirst($vars['objectType']) . '_display.tpl');
     $this->view->clear_cache('block/itemlist_display_description.tpl');
     $this->view->clear_cache('block/itemlist_' . ucfirst($vars['objectType']) . '_display_description.tpl');
     return $blockinfo;
 }
Beispiel #14
0
 /**
  * Searches for entities for auto completion usage.
  *
  * @param string $ot       Treated object type.
  * @param string $fragment The fragment of the entered item name.
  * @param string $exclude  Comma separated list with ids of other items (to be excluded from search).
  *
  * @return Zikula_Response_Ajax_Plain
  */
 public function getItemListAutoCompletion()
 {
     if (!SecurityUtil::checkPermission($this->name . '::Ajax', '::', ACCESS_EDIT)) {
         return true;
     }
     $objectType = 'collection';
     if ($this->request->isPost() && $this->request->request->has('ot')) {
         $objectType = $this->request->request->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     } elseif ($this->request->isGet() && $this->request->query->has('ot')) {
         $objectType = $this->request->query->filter('ot', 'collection', FILTER_SANITIZE_STRING);
     }
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('controller' => 'ajax', 'action' => 'getItemListAutoCompletion');
     if (!in_array($objectType, $controllerHelper->getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = $controllerHelper->getDefaultObjectType('controllerAction', $utilArgs);
     }
     $entityClass = 'MUVideo_Entity_' . ucfirst($objectType);
     $repository = $this->entityManager->getRepository($entityClass);
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     $fragment = '';
     $exclude = '';
     if ($this->request->isPost() && $this->request->request->has('fragment')) {
         $fragment = $this->request->request->get('fragment', '');
         $exclude = $this->request->request->get('exclude', '');
     } elseif ($this->request->isGet() && $this->request->query->has('fragment')) {
         $fragment = $this->request->query->get('fragment', '');
         $exclude = $this->request->query->get('exclude', '');
     }
     $exclude = !empty($exclude) ? array($exclude) : array();
     // parameter for used sorting field
     $sort = $this->request->query->get('sort', '');
     if (empty($sort) || !in_array($sort, $repository->getAllowedSortingFields())) {
         $sort = $repository->getDefaultSortingField();
     }
     $sortParam = $sort . ' asc';
     $currentPage = 1;
     $resultsPerPage = 20;
     // get objects from database
     list($entities, $objectCount) = $repository->selectSearch($fragment, $exclude, $sortParam, $currentPage, $resultsPerPage);
     $out = '<ul>';
     if ((is_array($entities) || is_object($entities)) && count($entities) > 0) {
         $descriptionFieldName = $repository->getDescriptionFieldName();
         $previewFieldName = $repository->getPreviewFieldName();
         if (!empty($previewFieldName)) {
             $imageHelper = new MUVideo_Util_Image($this->serviceManager);
             $imagineManager = $imageHelper->getManager($objectType, $previewFieldName, 'controllerAction', $utilArgs);
         }
         foreach ($entities as $item) {
             // class="informal" --> show in dropdown, but do nots copy in the input field after selection
             $itemTitle = $item->getTitleFromDisplayPattern();
             $itemTitleStripped = str_replace('"', '', $itemTitle);
             $itemDescription = isset($item[$descriptionFieldName]) && !empty($item[$descriptionFieldName]) ? $item[$descriptionFieldName] : '';
             //$this->__('No description yet.');
             $itemId = $item->createCompositeIdentifier();
             $out .= '<li id="' . $itemId . '" title="' . $itemTitleStripped . '">';
             $out .= '<div class="itemtitle">' . $itemTitle . '</div>';
             if (!empty($itemDescription)) {
                 $out .= '<div class="itemdesc informal">' . substr($itemDescription, 0, 50) . '&hellip;</div>';
             }
             // check for preview image
             if (!empty($previewFieldName) && !empty($item[$previewFieldName]) && isset($item[$previewFieldName . 'FullPath'])) {
                 $fullObjectId = $objectType . '-' . $itemId;
                 $thumbImagePath = $imagineManager->getThumb($item[$previewFieldName], $fullObjectId);
                 $preview = '<img src="' . $thumbImagePath . '" width="50" height="50" alt="' . $itemTitleStripped . '" />';
                 $out .= '<div id="itemPreview' . $itemId . '" class="itempreview informal">' . $preview . '</div>';
             }
             $out .= '</li>';
         }
     }
     $out .= '</ul>';
     // return response
     return new Zikula_Response_Ajax_Plain($out);
 }