/** * 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); }
/** * 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); }
/** * Gets the current field value of the entry * @param \ride\library\orm\model\Model $model * @param \ride\library\orm\definition\field\ModelField $field * @param \ride\library\orm\entry\Entry $entry * @return mixed Current field value of the entry */ protected function getCurrentValue(Model $model, ModelField $field, Entry $entry) { return $model->getReflectionHelper()->getProperty($entry, $field->getName()); }
/** * Gets the body of a relationship and translate into entries * @param \ride\library\orm\model\Model $model * @param \ride\library\orm\definition\field\ModelField $field * @param string $relationship Name of the relationship * @return mixed|array */ private function getRelationshipBody(Model $model, ModelField $field, $relationship) { $json = $this->getBody(); $relationModelName = $field->getRelationModelName(); // check the submitted type if (!array_key_exists('data', $json)) { $this->addDataNotFoundError(); } elseif ($json['data'] === null) { $data = null; } elseif (isset($json['data']['type']) && isset($json['data']['id'])) { $model = $this->getModel($json['data']['type'], '/data/type'); $data = $this->getEntry($model, $json['data']['type'], $json['data']['id']); } elseif (is_array($json['data'])) { if ($field instanceof HasManyField) { $data = array(); foreach ($json['data'] as $index => $resource) { if (!isset($resource['type']) || !isset($resource['id'])) { $error = $this->api->createError(Response::STATUS_CODE_BAD_REQUEST, 'input.data', 'Invalid data submitted'); $error->setDetail('No type or id member found in the submitted data'); $error->setSourcePointer('/data/' . $index); $this->document->addError($error); } else { $model = $this->getModel($resource['type'], '/data/' . $index . '/type'); if ($model->getName() !== $relationModelName) { $error = $this->api->createError(Response::STATUS_CODE_BAD_REQUEST, 'input.data', 'Invalid data submitted'); $error->setDetail('No type or id member found in the submitted data'); $error->setSourcePointer('/data/' . $index); $this->document->addError($error); } else { $resourceEntry = $this->getEntry($model, $resource['type'], $resource['id'], '/data/' . $index); if ($resourceEntry) { $data[$index] = $resourceEntry; } } } } } else { $this->addDataValidationError('can not be an array'); } } else { $this->addDataValidationError('is invalid'); } return $data; }