コード例 #1
0
 /**
  * Gets the content objects for the provided entries
  * @param \ride\library\orm\model\Model $model
  * @param array $entries
  * @param string $siteId
  * @param string $locale
  * @param string $idContentMapper
  * @param string $titleFormat
  * @param string $teaserFormat
  * @param string $imageFormat
  * @param string $dateFormat
  * @return array Array with Content objects for the provided entries
  * @see \ride\library\cms\content\Content
  */
 public function getContentForEntries(Model $model, array $result, $siteId, $locale, $idContentMapper = null, $titleFormat = null, $teaserFormat = null, $imageFormat = null, $dateFormat = null)
 {
     $modelName = $model->getName();
     $modelTable = $model->getMeta()->getModelTable();
     $entryFormatter = $this->orm->getEntryFormatter();
     if (!$titleFormat) {
         $titleFormat = $modelTable->getFormat(EntryFormatter::FORMAT_TITLE, false);
         if ($titleFormat == null) {
             $titleFormat = $model->getName() . ' #{id}';
         }
     }
     if (!$teaserFormat && $modelTable->hasFormat(EntryFormatter::FORMAT_TEASER)) {
         $teaserFormat = $modelTable->getFormat(EntryFormatter::FORMAT_TEASER);
     }
     if (!$imageFormat && $modelTable->hasFormat(EntryFormatter::FORMAT_IMAGE)) {
         $imageFormat = $modelTable->getFormat(EntryFormatter::FORMAT_IMAGE);
     }
     if (!$dateFormat && $modelTable->hasFormat(EntryFormatter::FORMAT_DATE)) {
         $dateFormat = $modelTable->getFormat(EntryFormatter::FORMAT_DATE);
     }
     try {
         $mapper = $this->getContentMapper($modelName, $idContentMapper);
     } catch (Exception $e) {
         $mapper = new OrmContentMapper($this->nodeModel, $model, $entryFormatter);
     }
     foreach ($result as $index => $entry) {
         $title = $entryFormatter->formatEntry($entry, $titleFormat);
         $url = $mapper->getUrl($siteId, $locale, $entry);
         $teaser = null;
         if ($teaserFormat) {
             $teaser = $entryFormatter->formatEntry($entry, $teaserFormat);
         }
         $image = null;
         if ($imageFormat) {
             $image = $entryFormatter->formatEntry($entry, $imageFormat);
         }
         $date = null;
         if ($dateFormat) {
             $date = $entryFormatter->formatEntry($entry, $dateFormat);
         }
         $content = new Content($modelName, $title, $url, $teaser, $image, $date, $entry);
         $result[$index] = $content;
     }
     return $result;
 }
コード例 #2
0
 /**
  * Action to display the widget
  * @return null
  */
 public function indexAction(OrmManager $orm, ContentService $contentService, I18n $i18n, ReflectionHelper $reflectionHelper, $id = null)
 {
     $contentProperties = $this->getContentProperties();
     $id = $contentProperties->getEntryId();
     if ($id === null) {
         return;
     }
     $modelName = $contentProperties->getModelName();
     if (!$modelName) {
         return;
     }
     $contentProperties->setIdField(ModelTable::PRIMARY_KEY);
     $this->entryFormatter = $orm->getEntryFormatter();
     $this->model = $orm->getModel($modelName);
     $query = $this->getModelQuery($contentProperties, $this->locale, $id);
     $content = $this->getResult($contentProperties, $contentService, $query);
     if ($content && $content->data instanceof LocalizedEntry && !$content->data->isLocalized() && !$contentProperties->getIncludeUnlocalized()) {
         $content = null;
     }
     if (!$content) {
         return;
     }
     $this->setContext('orm.entry.' . $this->id, $content);
     if ($contentProperties->getBreadcrumb()) {
         $url = $this->request->getBaseScript() . $this->properties->getNode()->getRoute($this->locale) . '/' . $id;
         $this->addBreadcrumb($url, $content->title);
     }
     if ($contentProperties->getTitle()) {
         $this->setPageTitle($content->title);
     }
     $this->setView($contentProperties, $content);
     if ($this->properties->getWidgetProperty('region')) {
         $this->setIsRegion(true);
     }
     if ($this->properties->getWidgetProperty('section')) {
         $this->setIsSection(true);
     }
     if ($this->properties->getWidgetProperty('block')) {
         $this->setIsBlock(true);
     }
 }
