コード例 #1
0
ファイル: ActiveRecord.php プロジェクト: quynhvv/stepup
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     $attributes = array_keys($this->getAttributes());
     // ID
     if ($this->isNewRecord and empty($this->_id)) {
         $this->_id = uniqid();
     }
     // SEO
     if (in_array('title', $attributes) and in_array('seo_url', $attributes) and empty($this->seo_url)) {
         $this->seo_url = StringHelper::asUrl($this->title);
     }
     if (in_array('title', $attributes) and in_array('seo_title', $attributes) and empty($this->seo_title)) {
         $this->seo_title = $this->title;
     }
     if (in_array('description', $attributes) and in_array('seo_desc', $attributes) and empty($this->seo_desc)) {
         $this->seo_desc = $this->description;
     }
     // Upload image
     if (in_array('image', $attributes)) {
         $image = \yii\web\UploadedFile::getInstance($this, 'image');
         if (!empty($image)) {
             $this->image = \yii\web\UploadedFile::getInstance($this, 'image');
             $ext = FileHelper::getExtention($this->image);
             if (!empty($ext)) {
                 $fileDir = Yii::$app->controller->module->id . '/' . date('Y/m/d/');
                 if (property_exists($this, 'title')) {
                     $title = $this->title;
                 } elseif (property_exists($this, 'name')) {
                     $title = $this->name;
                 } else {
                     $title = uniqid();
                 }
                 $fileName = StringHelper::asUrl($title) . '.' . $ext;
                 $folder = Yii::$app->params['uploadPath'] . '/' . Yii::$app->params['uploadDir'] . '/' . $fileDir;
                 FileHelper::createDirectory($folder);
                 $this->image->saveAs($folder . $fileName);
                 $this->image = $fileDir . $fileName;
             }
         } else {
             $this->image = $this->image_old;
         }
     }
     // creator, editor and time
     $now = new MongoDate();
     if (in_array('update_time', $attributes) and empty($this->update_time)) {
         $this->update_time = $now;
     }
     if (in_array('editor', $attributes) and !ClientHelper::isCommandLine()) {
         $this->editor = Yii::$app->user->id;
     }
     if ($this->isNewRecord) {
         if (in_array('creator', $attributes) and !ClientHelper::isCommandLine()) {
             $this->creator = Yii::$app->user->id;
         }
         if (in_array('create_time', $attributes) and $this->create_time == null) {
             $this->create_time = $now;
         }
     }
     return parent::beforeSave($insert);
 }
コード例 #2
0
ファイル: ActiveRecord.php プロジェクト: sammaye/embedded
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (!parent::beforeSave($insert)) {
         return false;
     }
     $this->refreshFromEmbedded();
     return true;
 }
コード例 #3
0
ファイル: Job.php プロジェクト: julsuniverse/jobs
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         $this->setAttribute('author', Yii::$app->user->identity->username);
         return true;
     } else {
         return false;
     }
 }
コード例 #4
0
ファイル: ProductCategory.php プロジェクト: chimgrrl/auction
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             $this->product_category_id = Yii::$app->UtilHelper->randString(10);
         }
         return true;
     } else {
         return false;
     }
 }
コード例 #5
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($this->isAttributeChanged('gravatar_email')) {
             $this->setAttribute('gravatar_id', md5($this->getAttribute('gravatar_email')));
         }
         return true;
     } else {
         return false;
     }
 }
コード例 #6
0
ファイル: Product.php プロジェクト: chimgrrl/auction
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if ($insert) {
             if (!empty($this->merchant_brand_fk)) {
                 $this->merchant_brand_fk = new \MongoId($this->merchant_brand_fk);
             }
             $this->product_id = Yii::$app->UtilHelper->randString(10);
             $this->product_status = 1;
         }
         return true;
     } else {
         return false;
     }
 }
コード例 #7
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     $attributes = array_keys($this->getAttributes());
     // Get namespace of model
     $ecommerce = Ecommerce::module();
     // User name field
     $username = ArrayHelper::getValue($ecommerce->userTable, 'nameField');
     // date time
     $now = new MongoDate();
     if (in_array('created_at', $attributes) and empty($this->created_at)) {
         $this->created_at = $now;
     }
     if (in_array('updated_at', $attributes)) {
         $this->updated_at = $now;
     }
     if ($this->isNewRecord) {
         // creator
         if (in_array('creator', $attributes)) {
             $this->creator = Yii::$app->user->id;
         }
         // ID
         if (empty($this->_id)) {
             $this->_id = uniqid();
         }
         // ecommerce_id
         if (empty($this->ecommerce_id)) {
             $this->ecommerce_id = uniqid('EM');
         }
         // status
         if (empty($this->status)) {
             $this->status = $ecommerce::STATUS_NEW;
         }
     }
     // Write log order
     $this->buildLogOrder($attributes, $username, $now);
     // Note admin
     if (in_array('note_admin', $attributes) and in_array('note_admin_content', $attributes) and !empty($this->note_admin_content)) {
         if ($this->isNewRecord) {
             $this->note_admin = [['content' => $this->note_admin_content, 'creator' => Yii::$app->user->id, 'creator_name' => Yii::$app->user->identity->{$username}, 'created_at' => $now]];
         } else {
             $this->note_admin = ArrayHelper::merge($this->note_admin, [['content' => $this->note_admin_content, 'creator' => Yii::$app->user->id, 'creator_name' => Yii::$app->user->identity->{$username}, 'created_at' => $now]]);
         }
         $this->note_admin_content = '';
     }
     return parent::beforeSave($insert);
 }
コード例 #8
0
ファイル: Products.php プロジェクト: harish-reglobbe/Auction
 public function beforeSave($insert){
     $this->doMasking();
     return parent::beforeSave($insert);
 }
コード例 #9
0
ファイル: User.php プロジェクト: verstoff/yii2-user-mongo
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($insert) {
         $this->setAttribute('auth_key', \Yii::$app->security->generateRandomString());
         $this->setAttribute('role', $this->module->defaultRole);
     }
     if (!empty($this->password)) {
         $this->setAttribute('password_hash', Password::hash($this->password));
     }
     return parent::beforeSave($insert);
 }
コード例 #10
0
ファイル: Number.php プロジェクト: shubnikofff/mobiles
 /**
  * @param bool $insert
  * @return bool
  */
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         if (in_array($this->scenario, ['create', 'update'])) {
             $this->updateHistory();
         }
         if (!empty($this->limit)) {
             $this->limit = (int) $this->limit;
         }
         return true;
     }
     return false;
 }
コード例 #11
0
 public function beforeSave($insert)
 {
     //重载部分
     $this->_beforeSave($insert);
     return parent::beforeSave($insert);
 }
コード例 #12
0
ファイル: Trip.php プロジェクト: shubnikofff/mobiles
 public function beforeSave($insert)
 {
     if (parent::beforeSave($insert)) {
         switch ($this->getScenario()) {
             case 'edit':
                 $this->numberId = Number::findOne(['number' => $this->mobileNumber])->getPrimaryKey();
                 $this->employeeId = Employee::findByName($this->employeeName)->andWhere(['post' => $this->employeePost])->one()->getPrimaryKey();
                 $this->duration = ['from' => new MongoDate(strtotime($this->beginDate)), 'to' => new MongoDate(strtotime($this->endDate))];
                 $this->numberPossession = ['from' => new MongoDate(strtotime($this->rentNumberDate))];
                 break;
             case 'complete':
                 break;
         }
         return true;
     } else {
         return false;
     }
 }