Пример #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);
 }
Пример #2
0
 /**
  * Listener for the `user.account.delete` event.
  *
  * Occurs after a user is deleted from the system.
  * All handlers are notified.
  * The full user record deleted is available as the subject.
  * This is a storage-level event, not a UI event. It should not be used for UI-level actions such as redirects.
  * The subject of the event is set to the user record that is being deleted.
  *
  * @param Zikula_Event $event The event instance.
  */
 public static function delete(Zikula_Event $event)
 {
     ModUtil::initOOModule('Reviews');
     $userRecord = $event->getSubject();
     $uid = $userRecord['uid'];
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     $repo = $entityManager->getRepository('Reviews_Entity_Review');
     // delete all reviews created by this user
     $repo->deleteCreator($uid);
     // note you could also do: $repo->updateCreator($uid, 2);
     // set last editor to admin (2) for all reviews updated by this user
     $repo->updateLastEditor($uid, 2);
     // note you could also do: $repo->deleteLastEditor($uid);
 }
Пример #3
0
 public function display()
 {
     $dom = ZLanguage::getModuleDomain('MUBoard');
     ModUtil::initOOModule('MUBoard');
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     $repository = $entityManager->getRepository('MUBoard_Entity_' . ucfirst($this->objectType));
     $idFields = ModUtil::apiFunc('MUBoard', 'selection', 'getIdFields', array('ot' => $objectType));
     $sortParam = '';
     if ($this->sorting == 'random') {
         $sortParam = 'RAND()';
     } elseif ($this->sorting == 'newest') {
         if (count($idFields) == 1) {
             $sortParam = $idFields[0] . ' DESC';
         } else {
             foreach ($idFields as $idField) {
                 if (!empty($sortParam)) {
                     $sortParam .= ', ';
                 }
                 $sortParam .= $idField . ' ASC';
             }
         }
     } elseif ($this->sorting == 'default') {
         $sortParam = $repository->getDefaultSortingField() . ' ASC';
     }
     $resultsPerPage = $this->amount ? $this->amount : 1;
     // get objects from database
     $selectionArgs = array('ot' => $objectType, 'where' => $this->filter, 'orderBy' => $sortParam, 'currentPage' => 1, 'resultsPerPage' => $resultsPerPage);
     list($entities, $objectCount) = ModUtil::apiFunc('MUBoard', 'selection', 'getEntitiesPaginated', $selectionArgs);
     $this->view->setCaching(true);
     $data = array('objectType' => $this->objectType, 'sorting' => $this->sorting, 'amount' => $this->amount, 'filter' => $this->filter, 'template' => $this->template);
     // assign block vars and fetched data
     $this->view->assign('vars', $data)->assign('objectType', $this->objectType)->assign('items', $entities)->assign($repository->getAdditionalTemplateParameters('contentType'));
     $output = '';
     if (!empty($this->template) && $this->view->template_exists('contenttype/' . $this->template)) {
         $output = $this->view->fetch('contenttype/' . $this->template);
     }
     $templateForObjectType = str_replace('itemlist_', 'itemlist_' . ucwords($this->objectType) . '_', $this->template);
     if ($this->view->template_exists('contenttype/' . $templateForObjectType)) {
         $output = $this->view->fetch('contenttype/' . $templateForObjectType);
     } elseif ($this->view->template_exists('contenttype/' . $this->template)) {
         $output = $this->view->fetch('contenttype/' . $this->template);
     } else {
         $output = $this->view->fetch('contenttype/itemlist_display.tpl');
     }
     return $output;
 }
Пример #4
0
 /**
  * Listener for the `user.account.delete` event.
  *
  * Occurs after a user is deleted from the system.
  * All handlers are notified.
  * The full user record deleted is available as the subject.
  * This is a storage-level event, not a UI event. It should not be used for UI-level actions such as redirects.
  * The subject of the event is set to the user record that is being deleted.
  *
  * @param Zikula_Event $event The event instance.
  */
 public static function delete(Zikula_Event $event)
 {
     ModUtil::initOOModule('MUVideo');
     $userRecord = $event->getSubject();
     $uid = $userRecord['uid'];
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     $repo = $entityManager->getRepository('MUVideo_Entity_Collection');
     // set creator to admin (2) for all collections created by this user
     $repo->updateCreator($uid, 2);
     // set last editor to admin (2) for all collections updated by this user
     $repo->updateLastEditor($uid, 2);
     $repo = $entityManager->getRepository('MUVideo_Entity_Movie');
     // set creator to admin (2) for all movies created by this user
     $repo->updateCreator($uid, 2);
     // set last editor to admin (2) for all movies updated by this user
     $repo->updateLastEditor($uid, 2);
 }
