コード例 #1
0
ファイル: ItemList.php プロジェクト: rmaiwald/MUBoard
 public function loadData(&$data)
 {
     if (!isset($data['objectType']) || !in_array($data['objectType'], MUBoard_Util_Controller::getObjectTypes('contentType'))) {
         $data['objectType'] = MUBoard_Util_Controller::getDefaultObjectType('contentType');
     }
     $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_' . ucwords($this->objectType) . '_display.tpl';
     }
     if (!isset($data['filter'])) {
         $data['filter'] = '';
     }
     $this->sorting = $data['sorting'];
     $this->amount = $data['amount'];
     $this->template = $data['template'];
     $this->filter = $data['filter'];
 }
コード例 #2
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * This method provides a generic handling of all edit requests.
  *
  * @param string  $ot           Treated object type.
  * @param string  $tpl          Name of alternative template (for alternative display options, feeds and xml output)
  * @param boolean $raw          Optional way to display a template instead of fetching it (needed for standalone output)
  * @return mixed Output.
  */
 public function edit($args)
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', 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', 'category', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'edit');
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     // create new Form reference
     $view = FormUtil::newForm($this->name, $this);
     // build form handler class name
     $handlerClass = 'MUBoard_Form_Handler_User_' . ucfirst($objectType) . '_Edit';
     // execute form using supplied template and page event handler
     return $view->execute('user/' . $objectType . '/edit.tpl', new $handlerClass());
 }
コード例 #3
0
ファイル: Admin.php プロジェクト: rmaiwald/MUBoard
 /**
  * This method provides a generic handling of simple delete requests.
  *
  * @param string  $ot           Treated object type.
  * @param int     $id           Identifier of entity to be deleted.
  * @param boolean $confirmation Confirm the deletion, else a confirmation page is displayed.
  * @param string  $tpl          Name of alternative template (for alternative display options, feeds and xml output)
  * @param boolean $raw          Optional way to display a template instead of fetching it (needed for standalone output)
  * @return mixed Output.
  */
 public function delete($args)
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_ADMIN));
     // 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', 'category', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'admin', 'action' => 'delete');
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to delete
     $idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, $args, $objectType, $idFields);
     $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($idValues);
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues));
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     $confirmation = (bool) (isset($args['confirmation']) && !empty($args['confirmation'])) ? $args['confirmation'] : $this->request->getPost()->filter('confirmation', false, FILTER_VALIDATE_BOOLEAN);
     if ($confirmation) {
         $this->checkCsrfToken();
         // TODO call pre delete validation hooks
         $this->entityManager->remove($entity);
         $this->entityManager->flush();
         $this->registerStatus($this->__('Done! Item deleted.'));
         // TODO call post delete process hooks
         // clear view cache to reflect our changes
         $this->view->clear_cache();
         // redirect to the list of the current object type
         $this->redirect(ModUtil::url($this->name, 'admin', 'view', array('ot' => $objectType)));
     }
     $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     // assign the object we loaded above
     $this->view->assign($objectType, $entity)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     // fetch and return the appropriate template
     return MUBoard_Util_View::processTemplate($this->view, 'admin', $objectType, 'delete', $args);
 }
コード例 #4
0
ファイル: Selection.php プロジェクト: rmaiwald/MUBoard
 /**
  * Select tree of given object type.
  *
  * @param string $args['ot'] The object type to retrieve (optional)
  * @param string $methodName Name of calling method
  */
 protected function determineObjectType($args, $methodName = '')
 {
     $objectType = isset($args['ot']) ? $args['ot'] : '';
     $utilArgs = array('api' => 'selection', 'action' => $methodName);
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('api', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('api', $utilArgs);
     }
     return $objectType;
 }
コード例 #5
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * Form custom url string
  *
  * @return       string custom url string
  */
 public function encodeurl($args)
 {
     // check if we have the required input
     if (!is_array($args) || !isset($args['modname']) || !isset($args['func'])) {
         return LogUtil::registerArgsError();
     }
     // 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;
     }
     // reference to current language
     $lang = ZLanguage::getLanguageCode();
     // initialise url routing rules
     $routerFacade = new MUBoard_RouterFacade();
     // get router itself for convenience
     $router = $routerFacade->getRouter();
     // initialise object type
     $utilArgs = array('controller' => 'user', 'action' => 'encodeurl');
     $allowedObjectTypes = MUBoard_Util_Controller::getObjectTypes('api', $utilArgs);
     $objectType = isset($args['args']['ot']) && in_array($args['args']['ot'], $allowedObjectTypes) ? $args['args']['ot'] : MUBoard_Util_Controller::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 = '';
     $endingPrefix = $args['func'] == 'view' ? '.' : '';
     foreach (array('csv', 'rss', 'atom', 'xml', 'pdf', 'json') 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]);
             }
         }
         $slugTitle = '';
         if ($id > 0) {
             $slugTitle = $routerFacade->getFormattedSlug($objectType, $args['func'], $args['args'], $id);
         }
         if (!empty($slugTitle) && $slugTitle != $id) {
             // add slug expression
             $args['args']['title'] = $slugTitle;
         } else {
             // readd id
             $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('MUBoard');
     $result = preg_replace('/' . $modInfo['name'] . '/', $modInfo['url'], $result, 1);
     return $result;
 }
