コード例 #1
0
 public function process()
 {
     $this->setCheckbox('active');
     if (empty($_FILES['file'])) {
         $this->addFieldError('file', $this->modx->lexicon('gallery.item_err_ns_file'));
     }
     if ($this->hasErrors()) {
         return $this->failure();
     }
     /** @var galItem $item */
     $this->object = $this->modx->newObject('galItem');
     $this->object->fromArray($this->getProperties());
     $this->object->set('createdby', $this->modx->user->get('id'));
     if (empty($_FILES['file']) || $_FILES['file']['error'] != UPLOAD_ERR_OK) {
         return $this->failure($this->modx->lexicon('gallery.item_err_ns_file'));
     }
     if (!$this->object->save()) {
         return $this->failure($this->modx->lexicon('gallery.item_err_save'));
     }
     if (!$this->object->upload($_FILES['file'], $this->getProperty('album'))) {
         $this->object->remove();
         return $this->failure($this->modx->lexicon('gallery.item_err_upload'));
     }
     $this->object->save();
     $this->associateToAlbum();
     $this->setTags();
     return $this->cleanup();
 }