Пример #5
0
 /**
  * Returns the content for a given Mailz plugin.
  *
  * @param array    $args                List of arguments.
  * @param int      $args['pluginid']    id number of plugin (internal id for this module, see getPlugins method).
  * @param string   $args['params']      optional, show specific one or all otherwise.
  * @param int      $args['uid']         optional, user id for user specific content.
  * @param string   $args['contenttype'] h or t for html or text.
  * @param datetime $args['last']        timestamp of last newsletter.
  *
  * @return string output of plugin template.
  */
 public function getContent(array $args = array())
 {
     ModUtil::initOOModule('Reviews');
     // $args is something like:
     // Array ( [uid] => 5 [contenttype] => h [pluginid] => 1 [nid] => 1 [last] => 0000-00-00 00:00:00 [params] => Array ( [] => ) ) 1
     $objectType = 'review';
     $entityClass = 'Reviews_Entity_' . ucwords($objectType);
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     $repository = $entityManager->getRepository($entityClass);
     $idFields = ModUtil::apiFunc('Reviews', 'selection', 'getIdFields', array('ot' => $objectType));
     $sortParam = '';
     if ($args['pluginid'] == 2) {
         $sortParam = 'RAND()';
     } elseif ($args['pluginid'] == 1) {
         if (count($idFields) == 1) {
             $sortParam = $idFields[0] . ' DESC';
         } else {
             foreach ($idFields as $idField) {
                 if (!empty($sortParam)) {
                     $sortParam .= ', ';
                 }
                 $sortParam .= $idField . ' ASC';
             }
         }
     }
     $where = '';
     $resultsPerPage = 3;
     // get objects from database
     $selectionArgs = array('ot' => $objectType, 'where' => $where, 'orderBy' => $sortParam, 'currentPage' => 1, 'resultsPerPage' => $resultsPerPage);
     list($entities, $objectCount) = ModUtil::apiFunc('Reviews', 'selection', 'getEntitiesPaginated', $selectionArgs);
     $view = Zikula_View::getInstance('Reviews', true);
     //$data = array('sorting' => $this->sorting, 'amount' => $this->amount, 'filter' => $this->filter, 'template' => $this->template);
     //$view->assign('vars', $data);
     $view->assign('objectType', $objectType)->assign('items', $entities)->assign($repository->getAdditionalTemplateParameters('api', array('name' => 'mailz')));
     if ($args['contenttype'] == 't') {
         /* text */
         return $view->fetch('mailz/itemlist_review_text.tpl');
     } else {
         //return $view->fetch('contenttype/itemlist_display.html');
         return $view->fetch('mailz/itemlist_review_html.tpl');
     }
 }
Пример #6
0
 /**
  * Displays the data.
  *
  * @return string The returned output.
  */
 public function display()
 {
     $dom = ZLanguage::getModuleDomain('MUVideo');
     ModUtil::initOOModule('MUVideo');
     $entityClass = 'MUVideo_Entity_' . ucfirst($this->objectType);
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     $repository = $entityManager->getRepository($entityClass);
     // ensure that the view does not look for templates in the Content module (#218)
     $this->view->toplevelmodule = 'MUVideo';
     $this->view->setCaching(Zikula_View::CACHE_ENABLED);
     // set cache id
     $component = 'MUVideo:' . ucfirst($this->objectType) . ':';
     $instance = '::';
     $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('view|ot_' . $this->objectType . '_sort_' . $this->sorting . '_amount_' . $this->amount . '_' . $accessLevel);
     $template = $this->getDisplayTemplate();
     // if page is cached return cached content
     if ($this->view->is_cached($template)) {
         return $this->view->fetch($template);
     }
     // create query
     $where = $this->filter;
     $orderBy = $this->getSortParam($repository);
     $qb = $repository->genericBaseQuery($where, $orderBy);
     // apply category filters
     if (in_array($this->objectType, $this->categorisableObjectTypes)) {
         if (is_array($this->catIds) && count($this->catIds) > 0) {
             $qb = ModUtil::apiFunc('MUVideo', 'category', 'buildFilterClauses', array('qb' => $qb, 'ot' => $this->objectType, 'catids' => $this->catIds));
         }
     }
     // get objects from database
     $currentPage = 1;
     $resultsPerPage = isset($this->amount) ? $this->amount : 1;
     list($query, $count) = $repository->getSelectWherePaginatedQuery($qb, $currentPage, $resultsPerPage);
     $entities = $repository->retrieveCollectionResult($query, $orderBy, true);
     $data = array('objectType' => $this->objectType, 'catids' => $this->catIds, 'sorting' => $this->sorting, 'amount' => $this->amount, 'template' => $this->template, 'customTemplate' => $this->customTemplate, 'filter' => $this->filter);
     // assign block vars and fetched data
     $this->view->assign('vars', $data)->assign('objectType', $this->objectType)->assign('items', $entities)->assign($repository->getAdditionalTemplateParameters('contentType'));
     // assign category data
     $this->view->assign('registries', $this->catRegistries);
     $this->view->assign('properties', $this->catProperties);
     $output = $this->view->fetch($template);
     return $output;
 }
