/** * Loads the properties of the detail widget for the provided site and locale * @param string $index The key to store the values * @param string $site Id of the site * @param string $locale Code of the current locale * @return null */ protected function parseArguments($index, $site, $locale) { $properties = new ContentProperties(); $properties->getFromWidgetProperties($this->properties, $locale); $this->reflectionHelper = $this->model->getReflectionHelper(); $this->arguments[$index] = array(ContentProperties::PROPERTY_RECURSIVE_DEPTH => $properties->getRecursiveDepth(), ContentProperties::PROPERTY_INCLUDE_UNLOCALIZED => $properties->getIncludeUnlocalized(), ContentProperties::PROPERTY_ID_FIELD => $properties->getIdField(), ContentProperties::PROPERTY_FORMAT_TITLE => $properties->getContentTitleFormat(), ContentProperties::PROPERTY_FORMAT_TEASER => $properties->getContentTeaserFormat(), ContentProperties::PROPERTY_FORMAT_IMAGE => $properties->getContentImageFormat(), ContentProperties::PROPERTY_FORMAT_DATE => $properties->getContentDateFormat(), self::PROPERTY_URL => rtrim($this->routerService->getUrl($this->baseScript, 'cms.front.' . $site . '.' . $this->node->getId() . '.' . $locale), '/') . '/'); }
/** * Gets the model query * @param \ride\web\cms\orm\ContentProperties $contentProperties * @param \ride\library\orm\model\Model $model * @param string $locale Code of the locale * @param string $id The id of the record to fetch * @return \ride\library\orm\query\ModelQuery */ protected function getModelQuery(ContentProperties $contentProperties, $locale, $id) { $query = $this->model->createQuery($locale); $query->setRecursiveDepth($contentProperties->getRecursiveDepth()); $query->setFetchUnlocalized($contentProperties->getIncludeUnlocalized()); $modelFields = $contentProperties->getModelFields(); if ($modelFields) { foreach ($modelFields as $fieldName) { $query->addFields('{' . $fieldName . '}'); } } $idField = $contentProperties->getIdField(); $query->addCondition('{' . $idField . '} = %1%', $id); $condition = $contentProperties->getCondition(); if ($condition) { $query->addCondition($condition); } $order = $contentProperties->getOrder(); if ($order) { $query->addOrderBy($order); } return $query; }
/** * Creates the model query from the provided properties * @param \ride\library\orm\model\Model $model * @param \ride\library\orm\model\ContentProperties $contentProperties * @param string $locale Code of the locale * @param integer $page Page number * @param array $arguments Arguments for the condition * @return \ride\library\orm\query\ModelQuery */ public function getModelQuery(ContentProperties $contentProperties, $locale, $page = 1, array $arguments, &$isFiltered = null) { $isFiltered = false; // create query $query = $this->model->createQuery($locale); $query->setRecursiveDepth($contentProperties->getRecursiveDepth()); $query->setFetchUnlocalized($contentProperties->getIncludeUnlocalized()); // select fields $modelFields = $contentProperties->getModelFields(); if ($modelFields) { foreach ($modelFields as $fieldName) { $query->addFields('{' . $fieldName . '}'); } } // apply condition $condition = $contentProperties->getCondition(); if ($condition) { $arguments = $this->parseContextVariables($condition, $arguments); if ($arguments) { $isFiltered = true; $query->addConditionWithVariables($condition, $arguments); } else { $query->addCondition($condition); } } // apply search if ($contentProperties->hasSearch()) { $searchQuery = $this->request->getQueryParameter('query'); if ($searchQuery) { $conditions = array(); $fields = $this->model->getMeta()->getProperties(); foreach ($fields as $fieldName => $field) { if ($field->getOption('scaffold.search')) { $conditions[] = '{' . $fieldName . '} LIKE %1%'; } } if ($conditions) { $condition = implode(' OR ', $conditions); $searchQuery = '%' . $searchQuery . '%'; $query->addCondition($condition, $searchQuery); } } } // apply filters $this->filters = array(); $filters = $contentProperties->getFilters(); foreach ($filters as $filter) { $filterValue = $this->request->getQueryParameter($filter['name']); if ($filterValue) { $isFiltered = true; } $this->filters[$filter['name']] = array('type' => $filter['type'], 'field' => $filter['field'], 'filter' => $this->dependencyInjector->get('ride\\web\\cms\\orm\\filter\\ContentOverviewFilter', $filter['type'])); $this->filters[$filter['name']]['value'] = $this->filters[$filter['name']]['filter']->applyQuery($this->model, $query, $filter['field'], $filterValue); } // apply order $order = $contentProperties->getOrder(); if ($order) { $query->addOrderBy($order); } // apply pagination if ($contentProperties->isPaginationEnabled()) { $paginationOffset = $contentProperties->getPaginationOffset(); $rows = $contentProperties->getPaginationRows(); $offset = ($page - 1) * $rows; if ($paginationOffset) { $offset += $paginationOffset; } $query->setLimit((int) $rows, (int) $offset); } return $query; }