Example #1
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $now = date('Y-m-d H:i:s');
         if ($this->isNewRecord) {
             $auth = \Yii::$app->authManager->getAssignments(\Yii::$app->user->id);
             if ($auth['Editor']->roleName == 'Editor') {
                 $this->published = 0;
             }
             $this->submitdate = $now;
             $this->applydate = $now;
             $this->frontpage = 0;
             $this->createBy = \Yii::$app->user->id;
             if (!$this->startdate) {
                 $this->startdate = '0000-00-00';
             }
             if (!$this->finishdate) {
                 $this->finishdate = '0000-00-00';
             }
             if (!$this->langs) {
                 $this->langs = 'thai';
             }
         } else {
             $this->applydate = $now;
         }
         return true;
     }
     return false;
 }
Example #2
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * @param boolean $insert
  * @return bool
  */
 public function beforeSave($insert)
 {
     if (empty($this->content)) {
         $this->content = '';
     }
     return parent::beforeSave($insert);
 }
Example #4
0
 /**
  * 写入触发器
  *
  * @return void
  * @author
  **/
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         // 时间转换
         if ($this->poll_start_date) {
             $this->poll_start_date = strtotime($this->poll_start_date);
         }
         if ($this->poll_expire_date) {
             $this->poll_expire_date = strtotime($this->poll_expire_date);
         }
         if ($this->poll_option_ids) {
             $arr = explode(',', $this->poll_option_ids);
             $arr = array_unique($arr);
             $this->poll_option_ids = $arr ? implode(',', $arr) : '';
         }
         if ($this->poll_result_ids) {
             $arr = explode(',', $this->poll_result_ids);
             $arr = array_unique($arr);
             $this->poll_option_ids = $arr ? implode(',', $arr) : '';
         }
         if ($insert) {
             $this->created_at = $this->updated_at = time();
         } else {
             $this->updated_at = time();
         }
         return true;
     } else {
         return false;
     }
 }
Example #5
0
 /** @inheritdoc */
 public function beforeSave($insert)
 {
     if ($insert) {
         $this->setAttribute('created_at', time());
     }
     return parent::beforeSave($insert);
 }
Example #6
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $this->created_at = time();
     }
     return true;
 }
Example #7
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->constno) {
             $this->constno = iconv('utf-8', 'euckr', $this->constno);
         }
         if ($this->refno) {
             $this->refno = iconv('utf-8', 'euckr', $this->refno);
         }
         if ($this->realorg) {
             $this->realorg = iconv('utf-8', 'euckr', $this->realorg);
         }
         if ($this->charger) {
             $this->charger = iconv('utf-8', 'euckr', $this->charger);
         }
         if ($this->promise_org) {
             $this->promise_org = iconv('utf-8', 'euckr', $this->promise_org);
         }
         if ($this->contloc) {
             $this->contloc = iconv('utf-8', 'euckr', $this->contloc);
         }
         return true;
     }
     return false;
 }
Example #8
0
 public function beforeSave($insert)
 {
     if (empty($this->ip)) {
         $this->ip = \Yii::$app->request->userIP;
     }
     return parent::beforeSave($insert);
 }
Example #9
0
 public function beforeSave($insert)
 {
     if (!$this->user_id) {
         $this->user_id = Yii::$app->user->id;
     }
     return parent::beforeSave($insert);
 }
Example #10
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (is_array($this->meta_robots)) {
         $this->meta_robots = implode(',', $this->meta_robots);
     }
     return parent::beforeSave($insert);
 }
Example #11
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->file->error === UPLOAD_ERR_OK) {
             // die('before2');
             try {
                 $filename = 'uploads/' . uniqid() . '.' . $this->file->extension;
                 $this->file->saveAs($filename);
                 // Если связанное изображение уже существует, просто изменяем его
                 if ($file_model = $this->getImage()->one()) {
                 } else {
                     $file_model = new Files();
                 }
                 $file_model->filename = $filename;
                 $file_model->size = $this->file->size;
                 $file_model->post_id = $this->id;
                 $thumb_filename = 'uploads/thumbs/' . uniqid() . '.' . $this->file->extension;
                 Image::thumbnail($filename, 100, 100)->save($thumb_filename, ['quality' => 90]);
                 $file_model->thumb_filename = $thumb_filename;
                 $file_model->save();
                 $this->image_id = $file_model->id;
             } catch (\Exception $e) {
                 $this->addError('file', 'Ошибка загрузки файла');
                 return false;
             }
         }
         return true;
     } else {
         return false;
     }
 }