Пример #7
0
 /**
  * Returns data for the Newsletter plugin.
  *
  * @param datetime $filtAfterDate Optional date filter (items should be newer), format yyyy-mm-dd hh:mm:ss or null if not set
  *
  * @return array List of affected content items.
  */
 public function getPluginData($filtAfterDate = null)
 {
     if (!$this->pluginAvailable()) {
         return array();
     }
     ModUtil::initOOModule($this->modname);
     // collect data for each activated object type
     $itemsGrouped = $this->getItemsPerObjectType($filtAfterDate);
     // now flatten for presentation
     $items = array();
     if ($itemsGrouped) {
         foreach ($itemsGrouped as $objectTypes => $itemList) {
             foreach ($itemList as $item) {
                 $items[] = $item;
             }
         }
     }
     return $items;
 }
Пример #8
0
 /**
  * Display the block
  *
  * @param        array       $blockinfo a blockinfo structure
  * @return       output      the rendered block
  */
 public function display($blockinfo)
 {
     // only show block content if the user has the required permissions
     if (!SecurityUtil::checkPermission('MUBoard:ItemListBlock:', "{$blockinfo['title']}::", ACCESS_OVERVIEW)) {
         return false;
     }
     // check if the module is available at all
     if (!ModUtil::available('MUBoard')) {
         return false;
     }
     // get current block content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $vars['bid'] = $blockinfo['bid'];
     // set default values for all params which are not properly set
     if (!isset($vars['objectType']) || empty($vars['objectType'])) {
         $vars['objectType'] = 'category';
     }
     if (!isset($vars['sorting']) || empty($vars['sorting'])) {
         $vars['sorting'] = 'default';
     }
     if (!isset($vars['amount']) || !is_numeric($vars['amount'])) {
         $vars['amount'] = 5;
     }
     if (!isset($vars['template'])) {
         $vars['template'] = 'itemlist_' . ucwords($vars['objectType']) . '_display.tpl';
     }
     if (!isset($vars['filter'])) {
         $vars['filter'] = '';
     }
     ModUtil::initOOModule('MUBoard');
     if (!isset($vars['objectType']) || !in_array($vars['objectType'], MUBoard_Util_Controller::getObjectTypes('block'))) {
         $vars['objectType'] = MUBoard_Util_Controller::getDefaultObjectType('block');
     }
     $objectType = $vars['objectType'];
     $serviceManager = ServiceUtil::getManager();
     $entityManager = $serviceManager->getService('doctrine.entitymanager');
     $repository = $entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     $idFields = ModUtil::apiFunc('MUBoard', 'selection', 'getIdFields', array('ot' => $objectType));
     $sortParam = '';
     if ($vars['sorting'] == 'random') {
         $sortParam = 'RAND()';
     } elseif ($vars['sorting'] == 'newest') {
         if (count($idFields) == 1) {
             $sortParam = $idFields[0] . ' DESC';
         } else {
             foreach ($idFields as $idField) {
                 if (!empty($sortParam)) {
                     $sortParam .= ', ';
                 }
                 $sortParam .= $idField . ' ASC';
             }
         }
     } elseif ($vars['sorting'] == 'default') {
         $sortParam = $repository->getDefaultSortingField() . ' ASC';
     }
     // get objects from database
     $selectionArgs = array('ot' => $objectType, 'where' => $vars['filter'], 'orderBy' => $sortParam, 'currentPage' => 1, 'resultsPerPage' => $vars['amount']);
     list($entities, $objectCount) = ModUtil::apiFunc('MUBoard', 'selection', 'getEntitiesPaginated', $selectionArgs);
     $this->view->setCaching(true);
     // assign block vars and fetched data
     $this->view->assign('vars', $vars)->assign('objectType', $objectType)->assign('items', $entities)->assign($repository->getAdditionalTemplateParameters('block'));
     // set a block title
     if (empty($blockinfo['title'])) {
         $blockinfo['title'] = $this->__('MUBoard items');
     }
     $output = '';
     $templateForObjectType = str_replace('itemlist_', 'itemlist_' . ucwords($objectType) . '_', $vars['template']);
     if ($this->view->template_exists('contenttype/' . $templateForObjectType)) {
         $output = $this->view->fetch('contenttype/' . $templateForObjectType);
     } elseif ($this->view->template_exists('contenttype/' . $vars['template'])) {
         $output = $this->view->fetch('contenttype/' . $vars['template']);
     } elseif ($this->view->template_exists('block/' . $templateForObjectType)) {
         $output = $this->view->fetch('block/' . $templateForObjectType);
     } elseif ($this->view->template_exists('block/' . $vars['template'])) {
         $output = $this->view->fetch('block/' . $vars['template']);
     } else {
         $output = $this->view->fetch('block/itemlist.tpl');
     }
     $blockinfo['content'] = $output;
     // return the block to the theme
     return BlockUtil::themeBlock($blockinfo);
 }
