Esempio n. 1
0
 public function duplicate($modify = array())
 {
     $clone = new Image();
     $clone->attributes = $this->attributes;
     $clone->id = null;
     foreach ($modify as $key => $value) {
         $clone->{$key} = $value;
     }
     // Копируем файлы
     if ($this->file != '') {
         $from = $this->imageUpload->getFilePath();
         $clone->file = md5($this->file . time()) . '.' . pathinfo($from, PATHINFO_EXTENSION);
         $to = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->uploadPath . DIRECTORY_SEPARATOR . $clone->file;
         yupe\helpers\YFile::cpFile($from, $to);
     }
     if ($clone->save()) {
         return true;
     }
     if ($clone->file) {
         yupe\helpers\YFile::rmFile($clone->imageUpload->getFilePath());
     }
     return false;
 }
Esempio n. 2
0
 public function duplicate($modify = array())
 {
     $className = $this->type_of_block . 'Block';
     $clone = new $className();
     $clone->attributes = $this->attributes;
     $clone->id = null;
     foreach ($modify as $key => $value) {
         $clone->{$key} = $value;
     }
     // Копируем файлы
     if ($this->file != '') {
         $from = $this->fileUpload->getFilePath();
         $clone->file = md5($this->file . time()) . '.' . pathinfo($from, PATHINFO_EXTENSION);
         $to = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->fileUpload->uploadPath . DIRECTORY_SEPARATOR . $clone->file;
         yupe\helpers\YFile::cpFile($from, $to);
     }
     if ($this->video != '') {
         $clone->video = $this->video;
     }
     if ($this->image != '') {
         $from = $this->imageUpload->getFilePath();
         $clone->image = md5($this->image . time()) . '.' . pathinfo($from, PATHINFO_EXTENSION);
         $to = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->imageUpload->uploadPath . DIRECTORY_SEPARATOR . $clone->image;
         yupe\helpers\YFile::cpFile($from, $to);
     }
     // Сохраняем блок
     if ($clone->save()) {
         // Сохраняем изображения
         $result = true;
         foreach ($this->images as $image) {
             $result = $image->duplicate(array('block_id' => $clone->id));
         }
         return $result;
     }
     if ($clone->file) {
         yupe\helpers\YFile::rmFile($clone->fileUpload->getFilePath());
     }
     if ($clone->image) {
         yupe\helpers\YFile::rmFile($clone->imageUpload->getFilePath());
     }
     return false;
 }
 /**
  * Метод очистки ресурсов (assets)
  *
  * @return boolean
  **/
 private function _cleanAssets()
 {
     try {
         $dirsList = glob(Yii::app()->assetManager->getBasePath() . DIRECTORY_SEPARATOR . '*', GLOB_ONLYDIR);
         if (is_array($dirsList)) {
             foreach ($dirsList as $item) {
                 yupe\helpers\YFile::rmDir($item);
             }
         }
         return true;
     } catch (Exception $e) {
         Yii::app()->ajax->failure($e->getMessage());
     }
 }
 public function duplicate($modify = [])
 {
     $clone = clone $this;
     // clean up data for new entry
     $clone->id = null;
     $clone->isNewRecord = true;
     foreach ($modify as $key => $value) {
         $clone->{$key} = $value;
     }
     // Копируем файлы
     if ($this->image != '') {
         $from = $this->imageUpload->getFilePath();
         $clone->image = md5($this->image . time()) . '.' . pathinfo($from, PATHINFO_EXTENSION);
         $to = Yii::app()->uploadManager->getBasePath() . DIRECTORY_SEPARATOR . $this->uploadPath . DIRECTORY_SEPARATOR . $clone->image;
         yupe\helpers\YFile::cpFile($from, $to);
     }
     if ($clone->save()) {
         return true;
     }
     if ($clone->image) {
         yupe\helpers\YFile::rmFile($clone->imageUpload->getFilePath());
     }
     return false;
 }