コード例 #1
0
 /**
  * Reads the content mappers for the content detail widgets
  * @return array
  */
 public function readContentMappers()
 {
     $this->mappers = array();
     $this->defaultMappers = array();
     $entryFormatter = $this->orm->getEntryFormatter();
     $nodes = $this->nodeModel->getNodesForWidget('orm.detail');
     foreach ($nodes as $node) {
         $widgetId = $node->getWidgetId();
         if (!$widgetId) {
             continue;
         }
         $widgetProperties = $node->getWidgetProperties($widgetId);
         $modelName = $widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_MODEL_NAME);
         if (!$modelName) {
             continue;
         }
         if (!isset($mappers[$modelName])) {
             $mappers[$modelName] = array();
         }
         $model = $this->orm->getModel($modelName);
         $mapperId = $node->getId() . '-' . $widgetId;
         $this->mappers[$modelName][$mapperId] = new GenericOrmContentMapper($this->nodeModel, $node, $model, $entryFormatter, $widgetProperties, $this->routerService);
         if ($widgetProperties->getWidgetProperty(ContentProperties::PROPERTY_PRIMARY)) {
             $this->defaultMappers[$modelName] = $mapperId;
         }
     }
     foreach ($this->mappers as $modelName => $modelMappers) {
         if (!isset($this->defaultMappers[$modelName])) {
             reset($modelMappers);
             $this->defaultMappers[$modelName] = key($modelMappers);
         }
     }
     return $this->mappers;
 }
コード例 #2
0
 /**
  * Gets the entry
  * @param string $locale Code of the locale
  * @return mixed|null Instance of the entry if found, null otherwise
  */
 public function getEntry($locale = null)
 {
     if (isset($this->entries[$locale])) {
         return $this->entries[$locale];
     }
     $model = $this->getEntryModel();
     $id = $this->getEntryId();
     if (!$model || !$id) {
         return null;
     }
     $model = $this->orm->getModel($model);
     $this->entries[$locale] = $model->getById($id, $locale);
     return $this->entries[$locale];
 }
コード例 #3
0
ファイル: OrmJsonApi.php プロジェクト: all-ride/ride-wra-orm
 /**
  * Gets the resource adapter for the provided type
  * @param string $type Name of the resource type
  * @return JsonApiResourceAdapter
  * @throws \ride\library\http\jsonapi\exception\JsonApiException when no
  * resource adapter is set for the provided type
  */
 public function getResourceAdapter($type)
 {
     if (isset($this->resourceAdapters[$type])) {
         return $this->resourceAdapters[$type];
     }
     $modelName = $this->getModelName($type);
     if (!$modelName) {
         throw new JsonApiException('Could not get resource adapter: no adapter set for type ' . $type);
     }
     $model = $this->orm->getModel($modelName);
     $meta = $model->getMeta();
     $filterStrategies = array();
     $filterStrategyNames = $meta->getOption('json.api.filters', 'query,exact,match,expression');
     $filterStrategyNames = explode(',', $filterStrategyNames);
     foreach ($filterStrategyNames as $filterStrategyName) {
         $filterStrategyName = trim($filterStrategyName);
         $filterStrategies[$filterStrategyName] = $this->dependencyInjector->get('ride\\web\\rest\\jsonapi\\filter\\FilterStrategy', $filterStrategyName);
     }
     $resourceAdapterArguments = array('web' => $this->web, 'model' => $model, 'type' => $type);
     $resourceAdapter = $meta->getOption('json.api.adapter', 'entry');
     $resourceAdapter = $this->dependencyInjector->get('ride\\web\\rest\\jsonapi\\EntryJsonApiResourceAdapter', $resourceAdapter, $resourceAdapterArguments, true);
     $resourceAdapter->setFilterStrategies($filterStrategies);
     $this->setResourceAdapter($type, $resourceAdapter);
     return $resourceAdapter;
 }
コード例 #4
0
 public function contentAction(OrmManager $orm, Cms $cms, ContentService $contentService, ImageUrlGenerator $imageUrlGenerator, $model, $id, $locale)
 {
     $model = $orm->getModel($model);
     $entry = $model->getById($id);
     if (!$entry) {
         $this->response->setStatusCode(Response::STATUS_CODE_NOT_FOUND);
         return;
     }
     $site = $cms->getCurrentSite($this->request->getBaseUrl(), $locale);
     $content = $contentService->getContentForEntry($model, $entry, $site->getId(), $locale);
     if ($content->image) {
         $transformation = $this->request->getQueryParameter('transformation', 'crop');
         $options = array('width' => $this->request->getQueryParameter('width', 100), 'height' => $this->request->getQueryParameter('height', 100));
         $content->image = $imageUrlGenerator->generateUrl($content->image, $transformation, $options);
     }
     unset($content->data);
     $this->setJsonView($content);
 }
コード例 #5
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);
     }
 }