コード例 #6
0
ファイル: User.php プロジェクト: rmaiwald/MUBoard
 /**
  * This method provides a generic item detail view.
  *
  * @param string  $ot           Treated object type.
  * @param string  $tpl          Name of alternative template (for alternative display options, feeds and xml output)
  * @param boolean $raw          Optional way to display a template instead of fetching it (needed for standalone output)
  * @return mixed Output.
  */
 public function display($args)
 {
     // DEBUG: permission check aspect starts
     $this->throwForbiddenUnless(SecurityUtil::checkPermission('MUBoard::', '::', ACCESS_READ));
     // 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', 'category', FILTER_SANITIZE_STRING);
     $utilArgs = array('controller' => 'user', 'action' => 'display');
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', $utilArgs))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', $utilArgs);
     }
     $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     // retrieve identifier of the object we wish to view
     $idValues = MUBoard_Util_Controller::retrieveIdentifier($this->request, $args, $objectType, $idFields);
     $hasIdentifier = MUBoard_Util_Controller::isValidIdentifier($idValues);
     // check for unique permalinks (without id)
     $hasSlug = false;
     $slugTitle = '';
     if ($hasIdentifier === false) {
         $entityClass = 'MUBoard_Entity_' . ucfirst($objectType);
         $objectTemp = new $entityClass();
         $hasSlug = $objectTemp->get_hasUniqueSlug();
         if ($hasSlug) {
             $slugTitle = isset($args['title']) && !empty($args['title']) ? $args['title'] : $this->request->getGet()->filter('title', '', FILTER_SANITIZE_STRING);
             $hasSlug = !empty($slugTitle);
         }
     }
     $hasIdentifier |= $hasSlug;
     $this->throwNotFoundUnless($hasIdentifier, $this->__('Error! Invalid identifier received.'));
     $entity = ModUtil::apiFunc($this->name, 'selection', 'getEntity', array('ot' => $objectType, 'id' => $idValues, 'slug' => $slugTitle));
     $this->throwNotFoundUnless($entity != null, $this->__('No such item.'));
     // we take the children postings of the parent issue
     if ($objectType == 'posting') {
         $postingid = $entity['id'];
         $postingsWhere = 'tbl.parent = \'' . DataUtil::formatForStore($postingid) . '\'';
         $order = ModUtil::getVar($this->name, 'sortingPostings');
         if ($order == 'descending') {
             $sdir = 'desc';
         } else {
             $sdir = 'asc';
         }
         $selectionArgs = array('ot' => 'posting', 'where' => $postingsWhere, 'orderBy' => 'createdDate' . ' ' . $sdir);
         // the current offset which is used to calculate the pagination
         $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT);
         // the number of items displayed on a page for pagination
         $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT);
         if ($resultsPerPage == 0) {
             $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT);
             $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10);
         }
         $selectionArgs['currentPage'] = $currentPage;
         $selectionArgs['resultsPerPage'] = $resultsPerPage;
         list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs);
         // we check if the user may see the form to answer to posting
         $mayEdit = MUBoard_Util_Controller::mayEdit($id);
         $this->view->assign('mayEdit', $mayEdit);
     }
     if ($objectType == 'forum') {
         $forumid = $entity['id'];
         $parentWhere = 'tbl.parent_id IS NULL';
         $parentWhere .= ' AND ';
         $parentWhere .= 'tbl.forum = \'' . DataUtil::formatForStore($forumid) . '\'';
         $order = ModUtil::getVar($this->name, 'sortingPostings');
         if ($order == 'descending') {
             $sdir = 'desc';
         } else {
             $sdir = 'asc';
         }
         $selectionArgs = array('ot' => 'posting', 'where' => $parentWhere, 'orderBy' => 'createdDate' . ' ' . $sdir);
         // the current offset which is used to calculate the pagination
         $currentPage = (int) (isset($args['pos']) && !empty($args['pos'])) ? $args['pos'] : $this->request->getGet()->filter('pos', 1, FILTER_VALIDATE_INT);
         // the number of items displayed on a page for pagination
         $resultsPerPage = (int) (isset($args['num']) && !empty($args['num'])) ? $args['num'] : $this->request->getGet()->filter('num', 0, FILTER_VALIDATE_INT);
         if ($resultsPerPage == 0) {
             $csv = (int) (isset($args['usecsv']) && !empty($args['usecsv'])) ? $args['usecsv'] : $this->request->getGet()->filter('usecsvext', 0, FILTER_VALIDATE_INT);
             $resultsPerPage = $csv == 1 ? 999999 : $this->getVar('pagesize', 10);
         }
         $selectionArgs['currentPage'] = $currentPage;
         $selectionArgs['resultsPerPage'] = $resultsPerPage;
         list($entities, $objectCount) = ModUtil::apiFunc($this->name, 'selection', 'getEntitiesPaginated', $selectionArgs);
     }
     // build ModUrl instance for display hooks
     $currentUrlArgs = array('ot' => $objectType);
     foreach ($idFields as $idField) {
         $currentUrlArgs[$idField] = $idValues[$idField];
     }
     // add a call to the posting
     if ($objectType == 'posting') {
         MUBoard_Util_Model::addView($idValues);
     }
     // get actual time
     $nowtime = DateUtil::getDatetime();
     // set sessionvar with calling time
     SessionUtil::setVar('muboardonline', $nowtime);
     $currentUrlObject = new Zikula_ModUrl($this->name, 'user', 'display', ZLanguage::getLanguageCode(), $currentUrlArgs);
     $type = $this->request->getGet()->filter('type', 'admin', FILTER_SANITIZE_STRING);
     $func = $this->request->getGet()->filter('func', 'view', FILTER_SANITIZE_STRING);
     $editPostings = ModUtil::getVar($this->name, 'editPostings');
     // assign output data to view object.
     $this->view->assign($objectType, $entity)->assign('postings', $entities)->assign('currentUrlObject', $currentUrlObject)->assign('func', $func)->assign('editPostings', $editPostings)->assign($repository->getAdditionalTemplateParameters('controllerAction', $utilArgs));
     $this->view->assign('currentPage', $currentPage)->assign('pager', array('numitems' => $objectCount, 'itemsperpage' => $resultsPerPage));
     $dom = ZLanguage::getModuleDomain($this->name);
     // we set Pagetitle
     $sitename = ModUtil::getVar('ZConfig', 'sitename');
     if ($objectType == 'category') {
         $titletobject = __('Forum - Category: ', $dom);
     }
     if ($objectType == 'forum') {
         $titletobject = __('Forum - Category: ', $dom) . ' ' . $entity['category']['title'] . ' - ' . __('Forum: ', $dom);
     }
     if ($objectType == 'posting') {
         $titletobject = 'Forum: ' . ' ' . $entity['forum']['title'] . ' - ' . __('Issue: ', $dom);
     }
     PageUtil::setVar('title', $sitename . ' - ' . $titletobject . ' ' . $entity['title']);
     // we set description
     if ($objectType == 'category' || $objectType == 'forum') {
         $descriptionobject = $entity['description'];
     }
     if ($objectType == 'posting') {
         $descriptionobject = $entity['text'];
         $descriptionobject = substr($descriptionobject, 0, 160) . '...';
     }
     PageUtil::setVar('description', $descriptionobject);
     // fetch and return the appropriate template
     return MUBoard_Util_View::processTemplate($this->view, 'user', $objectType, 'display', $args);
 }
