/**
  * 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);
 }
Пример #2
0
 /**
  * Handles the upload for the provided value
  * @param \ride\library\orm\model\Model $model
  * @param \ride\library\orm\definition\field\ModelField $field
  * @param \ride\library\orm\entry\Entry $entry
  * @param string $value DataURI of the file
  * @return string Relative path of the uploaded file
  */
 protected function handleUpload(Model $model, ModelField $field, Entry $entry, $value)
 {
     // new value, create file from incoming DataURI
     $applicationDirectory = $this->fileBrowser->getApplicationDirectory();
     $publicDirectory = $this->fileBrowser->getPublicDirectory();
     $absoluteApplicationDirectory = $applicationDirectory->getAbsolutePath();
     $absolutePublicDirectory = $publicDirectory->getAbsolutePath();
     $uploadDirectory = $field->getOption('upload.path');
     if ($uploadDirectory) {
         $uploadDirectory = str_replace('%application%', $absoluteApplicationDirectory, $uploadDirectory);
         $uploadDirectory = str_replace('%public%', $absolutePublicDirectory, $uploadDirectory);
         $uploadDirectory = $this->fileBrowser->getFileSystem()->getFile($uploadDirectory);
         $uploadDirectory->create();
     } else {
         $uploadDirectory = $this->uploadDirectory;
     }
     $name = $this->getFileName($model, $field, $entry);
     $dataUri = $this->httpFactory->createDataUriFromString($value);
     $extension = $this->mimeService->getExtensionForMediaType($dataUri->getMimeType());
     $uploadFile = $uploadDirectory->getChild($name . '.' . $extension);
     $uploadFile = $uploadFile->getCopyFile();
     $uploadFile->write($dataUri->getData());
     // return relative path of new file
     $path = $uploadFile->getAbsolutePath();
     $path = str_replace($absoluteApplicationDirectory . '/', '', $path);
     $path = str_replace($absolutePublicDirectory . '/', '', $path);
     return $path;
 }