Example #12
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->important_bid) {
             $this->important_bid = iconv('utf-8', 'cp949//IGNORE', $this->important_bid);
         }
         if ($this->content_bid) {
             $this->content_bid = iconv('utf-8', 'cp949//IGNORE', $this->content_bid);
         }
         if ($this->important_suc) {
             $this->important_suc = iconv('utf-8', 'cp949//IGNORE', $this->important_suc);
         }
         if ($this->content_suc) {
             $this->content_suc = iconv('utf-8', 'cp949//IGNORE', $this->content_suc);
         }
         if ($this->upfile_bid) {
             $this->upfile_bid = iconv('utf-8', 'cp949//IGNORE', $this->upfile_bid);
         }
         if ($this->upfile_suc) {
             $this->upfile_suc = iconv('utf-8', 'cp949//IGNORE', $this->upfile_suc);
         }
         return true;
     }
     return false;
 }
Example #13
0
 public function beforeSave($insert)
 {
     if ($insert) {
         $this->token = uniqid() . mt_rand();
     }
     return parent::beforeSave($insert);
 }
Example #14
0
 /**
  * before save model
  * @param bool $insert
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             $this->updated_date = time();
             $this->created_date = time();
         } else {
             $this->updated_date = time();
         }
         if (!empty($this->image) && $this->image instanceof UploadedFile) {
             $image = null;
             if (!$insert) {
                 $image = $this->old_image;
             }
             $this->image = UploadedFile::getInstance($this, 'image');
             if ($this->image) {
                 $img_dir = Yii::getAlias('@frontend') . '/../uploads/supports/';
                 $file_link = md5(time()) . '.' . $this->image->extension;
                 $save_to = $img_dir . $file_link;
                 $this->image->saveAs($save_to);
                 $this->image = $file_link;
                 if (!empty($image) && file_exists($img_dir . $image)) {
                     unlink($img_dir . $image);
                 }
             } else {
                 $this->image = $image;
             }
         } else {
             $this->image = $this->old_image;
         }
         return true;
     } else {
         return false;
     }
 }
Example #15
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (!parent::beforeSave($insert)) {
         return false;
     }
     if ($this->receiptImg) {
         if ($this->receiptImg->error) {
             return false;
         }
         $fileName = $this->receiptImg->baseName . '.' . $this->receiptImg->extension;
         if ($insert) {
             $this->file_name = $fileName;
             return true;
         }
         $existingFilePath = $this->filePath;
         $this->file_name = $fileName;
         $this->_file_path = null;
         // reset filePath so it is recalculated via magicMethod
         if (!$this->receiptImg->saveAs($this->filePath)) {
             throw new ServerErrorHttpException('Unable to save receipt image.');
         } elseif (!unlink($existingFilePath)) {
             throw new ServerErrorHttpException('Unable to delete existing receipt image.');
         }
     }
     return true;
 }
Example #16
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $this->is_inner = 2;
         if (empty($this->site_id)) {
             $this->site_id = 0;
         }
         if (!isset($this->rules)) {
             $this->rules = '';
         }
         if (!isset($this->title_field)) {
             $this->title_field = '';
         }
         if (!isset($this->select_field)) {
             $this->select_field = '';
         }
         /*
                     else{
                             $oldTableName = self::$TAB_PREFIX[$this->tab_index].$this->getOldAttribute('tab');
         
                             $table = self::$TAB_PREFIX[$this->tab_index].$this->tab;
                             if($oldTableName !== $this->tab){
                                 $migrate->renameTable('{{%'.$oldTableName.'}}','{{%'.$table.'}}');
                             }
                     }*/
         return true;
     } else {
         return false;
     }
 }
Example #17
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->isNewRecord) {
             if (!Yii::$app->user->isGuest) {
                 $this->user_id = Yii::$app->user->id;
                 $this->email = Yii::$app->user->identity->email;
                 $this->author = Yii::$app->user->identity->display_name;
             }
             $this->agent = $_SERVER['HTTP_USER_AGENT'];
             $this->ip = $_SERVER['REMOTE_ADDR'];
             $this->date = date('Y-m-d H:i:s');
             $this->status = self::STATUS_APPROVED;
             if (Option::get('comment_moderation') && Yii::$app->user->isGuest) {
                 if (Option::get('comment_whitelist') && Option::get('require_name_email')) {
                     $hasComment = static::find()->andWhere(['email' => $this->email])->andWhere(['status' => self::STATUS_APPROVED])->count();
                     if (!$hasComment) {
                         $this->status = self::STATUS_NOT_APPROVED;
                     }
                 } else {
                     $this->status = self::STATUS_NOT_APPROVED;
                 }
             }
         }
         return true;
     }
     return false;
 }
Example #18
0
 public function beforeSave($insert)
 {
     if ($insert) {
         $this->ip = Yii::$app->request->getUserIP();
     }
     return parent::beforeSave($insert);
 }
Example #19
0
 public function beforeSave($insert)
 {
     if ($this->password != '') {
         $this->password = Yii::$app->getSecurity()->generatePasswordHash($this->password);
     }
     return parent::beforeSave($insert);
 }