Пример #9
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('MUVideo:ItemListBlock:', "{$blockinfo['title']}::", ACCESS_OVERVIEW)) {
         return false;
     }
     // check if the module is available at all
     if (!ModUtil::available('MUVideo')) {
         return false;
     }
     // get current block content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $vars['bid'] = $blockinfo['bid'];
     // set default values for all params which are not properly set
     if (!isset($vars['objectType']) || empty($vars['objectType'])) {
         $vars['objectType'] = 'collection';
     }
     if (!isset($vars['sorting']) || empty($vars['sorting'])) {
         $vars['sorting'] = 'default';
     }
     if (!isset($vars['amount']) || !is_numeric($vars['amount'])) {
         $vars['amount'] = 5;
     }
     if (!isset($vars['template'])) {
         $vars['template'] = 'itemlist_' . DataUtil::formatForOS($vars['objectType']) . '_display.tpl';
     }
     if (!isset($vars['customTemplate'])) {
         $vars['customTemplate'] = '';
     }
     if (!isset($vars['filter'])) {
         $vars['filter'] = '';
     }
     if (!isset($vars['catIds'])) {
         $primaryRegistry = ModUtil::apiFunc('MUVideo', 'category', 'getPrimaryProperty', array('ot' => $vars['objectType']));
         $vars['catIds'] = array($primaryRegistry => array());
         // backwards compatibility
         if (isset($vars['catId'])) {
             $vars['catIds'][$primaryRegistry][] = $vars['catId'];
             unset($vars['catId']);
         }
     } elseif (!is_array($vars['catIds'])) {
         $vars['catIds'] = explode(',', $vars['catIds']);
     }
     ModUtil::initOOModule('MUVideo');
     $controllerHelper = new MUVideo_Util_Controller($this->serviceManager);
     $utilArgs = array('name' => 'list');
     if (!isset($vars['objectType']) || !in_array($vars['objectType'], $controllerHelper->getObjectTypes('block', $utilArgs))) {
         $vars['objectType'] = $controllerHelper->getDefaultObjectType('block', $utilArgs);
     }
     $objectType = $vars['objectType'];
     $entityClass = 'MUVideo_Entity_' . ucfirst($objectType);
     $entityManager = $this->serviceManager->getService('doctrine.entitymanager');
     $repository = $entityManager->getRepository($entityClass);
     $this->view->setCaching(Zikula_View::CACHE_ENABLED);
     // set cache id
     $component = 'MUVideo:' . ucfirst($objectType) . ':';
     $instance = '::';
     $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('view|ot_' . $objectType . '_sort_' . $vars['sorting'] . '_amount_' . $vars['amount'] . '_' . $accessLevel);
     $template = $this->getDisplayTemplate($vars);
     // if page is cached return cached content
     if ($this->view->is_cached($template)) {
         $blockinfo['content'] = $this->view->fetch($template);
         return BlockUtil::themeBlock($blockinfo);
     }
     // create query
     $where = $vars['filter'];
     $orderBy = $this->getSortParam($vars, $repository);
     $qb = $repository->genericBaseQuery($where, $orderBy);
     $properties = null;
     if (in_array($vars['objectType'], $this->categorisableObjectTypes)) {
         $properties = ModUtil::apiFunc('MUVideo', 'category', 'getAllProperties', array('ot' => $objectType));
     }
     // apply category filters
     if (in_array($objectType, $this->categorisableObjectTypes)) {
         if (is_array($vars['catIds']) && count($vars['catIds']) > 0) {
             $qb = ModUtil::apiFunc('MUVideo', 'category', 'buildFilterClauses', array('qb' => $qb, 'ot' => $objectType, 'catids' => $vars['catIds']));
         }
     }
     // get objects from database
     $currentPage = 1;
     $resultsPerPage = $vars['amount'];
     list($query, $count) = $repository->getSelectWherePaginatedQuery($qb, $currentPage, $resultsPerPage);
     $entities = $repository->retrieveCollectionResult($query, $orderBy, true);
     // assign block vars and fetched data
     $this->view->assign('vars', $vars)->assign('objectType', $objectType)->assign('items', $entities)->assign($repository->getAdditionalTemplateParameters('block'));
     // assign category properties
     $this->view->assign('properties', $properties);
     // set a block title
     if (empty($blockinfo['title'])) {
         $blockinfo['title'] = $this->__('MUVideo items');
     }
     $blockinfo['content'] = $this->view->fetch($template);
     // return the block to the theme
     return BlockUtil::themeBlock($blockinfo);
 }