コード例 #3
0
 /**
  * Action to display the widget
  * @return null
  */
 public function indexAction(OrmManager $orm, ContentService $contentService, I18n $i18n, ReflectionHelper $reflectionHelper, $id = null)
 {
     $contentProperties = $this->getContentProperties();
     $modelName = $contentProperties->getModelName();
     if (!$modelName) {
         return;
     }
     $action = $contentProperties->getNoParametersAction();
     if ($id === null) {
         if ($action != ContentProperties::NONE_IGNORE) {
             $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         }
         return;
     }
     $this->entryFormatter = $orm->getEntryFormatter();
     $this->model = $orm->getModel($modelName);
     $query = $this->getModelQuery($contentProperties, $this->locale, $id);
     $content = $this->getResult($contentProperties, $contentService, $query);
     if (!$content && $contentProperties->getIncludeUnlocalized()) {
         // no content, look for localized version
         $locales = $i18n->getLocaleList();
         foreach ($locales as $localeCode => $locale) {
             if ($localeCode == $this->locale) {
                 continue;
             }
             $query = $this->getModelQuery($contentProperties, $localeCode, $id);
             $content = $this->getResult($contentProperties, $contentService, $query);
             if ($content) {
                 break;
             }
         }
     }
     if (!$content && $contentProperties->getIdField() != ModelTable::PRIMARY_KEY) {
         // no content, look for slug in history and redirect if possible
         $entryId = $this->getIdFromLog($orm, $reflectionHelper, $contentProperties, $this->locale, $id);
         if ($entryId) {
             $url = $this->getUrl('detail', array('id' => $entryId));
             $this->response->setRedirect($url, Response::STATUS_CODE_MOVED_PERMANENTLY);
             return;
         }
     }
     if ($content && $content->data instanceof LocalizedEntry && !$content->data->isLocalized() && !$contentProperties->getIncludeUnlocalized()) {
         $content = null;
     }
     if (!$content) {
         if ($action != ContentProperties::NONE_IGNORE) {
             $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         }
         return;
     }
     $this->setContext('content', $content);
     $url = $this->request->getBaseScript() . $this->properties->getNode()->getRoute($this->locale) . '/' . $id;
     $this->addBreadcrumb($url, $content->title);
     if ($contentProperties->getTitle()) {
         $this->setPageTitle($content->title);
     }
     $this->setView($contentProperties, $content);
     if ($contentProperties->getMetaOg()) {
         $this->setMetaOg($contentProperties, $content, $this->dependencyInjector->get('ride\\library\\image\\ImageUrlGenerator'));
     }
     if ($this->properties->getWidgetProperty('region')) {
         $this->setIsRegion(true);
     }
     if ($this->properties->getWidgetProperty('section')) {
         $this->setIsSection(true);
     }
     if ($this->properties->getWidgetProperty('block')) {
         $this->setIsBlock(true);
     }
 }
コード例 #4
0
 /**
  * Action to display the widget
  * @return null
  */
 public function indexAction(OrmManager $orm, ContentService $contentService)
 {
     $contentProperties = $this->getContentProperties();
     $modelName = $contentProperties->getModelName();
     if (!$modelName) {
         if ($this->properties->isAutoCache()) {
             $this->properties->setCache(true);
         }
         return;
     }
     // handle search
     $searchForm = null;
     if ($contentProperties->hasSearch()) {
         $searchForm = $this->createFormBuilder();
         $searchForm->setAction('search' . $this->id);
         $searchForm->addRow('query', 'string', array('label' => $this->getTranslator()->translate('label.search'), 'default' => $this->request->getQueryParameter('query')));
         $searchForm = $searchForm->build();
         if ($searchForm->isSubmitted()) {
             // redirect the search
             $data = $searchForm->getData();
             $queryParameters = $this->request->getQueryParameters();
             $queryParameters['query'] = $data['query'];
             foreach ($queryParameters as $queryParameter => $queryValue) {
                 if ($queryParameter === self::PARAM_PAGE) {
                     $queryValue = 1;
                 }
                 $queryParameters[$queryParameter] = $queryParameter . '=' . urlencode($queryValue);
             }
             $url = $this->request->getUrl(true);
             $url .= '?' . implode('&', $queryParameters);
             $this->response->setRedirect($url);
             return;
         }
         $searchForm = $searchForm->getView();
     }
     // process parameters
     $action = $contentProperties->getNoParametersAction();
     $parameters = $contentProperties->getParameters();
     $arguments = func_get_args();
     array_shift($arguments);
     // remove $orm
     array_shift($arguments);
     // remove $contentService
     if ($parameters) {
         if (is_array($parameters)) {
             if (count($arguments) != count($parameters) * 2) {
                 if ($action != ContentProperties::NONE_IGNORE) {
                     $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
                 }
                 return;
             }
             $arguments = $this->parseArguments($arguments);
         } else {
             if (count($arguments) != $parameters) {
                 if ($action != ContentProperties::NONE_IGNORE) {
                     $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
                 }
                 return;
             }
             foreach ($arguments as $index => $argument) {
                 $arguments[$index] = urldecode($argument);
             }
         }
     } elseif ($arguments) {
         if ($action == ContentProperties::NONE_404 || $action == ContentProperties::NONE_IGNORE) {
             if ($action != ContentProperties::NONE_IGNORE) {
                 $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
             }
             return;
         }
     } else {
         $arguments = array();
     }
     // process pagination parameters
     $page = 1;
     $pages = 1;
     if ($contentProperties->willShowPagination()) {
         $page = $this->request->getQueryParameter(self::PARAM_PAGE);
         if (!is_numeric($page) || $page <= 0) {
             $page = 1;
         }
     }
     // create the query
     $this->entryFormatter = $orm->getEntryFormatter();
     $this->model = $orm->getModel($modelName);
     $query = $this->getModelQuery($contentProperties, $this->locale, $page, $arguments, $isFiltered);
     // apply pagination
     $numRows = -1;
     if ($contentProperties->willShowPagination()) {
         $numRows = max(0, $query->count() - $contentProperties->getPaginationOffset());
         $pages = ceil($numRows / $contentProperties->getPaginationRows());
         if ($contentProperties->useAjaxForPagination() && $this->request->isXmlHttpRequest()) {
             $this->setIsContent(true);
         }
     }
     // fetch the result
     $result = $this->getResult($contentProperties, $contentService, $query);
     if ($numRows == -1) {
         $numRows = count($result);
     }
     if (!$contentProperties->hasEmptyResultView() && !$isFiltered && !$result) {
         // no view requested when no result
         return;
     }
     if ($this->properties->getWidgetProperty('content')) {
         $this->setIsContent(true);
     }
     // set the view
     $this->setView($contentProperties, $result, $searchForm, $numRows, $pages, $page, $arguments);
 }