Exemplo n.º 1
0
 /**
  * Save input data to database
  */
 public function make()
 {
     // save data to db
     $this->_record->title = $this->title;
     $this->_record->text = $this->text;
     $this->_record->path = $this->path;
     $this->_record->category_id = (int) $this->categoryId;
     $this->_record->display = 0;
     // set to premoderation
     $this->_record->author_id = (int) $this->authorId;
     if ($this->_new === true) {
         $this->_record->comment_hash = $this->generateCommentHash();
     }
     $this->_record->save();
     // work with poster data
     if ($this->poster !== null) {
         // lets move poster from tmp to gallery
         $originDir = '/upload/gallery/' . $this->_record->id . '/orig/';
         $thumbDir = '/upload/gallery/' . $this->_record->id . '/thumb/';
         if (!Directory::exist($originDir)) {
             Directory::create($originDir);
         }
         if (!Directory::exist($thumbDir)) {
             Directory::create($thumbDir);
         }
         $fileName = App::$Security->simpleHash($this->poster->getClientOriginalName() . $this->poster->getSize());
         $newFullName = $fileName . '.' . $this->poster->guessExtension();
         // move poster to upload gallery directory
         $this->poster->move(Normalize::diskFullPath($originDir), $newFullName);
         // initialize image resizer
         $thumb = new Image();
         $thumb->setCacheDir(root . '/Private/Cache/images');
         // open original file, resize it and save
         $thumbSaveName = Normalize::diskFullPath($thumbDir) . '/' . $fileName . '.jpg';
         $thumb->open(Normalize::diskFullPath($originDir) . DIRECTORY_SEPARATOR . $newFullName)->cropResize($this->_configs['galleryResize'])->save($thumbSaveName, 'jpg', 90);
         $thumb = null;
         // update poster in database
         $this->_record->poster = $newFullName;
         $this->_record->save();
     }
 }