コード例 #6
0
 /**
  * Gets a previous slug from the entry log
  * @param \ride\library\orm\OrmManager $orm
  * @param \ride\library\reflection\ReflectionHelper $reflectionHelper
  * @param \ride\web\cms\orm\ContentProperties $contentProperties
  * @param string $locale Code of the locale
  * @param string $id Requested slug
  * @return string|null Current slug of the entry, null if no change found
  */
 protected function getIdFromLog(OrmManager $orm, ReflectionHelper $reflectionHelper, ContentProperties $contentProperties, $locale, $id)
 {
     $entryLogChangeModel = $orm->getEntryLogChangeModel();
     $meta = $this->model->getMeta();
     $isLocalized = $meta->isLocalized();
     if ($isLocalized) {
         $model = $orm->getModel($meta->getLocalizedModelName());
     } else {
         $model = $this->model;
     }
     $idField = $contentProperties->getIdField();
     // look in the log for the requested id
     $query = $entryLogChangeModel->createQuery($locale);
     $query->addCondition('{entryLog.model} = %1%', $model->getName());
     $query->addCondition('{fieldName} = %1%', $idField);
     $query->addCondition('{oldValue} = %1%', $id);
     $query->addOrderBy('{id} DESC');
     $entryLogChange = $query->queryFirst();
     if (!$entryLogChange) {
         // no history of the provided id
         return null;
     }
     $entryLog = $entryLogChange->getEntryLog();
     $entryId = $entryLog->getEntry();
     // get the original entry
     $entry = $model->getById($entryId, $this->locale);
     if (!$entry) {
         return null;
     }
     // retrieve and return the id value from the entry
     return $reflectionHelper->getProperty($entry, $idField);
 }
コード例 #7
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);
 }
コード例 #8
0
 public function formAction(Cms $cms, ImageUrlGenerator $imageUrlGenerator, $locale, OrmManager $orm, $site, $revision = null, $node = null)
 {
     if ($node) {
         if (!$cms->resolveNode($site, $revision, $node, 'entry')) {
             return;
         }
         $cms->setLastAction('edit');
     } else {
         if (!$cms->resolveNode($site, $revision)) {
             return;
         }
         $node = $cms->createNode('entry', $site);
     }
     $translator = $this->getTranslator();
     $locales = $cms->getLocales();
     $themes = $cms->getThemes();
     // gather data
     $data = array('name' => $node->getName($locale), 'model' => $node->getEntryModel(), 'entry' => $node->getEntryId(), 'route' => $node->getRoute($locale, false), 'theme' => $this->getThemeValueFromNode($node), 'availableLocales' => $this->getLocalesValueFromNode($node));
     $entryOptions = array('' => '---');
     if ($data['model']) {
         $model = $orm->getModel($data['model']);
         $entries = $model->find(null, $locale);
         $entryOptions += $model->getOptionsFromEntries($entries);
     }
     // build form
     $form = $this->createFormBuilder($data);
     $form->addRow('model', 'select', array('label' => $translator->translate('label.model'), 'description' => $translator->translate('label.model.description'), 'options' => $this->getModelOptions($orm), 'validators' => array('required' => array())));
     $form->addRow('entry', 'select', array('label' => $translator->translate('label.entry'), 'description' => $translator->translate('label.entry.description'), 'options' => $entryOptions, 'validators' => array('required' => array())));
     $form->addRow('name', 'string', array('label' => $translator->translate('label.name'), 'description' => $translator->translate('label.entry.name.description'), 'filters' => array('trim' => array())));
     $form->addRow('route', 'string', array('label' => $translator->translate('label.route'), 'description' => $translator->translate('label.route.description'), 'filters' => array('trim' => array())));
     $form->addRow('theme', 'select', array('label' => $translator->translate('label.theme'), 'description' => $translator->translate('label.theme.description'), 'options' => $this->getThemeOptions($node, $translator, $themes)));
     if ($site->isLocalizationMethodCopy()) {
         $form->addRow('availableLocales', 'select', array('label' => $translator->translate('label.locales'), 'description' => $translator->translate('label.locales.available.description'), 'options' => $this->getLocalesOptions($node, $translator, $locales), 'multiple' => true, 'validators' => array('required' => array())));
     }
     // process form
     $form = $form->build();
     if ($form->isSubmitted()) {
         try {
             $form->validate();
             $data = $form->getData();
             if (!$data['name']) {
                 $data['name'] = $entryOptions[$data['entry']];
             }
             $node->setName($locale, $data['name']);
             $node->setRoute($locale, $data['route']);
             $node->setTheme($this->getOptionValueFromForm($data['theme']));
             if ($site->isLocalizationMethodCopy()) {
                 $node->setAvailableLocales($this->getOptionValueFromForm($data['availableLocales']));
             } else {
                 $node->setAvailableLocales($locale);
             }
             $node->setEntry($data['model'], $data['entry']);
             $cms->saveNode($node, (!$node->getId() ? 'Created new entry ' : 'Updated entry ') . $node->getName());
             $this->addSuccess('success.node.saved', array('node' => $node->getName($locale)));
             $this->response->setRedirect($this->getUrl('cms.entry.edit', array('locale' => $locale, 'site' => $site->getId(), 'revision' => $node->getRevision(), 'node' => $node->getId())));
             return;
         } catch (ValidationException $validationException) {
             $this->setValidationException($validationException, $form);
         }
     }
     $referer = $this->request->getQueryParameter('referer');
     if (!$referer) {
         $referer = $this->getUrl('cms.site.detail.locale', array('site' => $site->getId(), 'revision' => $site->getRevision(), 'locale' => $locale));
     }
     // show view
     $view = $this->setTemplateView('cms/backend/entry.form', array('site' => $site, 'node' => $node, 'referer' => $referer, 'form' => $form->getView(), 'locale' => $locale, 'locales' => $locales));
     $view->addJavascript('js/cms/orm.js');
     $view->addInlineJavascript('initializeNodeEntryForm("' . $this->getUrl('api.orm.list', array('model' => '%model%')) . '");');
 }