示例#1
0
 public function getImage($suffix = null, $refresh = false)
 {
     if ($this->_image === null || $refresh == true) {
         $this->_image = FileUtils::getImage(['imageName' => $this->image, 'imagePath' => $this->image_path, 'imagesFolder' => Yii::$app->params['images_folder'], 'imagesUrl' => Yii::$app->params['images_url'], 'suffix' => $suffix, 'defaultImage' => Yii::$app->params['default_image']]);
     }
     return $this->_image;
 }
示例#2
0
 /**
  * function ->delete ()
  */
 public function delete()
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     $model = $this;
     if ($log = new UserLog()) {
         $log->username = $username;
         $log->action = 'Delete';
         $log->object_class = 'NoreplyEmail';
         $log->object_pk = $model->id;
         $log->created_at = $now;
         $log->is_success = 0;
         $log->save();
     }
     if (parent::delete()) {
         if ($log) {
             $log->is_success = 1;
             $log->save();
         }
         FileUtils::removeFolder(Yii::$app->params['images_folder'] . $model->image_path);
         return true;
     }
     return false;
 }
 /**
  * function ->update2 ($data)
  */
 public function update2($data)
 {
     $now = strtotime('now');
     $username = Yii::$app->user->identity->username;
     if ($this->load($data)) {
         if ($log = new UserLog()) {
             $log->username = $username;
             $log->action = 'Update';
             $log->object_class = 'GeneralInfoTranslation';
             $log->object_pk = $this->id;
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         if ($this->image_path != null && trim($this->image_path) != '' && is_dir(Yii::$app->params['images_folder'] . $this->image_path)) {
             $path = $this->image_path;
         } else {
             do {
                 $path = FileUtils::generatePath($now);
             } while (file_exists(Yii::$app->params['images_folder'] . $path));
         }
         $this->image_path = $path;
         $targetFolder = Yii::$app->params['images_folder'] . $this->image_path;
         $targetUrl = Yii::$app->params['images_url'] . $this->image_path;
         $this->content = FileUtils::copyContentImages(['content' => $this->content, 'defaultFromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'toUrl' => $targetUrl, 'removeInputImage' => true]);
         if ($this->save()) {
             if ($log) {
                 $log->is_success = 1;
                 $log->save();
             }
             return true;
         }
         return false;
     }
     return false;
 }