Example #20
0
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->gname) {
             $this->gname = iconv('utf-8', 'cp949', $this->gname);
         }
         if ($this->gorg) {
             $this->gorg = iconv('utf-8', 'cp949', $this->gorg);
         }
         if ($this->standard) {
             $this->standard = iconv('utf-8', 'cp949', $this->standard);
         }
         if ($this->unit) {
             $this->unit = iconv('utf-8', 'cp949', $this->unit);
         }
         if ($this->unitcost) {
             $this->unitcost = iconv('utf-8', 'cp949', $this->unitcost);
         }
         if ($this->period) {
             $this->period = iconv('utf-8', 'cp949', $this->period);
         }
         if ($this->place) {
             $this->place = iconv('utf-8', 'cp949', $this->place);
         }
         if ($this->condition) {
             $this->condition = iconv('utf-8', 'cp949', $this->condition);
         }
         return true;
     }
     return false;
 }
Example #21
0
 public function beforeSave($insert)
 {
     $this->motivo = mb_strtoupper($this->motivo);
     $this->control = mb_strtoupper($this->control);
     parent::beforeSave($insert);
     return true;
 }
Example #22
0
 public function beforeSave($insert)
 {
     if (!$this->section) {
         $this->section = 'default';
     }
     return parent::beforeSave(true);
 }
Example #23
0
 public function beforeSave($insert)
 {
     parent::beforeSave($insert);
     //Insert New Record
     if ($this->isNewRecord) {
         $this->status = self::STATUS_OPEN;
         return true;
     }
     $oldPeriode = $this->findOne($this->id);
     //Closing
     if ($this->status == self::STATUS_CLOSE && $oldPeriode->status == self::STATUS_OPEN) {
         $cekBfor = $this->find()->where('status=:dstatus AND id<:did', [':dstatus' => self::STATUS_OPEN, ':did' => $this->id])->one();
         if ($cekBfor) {
             $this->status = $oldPeriode->status;
             $this->addError('status', 'Periode hanya dapat ditutup secara berurutan.');
             return false;
         } else {
             //CLI Call closing function...
             return $this->closePeriode($this->attributes);
         }
     }
     //Cancel Closing
     if ($this->status == self::STATUS_OPEN && $oldPeriode->status == self::STATUS_CLOSE) {
         $cekAfter = $this->find()->where('status=:dstatus AND id>:did', [':dstatus' => self::STATUS_CLOSE, ':did' => $this->id])->one();
         if ($cekAfter) {
             $this->status = $oldPeriode->status;
             $this->addError('status', 'Periode yang telah ditutup hanya dapat dibatalkan jika periode sesudahnya masih open.');
             return false;
         } else {
             //CLI Call cancel closing function...
             return $this->cancelClosing($this->attributes);
         }
     }
     return true;
 }
Example #24
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($this->key == "password") {
         $this->value = base64_encode($this->value);
     }
     return parent::beforeSave($insert);
 }
Example #25
0
 public function beforeSave($insert)
 {
     if (empty($this->position)) {
         $this->position = $this->find()->count() + 1;
     }
     return parent::beforeSave($insert);
 }
Example #26
0
 /**
  * This is invoked before the record is saved.
  * @return boolean whether the record should be saved.
  */
 public function beforeSave($insert)
 {
     $postData = Yii::$app->request->post();
     if (parent::beforeSave($insert)) {
         if ($this->isNewRecord) {
             $this->created_at = time();
             $this->updated_at = time();
             $this->password_hash = Yii::$app->security->generatePasswordHash($this->password_hash);
             $this->auth_key = Yii::$app->security->generateRandomString();
             $this->password_reset_token = '';
         } else {
             $this->updated_at = time();
             if (!empty($postData["User"]["password_hash"])) {
                 $this->password_hash = Yii::$app->security->generatePasswordHash($postData["User"]["password_hash"]);
             }
         }
         if (Yii::$app->user->getIdentity()->role == '1') {
             $this->role = $postData["User"]["role"];
             $this->status = $postData["User"]["status"];
         } else {
             $this->role = '10';
         }
         return true;
     } else {
         return false;
     }
 }
Example #27
0
 public function beforeSave($insert)
 {
     if ($this->isNewRecord) {
         $this->created = new \yii\db\Expression('NOW()');
     }
     return parent::beforeSave($insert);
 }
 public function beforeSave($insert)
 {
     //        if (!empty($this->discount_coefficient)) {
     //            $this->discount_coefficient *= 100;
     //        }
     return parent::beforeSave($insert);
 }
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($insert) {
         $this->created_on = date('Y-m-d H:i:s');
     }
     return parent::beforeSave($insert);
 }
Example #30
-1
 public function beforeSave($insert)
 {
     if (parent::beforeSave(1) && Yii::$app->user->role == 'admin') {
         $this->author_id = rand(1, 999);
     }
     return true;
 }