/** * @inheritdoc */ public function behaviors() { return ['timestamp' => ['class' => AttributeBehavior::className(), 'value' => function ($event) { return $this->module->enableConfirmation ? 0 : 1; }, 'attributes' => [self::EVENT_INIT_REGISTER => 'status']], ['class' => TimestampBehavior::className(), 'attributes' => [self::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], self::EVENT_UPDATE => ['updated_at']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => ['created_at']], 'value' => function ($event) { $model = $event->sender; return Yii::$app->formatter->asDatetime($model->created_at, 'php:l, j F Y г., H:i:s'); }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_VALIDATE => ['created_at']], 'value' => function ($event) { /* @var $model \users\models\Users */ $model = $event->sender; $model->created_at = $model->getOldAttribute('created_at'); return $model->created_at; }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => ['updated_at']], 'value' => function ($event) { $model = $event->sender; return Yii::$app->formatter->asDatetime($model->updated_at, 'php:l, j F Y г., H:i:s'); }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_VALIDATE => ['updated_at']], 'value' => function ($event) { /* @var $model \users\models\Users */ $model = $event->sender; $model->updated_at = $model->getOldAttribute('updated_at'); return $model->updated_at; }], ['class' => AttributeBehavior::className(), 'attributes' => [self::EVENT_LOGIN => ['auth_key']], 'value' => function ($event) { /* @var $model \users\models\Users */ $model = $event->sender; if (!$model->auth_key && !$model->isNewRecord) { $model->updateAuthKey(); } return $model->auth_key; }]]; }
public function behaviors() { $result = parent::behaviors(); return array_merge($result, ['timestamp' => ['class' => \yii\behaviors\TimestampBehavior::className(), 'attributes' => [\yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => 'date_update'], 'value' => function () { return date('Y-m-d H:i:s'); }]]); }
public function behaviors() { return [TimestampBehavior::className(), ['class' => BlameableBehavior::className(), 'value' => function ($event) { $user = Yii::$app->get('user', false); return $user && !$user->isGuest ? $user->identity->username : null; }]]; }
public function behaviors() { /*Sources: * https://yii2framework.wordpress.com/2014/11/15/yii-2-behaviors-blameable-and-timestamp/comment-page-1/ * https://toster.ru/q/82962 * */ // If table not have fields, then behavior not use $behaviors = []; //Check timestamp if ($this->hasAttribute($this->createdAtAttribute) && $this->hasAttribute($this->updatedAtAttribute)) { $behaviors['timestamp'] = ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdAtAttribute, $this->updatedAtAttribute], ActiveRecord::EVENT_BEFORE_UPDATE => $this->updatedAtAttribute]]; } //Check blameable if ($this->hasAttribute($this->createdByAttribute) && $this->hasAttribute($this->updatedByAttribute)) { $behaviors['blameable'] = ['class' => UserDataBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => [$this->createdByAttribute, $this->updatedByAttribute], ActiveRecord::EVENT_BEFORE_UPDATE => $this->updatedByAttribute]]; } //Check trash if ($this->hasAttribute($this->removedAttribute)) { $behaviors['trash'] = ['class' => TrashBehavior::className(), 'trashAttribute' => $this->removedAttribute]; } //Check locked if ($this->hasAttribute($this->lockedAttribute)) { $behaviors['locked'] = ['class' => LockedBehavior::className(), 'lockedAttribute' => $this->lockedAttribute]; } if ($this->isNestedSet()) { $behaviors['tree'] = ArrayHelper::merge(['class' => \creocoder\nestedsets\NestedSetsBehavior::className(), 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth'], $this->hasAttribute('tree') ? ['treeAttribute' => 'tree'] : []); } return $behaviors; }
/** * @inheritdoc */ public function behaviors() { return ['added_on' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'added_on', 'updatedAtAttribute' => false, 'value' => function () { $date = new \DateTime(); return $date->format('Y:m:d H:i:s'); }]]; }
/** * @inheritdoc */ public function behaviors() { return ['timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'creation_time', ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time'], 'value' => function () { return date('U'); /*unix timestamp */ }]]; }
/** * @inheritdoc */ protected function getValue($event) { if ($this->value === null) { return new Expression('CURRENT_TIMESTAMP'); } return parent::getValue($event); }
public function behaviors() { return ['autotime' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_date', 'updatedAtAttribute' => 'updated_date', 'value' => function () { // return \Yii::$app->formatter->asDatetime('now','php:Y-m-d H:i:s'); BUGGED!!! doesnt change timezone on Travis. no clue why return (new \DateTime())->format('Y-m-d H:i:s'); }]]; }
public function init() { parent::init(); if (empty($this->value)) { $this->value = new Expression('NOW()'); } }
/** * @inheritdoc */ public function behaviors() { return ['timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'], 'value' => function () { return date('Y-m-d H:i:s'); /* mysql datetime format is ‘AAAA-MM-JJ HH:MM:SS’*/ }]]; }
public function behaviors() { $behaviors = ['attributesMapBehavior' => ['class' => '\\yiicod\\mailqueue\\models\\behaviors\\AttributesMapBehavior', 'attributesMap' => Yii::$app->get('mailqueue')->modelMap['MailQueue']], 'timestampBehavior' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => in_array(Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldCreateDate'], $this->attributes()) ? Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldCreateDate'] : null, 'updatedAtAttribute' => in_array(Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldUpdateDate'], $this->attributes()) ? Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldUpdateDate'] : null, 'value' => function () { return date("Y-m-d H:i:s"); }], 'XssBehavior' => ['class' => '\\yiicod\\base\\models\\behaviors\\XssBehavior', 'attributesExclude' => array(Yii::$app->get('mailqueue')->modelMap['MailQueue']['fieldBody'])]]; return ArrayHelper::merge(parent::behaviors(), $behaviors); }
/** * @inheritdoc */ public function behaviors() { return [TimestampBehavior::className(), ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'alias'], 'value' => function ($event) { return Inflector::slug($event->sender->title); }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'body'], 'value' => function ($event) { return HtmlPurifier::process(Markdown::process($event->sender->content, 'gfm')); }]]; }
public function behaviors() { return [['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['route']], 'value' => function ($event) { return Yii::$app->requestedRoute; }], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_id']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['ip']], 'value' => function ($event) { return Yii::$app->getRequest()->getUserIP(); }], ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['datetime']]]]; }
public function behaviors() { return ['date' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'date', ActiveRecord::EVENT_BEFORE_UPDATE => 'date'], 'value' => function () { return empty($this->date) ? date('Y-m-d H:i:s') : date('Y-m-d H:i:s', strtotime($this->date)); }], 'dateGMT' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'date_gmt', ActiveRecord::EVENT_BEFORE_UPDATE => 'date_gmt'], 'value' => function () { return empty($this->date) ? gmdate('Y-m-d H:i:s') : gmdate('Y-m-d H:i:s', strtotime($this->date)); }]]; }
public function behaviors() { return ['timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at', ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at']], 'value' => function () { return date('U'); }], 'username' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id'], 'value' => function () { return \yii::$app->user->id; }]]; }
/** * @inheritdoc */ public function behaviors() { $behaviors = []; if ($this->getScenario() != self::SCENARIO_CREATE_TEMPLET) { $behaviors = ['timestamp' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at']]; } return $behaviors; }
public function behaviors() { return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['cnf_created']], 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['cnf_flags']], 'value' => function ($event) { /** @var Conference $model */ $model = $event->sender; return empty($model->cnf_flags) ? self::CONF_FLAG_DEFAULT : $model->cnf_flags; }]]; }
/** * @inheritdoc */ public function behaviors() { return [['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'created_ip'], 'value' => function ($event) { return ip2long(Yii::$app->request->getUserIP()); }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'created_ip'], 'value' => function ($event) { return long2ip($event->sender->created_ip); }], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id']]]; }
/** * @return array */ public function behaviors() { $data = []; if ($this->isTimestampBehavior()) { $data['timestamp'] = ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'created_at', ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'], 'value' => new Expression('NOW()')]; } return $data; }
public function behaviors() { return [ [ 'class' => TimestampBehavior::className(), 'value' => new Expression('NOW()'), ], ]; }
/** * @inheritdoc */ public function behaviors() { return [TimestampBehavior::className(), ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_id']]], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_ip']], 'value' => function ($event) { return Yii::$app->getRequest()->getUserIP(); }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_host']], 'value' => function ($event) { return Yii::$app->getRequest()->getUserHost(); }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_agent']], 'value' => function ($event) { return Yii::$app->getRequest()->getUserAgent(); }]]; }
/** * @inheritdoc */ public function behaviors() { return ['timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at']]], 'event' => ['class' => EventBehavior::className(), 'events' => [ActiveRecord::EVENT_BEFORE_INSERT => function ($event) { $this->message = serialize($this->message); }, ActiveRecord::EVENT_BEFORE_UPDATE => function ($event) { $this->message = serialize($this->message); }, ActiveRecord::EVENT_AFTER_FIND => function ($event) { $this->message = unserialize($this->message); }]]]; }
public function behaviors() { return ['timestamp' => TimestampBehavior::className(), 'event' => ['class' => EventBehavior::className(), 'events' => [ActiveRecord::EVENT_BEFORE_INSERT => function ($event) { $this->access_token && ($this->access_token = serialize($this->access_token)); }, ActiveRecord::EVENT_BEFORE_UPDATE => function ($event) { $this->access_token && ($this->access_token = serialize($this->access_token)); }, ActiveRecord::EVENT_AFTER_FIND => function ($event) { $this->access_token && ($this->access_token = unserialize($this->access_token)); }]]]; }
public function behaviors() { return [['class' => TimestampBehavior::className(), 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'member_id'], 'value' => function ($event) { return Yii::$app->user->identity->id; }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'real_amount'], 'value' => function ($event) { return $this->amount - $this->fee; }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'status'], 'value' => function ($event) { return 1; }]]; }
public function behaviors() { return [['class' => TimestampBehavior::className(), 'value' => new Expression('NOW()')], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'member_id'], 'value' => function ($event) { if ($this->member_id) { return $this->member_id; } else { return Yii::$app->user->id; } }]]; }
public function behaviors() { return [['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at'], ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'user_id', 'updatedByAttribute' => 'user_id'], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'theMust'], 'value' => function ($event) { return $this->kpi->the_must; }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'theBest'], 'value' => function ($event) { return $this->kpi->the_best; }], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'groupName'], 'value' => function ($event) { return $this->kpi->group->name; }]]; }
/** * @inheritdoc */ public function behaviors() { return \yii\helpers\ArrayHelper::merge(parent::behaviors(), ['translateable' => ['class' => \creocoder\translateable\TranslateableBehavior::className(), 'translationAttributes' => static::getTranslationAttributes()], 'timestamp' => ['class' => \yii\behaviors\TimestampBehavior::className()], 'sitemap' => ['class' => SitemapBehavior::className(), 'scope' => function ($model) { /** @var \yii\db\ActiveQuery $model */ $model->andWhere(['published' => 1]); }, 'dataClosure' => function ($model) { /** @var self $model */ return ['loc' => Url::to($model->getViewUrl(), true), 'lastmod' => $model->updated_at, 'changefreq' => SitemapBehavior::CHANGEFREQ_WEEKLY, 'priority' => 0.8]; }]]); }
/** * @inheritdoc */ public function behaviors() { return ['timestamp' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'createdAt', 'updatedAtAttribute' => 'updatedAt'], 'softDelete' => ['class' => SoftDeleteBehavior::className(), 'softDeleteAttributeValues' => ['statusId' => self::STATUS_DELETED, 'updatedAt' => function () { return time(); }], 'restoreAttributeValues' => ['statusId' => self::STATUS_ACTIVE, 'updatedAt' => function () { return time(); }]], 'authLog' => ['class' => AuthLogIdentityBehavior::className(), 'defaultAuthLogData' => function ($model) { return ['ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null, 'host' => isset($_SERVER['REMOTE_ADDR']) ? @gethostbyaddr($_SERVER['REMOTE_ADDR']) : null, 'url' => $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'userAgent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null]; }]]; }
/** * @return array Behaviors */ public function behaviors() { $items = parent::behaviors(); if ($this->timeStampBehaviorEnabled && $this->hasAttribute('created_at')) { $items['date'] = ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => $this->hasAttribute('updated_at') ? 'updated_at' : 'created_at', 'value' => function () { return date('Y-m-d H:i:s'); }]; } return $items; }
/** * @return bool */ public function isVisible() { if (!parent::isVisible()) { return false; } if (!Validate::validate(new HasBehaviorsOr([TimestampBehavior::className(), TimestampPublishedBehavior::className(), BlameableBehavior::className()]), $this->controller->model)->isValid()) { return false; } return $this->checkAdvancedAccess(); }