コード例 #7
0
ファイル: ItemList.php プロジェクト: rmaiwald/MUBoard
 /**
  * Update block settings
  *
  * @param        array       $blockinfo a blockinfo structure
  * @return       $blockinfo  the modified blockinfo structure
  */
 public function update($blockinfo)
 {
     // Get current content
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $vars['objectType'] = $this->request->getPost()->filter('objecttype', 'category', FILTER_SANITIZE_STRING);
     $vars['sorting'] = $this->request->getPost()->filter('sorting', 'default', FILTER_SANITIZE_STRING);
     $vars['amount'] = (int) $this->request->getPost()->filter('amount', 5, FILTER_VALIDATE_INT);
     $vars['template'] = $this->request->getPost()->get('template', '');
     $vars['filter'] = $this->request->getPost()->get('filter', '');
     if (!in_array($vars['objectType'], MUBoard_Util_Controller::getObjectTypes('block'))) {
         $vars['objectType'] = MUBoard_Util_Controller::getDefaultObjectType('block');
     }
     // 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_' . ucwords($vars['objectType']) . '_display.tpl');
     $this->view->clear_cache('block/itemlist_display_description.tpl');
     $this->view->clear_cache('block/itemlist_' . ucwords($vars['objectType']) . '_display_description.tpl');
     return $blockinfo;
 }
