Пример #1
0
 /**
  * Set the field values
  *
  * @param  array $values
  * @return MediaLibrary
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->name && null !== $this->folder) {
         // Check for dupe name
         $library = Table\MediaLibraries::findBy(['name' => $this->name]);
         if (isset($library->id) && $this->id != $library->id) {
             $this->getElement('name')->addValidator(new Validator\NotEqual($this->name, 'That name already exists.'));
         }
         // Check for dupe name
         $library = Table\MediaLibraries::findBy(['folder' => $this->folder]);
         if (isset($library->id) && $this->id != $library->id) {
             $this->getElement('folder')->addValidator(new Validator\NotEqual($this->folder, 'That folder already exists.'));
             if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . $this->folder)) {
                 $this->getElement('folder')->addValidator(new Validator\NotEqual($this->folder, 'That folder already exists on disk.'));
             }
         }
     }
     return $this;
 }
Пример #2
0
 /**
  * Get library by folder
  *
  * @param  string $folder
  * @return void
  */
 public function getByFolder($folder)
 {
     $library = Table\MediaLibraries::findBy(['folder' => $folder]);
     if (isset($library->id)) {
         $data = $library->getColumns();
         $data['max_filesize'] = $this->unparseMaxFilesize($data['max_filesize']);
         if (null !== $data['actions']) {
             $actions = unserialize($data['actions']);
             $keys = array_keys($actions);
             $values = array_values($actions);
             if (isset($keys[0]) && isset($values[0])) {
                 $data['action_name_1'] = $keys[0];
                 $data['action_method_1'] = $values[0]['method'];
                 $data['action_params_1'] = $values[0]['params'];
                 $data['action_quality_1'] = $values[0]['quality'];
             }
             $data['actions'] = $actions;
         }
         $this->data = array_merge($this->data, $data);
     }
 }