作者:fourteenmeiste
项目:yii2-app-advance
/**
* @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;
}]];
}
作者:evgenyle
项目:book
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');
}]]);
}
作者:joorloohui
项目:bat-web-fronten
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;
}]];
}
作者:sibd
项目:yii2-activerecor
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;
}
作者:zxva
项目:PriceCalculationOfCircuitBoard
/**
* @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');
}]];
}
作者:J-Bea
项目:SchoolDM
/**
* @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 */
}]];
}
作者:yurii-githu
项目:yii2-myli
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');
}]];
}
作者:kleit
项目:golfleagu
/**
* @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’*/
}]];
}
作者:yiico
项目:yii2-mailqueu
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);
}
作者:fanin
项目:gtq
/**
* @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'));
}]];
}
作者:pythago
项目:yii2-mongolo
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']]]];
}
作者:linchpinstudio
项目:yii2-blo
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));
}]];
}
作者:developer-a
项目:yii2-blo
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;
}]];
}
作者:roman444u
项目:moja-objav
/**
* @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;
}
作者:mosed
项目:confpro
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;
}]];
}
作者:fanin
项目:gtq
/**
* @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']]];
}
作者:Zhanat8
项目:alina.tes
/**
* @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;
}
作者:harish-reglobb
项目:Auctio
public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'value' => new Expression('NOW()'),
],
];
}
作者:statsandresult
项目:statsandresult
/**
* @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();
}]];
}
作者:panfak
项目:yii2-wecha
/**
* @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);
}]]];
}