コード例 #8
0
ファイル: ItemList.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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(false);
     // 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
ファイル: Ajax.php プロジェクト: rmaiwald/MUBoard
 /**
  * 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_Base
  */
 public function getItemList()
 {
     if (!SecurityUtil::checkPermission($this->name . '::', '::', ACCESS_EDIT)) {
         return true;
     }
     $objectType = 'category';
     if ($this->request->isPost() && $this->request->getPost()->has('ot')) {
         $objectType = $this->request->getPost()->filter('ot', 'category', FILTER_SANITIZE_STRING);
     } elseif ($this->request->isGet() && $this->request->getGet()->has('ot')) {
         $objectType = $this->request->getGet()->filter('ot', 'category', FILTER_SANITIZE_STRING);
     }
     if (!in_array($objectType, MUBoard_Util_Controller::getObjectTypes('controllerAction', array('controller' => 'ajax', 'action' => 'getItemList')))) {
         $objectType = MUBoard_Util_Controller::getDefaultObjectType('controllerAction', array('controller' => 'ajax', 'action' => 'getItemList'));
     }
     $repository = $this->entityManager->getRepository('MUBoard_Entity_' . ucfirst($objectType));
     $idFields = ModUtil::apiFunc($this->name, 'selection', 'getIdFields', array('ot' => $objectType));
     $fragment = '';
     $exclude = '';
     if ($this->request->isPost() && $this->request->getPost()->has('fragment')) {
         $fragment = $this->request->getPost()->get('fragment', '');
         $exclude = $this->request->getPost()->get('exclude', '');
     } elseif ($this->request->isGet() && $this->request->getGet()->has('fragment')) {
         $fragment = $this->request->getGet()->get('fragment', '');
         $exclude = $this->request->getGet()->get('exclude', '');
     }
     $exclude = !empty($exclude) ? array($exclude) : array();
     // parameter for used sorting field
     $sort = $this->request->getGet()->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) {
         $titleFieldName = $repository->getTitleFieldName();
         $descriptionFieldName = $repository->getDescriptionFieldName();
         $previewFieldName = $repository->getPreviewFieldName();
         $thumbWidth = 100;
         $thumbHeight = 80;
         foreach ($entities as $item) {
             // class="informal" --> show in dropdown, but do not copy in the input field after selection
             $itemTitle = !empty($titleFieldName) ? $item[$titleFieldName] : $this->__('Item');
             $itemTitleStripped = str_replace('"', '', $itemTitle);
             $itemDescription = isset($item[$descriptionFieldName]) && !empty($item[$descriptionFieldName]) ? $item[$descriptionFieldName] : '';
             //$this->__('No description yet.'));
             $itemId = '';
             foreach ($idFields as $idField) {
                 $itemId .= (!empty($itemId) ? '_' : '') . $item[$idField];
             }
             $out .= '<li id="' . $itemId . '" title="' . $itemTitleStripped . '">';
             $out .= '<div class="itemtitle">' . $itemTitle . '</div>';
             if (!empty($itemDescription)) {
                 $out .= '<div class="itemdesc informal">' . $itemDescription . '</div>';
             }
             // check for preview image
             if (!empty($previewFieldName) && !empty($item[$previewFieldName]) && isset($item[$previewFieldName . 'FullPath'])) {
                 $thumbImagePath = MUBoard_Util_Image::getThumb($item[$previewFieldName], $item[$previewFieldName . 'FullPath'], $thumbWidth, $thumbHeight);
                 $preview = '<img src="' . $thumbImagePath . '" width="' . $thumbWidth . '" height="' . $thumbHeight . '" alt="' . $itemTitleStripped . '" />';
                 $out .= '<div class="itempreview informal" id="itempreview' . $itemId . '">' . $preview . '</div>';
             }
             $out .= '</li>';
         }
     }
     $out .= '</ul>';
     return new Zikula_Response_Ajax_Plain($out);
 }