/**
  * 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 ProductCategoryTranslation, id = {$this->id}";
             $log->created_at = $now;
             $log->type = 2;
             $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->description = FileUtils::copyContentImages(['content' => $this->description, '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;
 }
Exemple #2
0
 /**
  * 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 = 'NoreplyEmail';
             $log->object_pk = $this->id;
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $this->start_sending_at = strtotime($this->start_sending_at);
         empty($this->last_sent_at) or $this->last_sent_at = strtotime($this->last_sent_at);
         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;
 }
Exemple #3
0
 /**
  * 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 = "Customer";
             $log->object_pk = $this->id;
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $this->updated_at = $now;
         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;
         if (!empty($data['customer-image'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $this->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => [[120, 120], [200, 200]], 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $this->image = $copyResult['imageName'];
             }
         }
         if ($this->save()) {
             if ($log) {
                 $log->is_success = 1;
                 $log->save();
             }
             return true;
         }
         return false;
     }
     return false;
 }
Exemple #4
0
 /**
  * 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 = "Product";
             $log->object_pk = $this->id;
             $log->created_at = $now;
             $log->is_success = 0;
             $log->save();
         }
         $this->updated_at = $now;
         $this->updated_by = $username;
         $this->published_at = strtotime($this->published_at);
         if ($this->slug != $this->getOldAttribute('slug')) {
             $old_slugs_arr = json_decode($this->old_slugs, true);
             is_array($old_slugs_arr) or $old_slugs_arr = array();
             $old_slugs_arr[$now] = $this->getOldAttribute('slug');
             $this->old_slugs = json_encode($old_slugs_arr);
         }
         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;
         if (!empty($data['product-image'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $this->image, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'resize' => array_values(Product::$image_resizes), 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $this->image = $copyResult['imageName'];
             }
         }
         if (!empty($data['product-banner'])) {
             $copyResult = FileUtils::copyImage(['imageName' => $this->banner, 'fromFolder' => Yii::$app->params['uploads_folder'], 'toFolder' => $targetFolder, 'removeInputImage' => true]);
             if ($copyResult['success']) {
                 $this->banner = $copyResult['imageName'];
             }
         }
         if ($this->save()) {
             if ($log) {
                 $log->is_success = 1;
                 $log->save();
             }
             return true;
         }
         return false;
     }
     return false;
 }