/** * Processes the incoming value before setting it to the entry * @param \ride\library\orm\model\Model $model * @param \ride\library\orm\definition\field\ModelField $field * @param \ride\library\orm\entry\Entry $entry * @param mixed $value Incoming value * @return mixed Value to set on the entry */ public function processInputValue(Model $model, ModelField $field, Entry $entry, $value) { if ($value === null || $model->getName() != 'Asset' || $field->getName() != 'value' || $this->isUrl($value)) { // no value or not a asset file value return $value; } return $this->handleValue($model, $field, $entry, $value); }
/** * Constructs a new model resource adapter * @param \ride\web\WebApplication $web Instance of the web application * @param \ride\library\orm\model\Model $model Instance of the model * @param string $type Resource type for this model, defaults to model name * @return null */ public function __construct(WebApplication $web, Model $model, $type = null) { if ($type === null) { $type = $model->getName(); } $this->web = $web; $this->model = $model; $this->reflectionHelper = $model->getReflectionHelper(); $this->type = $type; $this->filterStrategies = array(); }
/** * 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; }
/** * Gets the available fiter entries for the provided field * @param \ride\library\orm\definition\field\ModelField $field * @param \ride\library\orm\model\Model $relationModel * @param string $locale Code of the locale * @return array Array with the id of the entry as key and the entry * instance as value */ protected function getEntries($field, $relationModel, $locale) { $options = array(); $condition = $field->getOption('scaffold.form.condition'); if ($condition) { $options['condition'] = array($condition); } $vocabulary = $field->getOption('taxonomy.vocabulary'); if ($vocabulary && $relationModel->getName() == 'TaxonomyTerm') { $options['condition'] = array('{vocabulary.slug} = "' . $vocabulary . '"'); } return $relationModel->find($options, $locale); }