/** * @param \yii\mongodb\ActiveRecord $model * * @return string */ protected function getErrors($model) { $errors = []; foreach ($model->getErrors() as $field_error) { $errors = ArrayHelper::merge($errors, $field_error); } return implode(', ', $errors); }
/** * @param integer $value * @param integer $depth */ protected function moveNode($value, $depth) { $leftValue = $this->owner->getAttribute($this->leftAttribute); $rightValue = $this->owner->getAttribute($this->rightAttribute); $depthValue = $this->owner->getAttribute($this->depthAttribute); $depth = $this->node->getAttribute($this->depthAttribute) - $depthValue + $depth; if ($this->treeAttribute === false || $this->owner->getAttribute($this->treeAttribute) === $this->node->getAttribute($this->treeAttribute)) { $delta = $rightValue - $leftValue + 1; $this->shiftLeftRightAttribute($value, $delta); if ($leftValue >= $value) { $leftValue += $delta; $rightValue += $delta; } $condition = ['and', [$this->leftAttribute => ['$gte' => $leftValue]], [$this->rightAttribute => ['$lte' => $rightValue]]]; $this->applyTreeAttributeCondition($condition); $this->owner->updateAll(['$inc' => [$this->depthAttribute => $depth]], $condition); foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) { $condition = ['and', [$attribute => ['$gte' => $leftValue]], [$attribute => ['$lte' => $rightValue]]]; $this->applyTreeAttributeCondition($condition); $this->owner->updateAll(['$inc' => [$attribute => $value - $leftValue]], $condition); } $this->shiftLeftRightAttribute($rightValue + 1, -$delta); } else { $nodeRootValue = $this->node->getAttribute($this->treeAttribute); foreach ([$this->leftAttribute, $this->rightAttribute] as $attribute) { $this->owner->updateAll(['$inc' => [$attribute => $rightValue - $leftValue + 1]], ['and', [$attribute => ['$gte' => $value]], [$this->treeAttribute => $nodeRootValue]]); } $delta = $value - $leftValue; $this->owner->updateAll(['$inc' => [$this->leftAttribute => $delta, $this->rightAttribute => $delta, $this->depthAttribute => $depth], '$set' => [$this->treeAttribute => $nodeRootValue]], ['and', [$this->leftAttribute => ['$gte' => $leftValue]], [$this->rightAttribute => ['$lte' => $rightValue]], [$this->treeAttribute => $this->owner->getAttribute($this->treeAttribute)]]); $this->shiftLeftRightAttribute($rightValue + 1, $leftValue - $rightValue - 1); } }
/** * @inheritdoc */ public function beforeSave($insert) { if (!parent::beforeSave($insert)) { return false; } $this->refreshFromEmbedded(); return true; }
public function afterFind() { $attributes = array_keys($this->getAttributes()); if (in_array('image', $attributes)) { $this->image_old = $this->image; } $this->generationUrl(); parent::afterFind(); }
public function beforeSave($insert) { if (parent::beforeSave($insert)) { $this->setAttribute('author', Yii::$app->user->identity->username); return true; } else { return false; } }
/** * 重载插入数据操作 * @param bool $insert */ protected function _beforeSave($insert) { parent::_beforeSave($insert); //插入前添加默认属性 if ($insert === true) { $this->setAttribute('create_time', \common\helpers\DateHelper::now()); $this->setAttribute('act_status', self::IDS_STATUS_OK); } }
/** * Initialize new entity. */ public function init() { $this->idAttribute = '_id'; $this->idAttributeType = static::$idTypeAutoIncrement; if ($this->skipInit) { return; } $this->initEntityEvents(); parent::init(); }
public function beforeSave($insert) { if (parent::beforeSave($insert)) { if ($insert) { $this->product_category_id = Yii::$app->UtilHelper->randString(10); } return true; } else { return false; } }
/** * Change our filename to match our own naming convention * @return bool */ public function beforeValidate() { //(optional) Generate a random name for our file to work on preventing // malicious users from determining / deleting other users' files if ($this->secureFileNames) { //$this->filename = sha1( Yii::app( )->user->id.microtime( ).$this->name); $this->filename = sha1(Yii::$app->user->id . microtime() . $this->image_name); $this->filename .= "." . $this->file->getExtensionName(); } return parent::beforeValidate(); }
/** * @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; } }
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; } }
/** * @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); }
public function validate($data = null){ $this->name=$data['Name']; $this->image=$data['Image']; $this->prize=$data['Price']; $this->condition=$data['Condition']; $this->summary=$data['Summary']; $this->quantity=$data['Quantity']; $this->brand=implode(array_slice($data, 7, 1),''); $this->brand_id = array_search($this->brand , $this->BrandList()); $this->category=implode(array_slice($data, 6, 1),''); $this->cat_id = array_search($this->category , $this->CategoryList()); $this->company= Auction::username(); $this->c_id = Auction::company(); $extraCondition = array_slice($data, 8 , count($data)); $extraCond= []; foreach($extraCondition as $key=>$value){; $extraCond[]=[$key => $value]; } $this->extra_cond = $extraCond; return parent::validate(); }
/** * @inheritdoc */ public function rules() { return array_merge(parent::rules(), [[['db', 'ns', 'collectionName', 'databaseName', 'attributeList', 'modelClass', 'baseClass'], 'filter', 'filter' => 'trim'], [['ns'], 'filter', 'filter' => function ($value) { return trim($value, '\\'); }], [['db', 'ns', 'collectionName', 'baseClass'], 'required'], [['db', 'modelClass'], 'match', 'pattern' => '/^\\w+$/', 'message' => 'Only word characters are allowed.'], [['ns', 'baseClass'], 'match', 'pattern' => '/^[\\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'], [['collectionName'], 'match', 'pattern' => '/^[^$ ]+$/', 'message' => 'Collection name can not contain spaces or "$" symbols.'], [['databaseName'], 'match', 'pattern' => '/^[^\\/\\\\\\. "*:?\\|<>]+$/', 'message' => 'Database name can not contain spaces or any of "/\\."*<>:|?" symbols.'], [['db'], 'validateDb'], [['ns'], 'validateNamespace'], [['collectionName'], 'validateCollectionName'], [['attributeList'], 'match', 'pattern' => '/^(\\w+\\,[ ]*)*([\\w]+)$/', 'message' => 'Attributes should contain only word characters, and should be separated by coma.'], [['modelClass'], 'validateModelClass', 'skipOnEmpty' => false], [['baseClass'], 'validateClass', 'params' => ['extends' => ActiveRecord::className()]], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false]]); }
public function insert($runValidation = true, $attributeNames = null) { $this->createdAt = $this->updatedAt = new \MongoDate(); $this->isDeleted = self::NOT_DELETED; return parent::insert($runValidation, $attributeNames); }
/** * Regular populate overridden to determine the dynamic attributes first and add those. * After that the populate can continue normally. Please note that this will pickup ANY * attribute not returned as a regular one, even if it wasn't added as magic property * * @param \yii\db\BaseActiveRecord $record * @param array $row */ public static function populateRecord($record, $row) { if ($row) { // Just figure out the ones we don't already know about and register them so they also get picked up $dynamic = array_diff(array_keys($row), $record->attributes()); $record->addAttributes($dynamic); } // Now let the regular code do its job parent::populateRecord($record, $row); }
public function afterFind() { parent::afterFind(); if (is_array($this->supportEmails)) { $this->supportEmailsInput = implode(';', $this->supportEmails); } }
/** * @return bool */ public function beforeDelete() { if (parent::beforeDelete()) { $this->unlinkAll('items', true); return true; } else { return false; } }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($insert) { $profile = $this->module->manager->createProfile(['user_id' => $this->_id, 'gravatar_email' => $this->email]); $profile->save(false); } parent::afterSave($insert, $changedAttributes); }
public function insert($runValidation = true, $attributeNames = null) { $this->createdAt = new \MongoDate(); return parent::insert($runValidation, $attributeNames); }
public function beforeSave($insert) { //重载部分 $this->_beforeSave($insert); return parent::beforeSave($insert); }
/** * Returns a value indicating whether the given active record is the same as the current one. * The comparison is made by comparing the collection names and the primary key values of the two active records. * If one of the records [[isNewRecord|is new]] they are also considered not equal. * @param ActiveRecord $record record to compare to * @return boolean whether the two active records refer to the same row in the same Mongo collection. */ public function equals($record) { if ($this->isNewRecord || $record->isNewRecord) { return false; } return $this->collectionName() === $record->collectionName() && (string) $this->getPrimaryKey() === (string) $record->getPrimaryKey(); }
public function getAttributes($names = null, $except = []) { $attributes = parent::getAttributes($names, $except); return $this->getRawAttributes($attributes); }
/** * @inheritDoc */ public function init() { parent::init(); $this->on(self::EVENT_STATUS_CHANGED, [new Mailer(), 'send']); }
/** * @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; }
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; } }