作者: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;
}]];
}
作者: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']]];
}
作者: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']]]];
}
作者:phisitho
项目:yii2-workshop-co-sapc
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;
}]];
}
作者:dextercoo
项目:yii2-q
/**
* @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'));
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_VALIDATE => 'tags'], 'value' => function ($event) {
return $event->sender->tags ? strip_tags($event->sender->tags) : $event->sender->tags;
}], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id']]];
}
作者:bennyb
项目:yii2-cza-bas
/**
*
* @param type $id
* @param type $allowReturnNew
* @return \cza\base\components\controllers\backend\modelClass
* @throws NotFoundHttpException
*/
public function retrieveModel($id = null, $allowReturnNew = true)
{
$model = parent::retrieveModel($id, $allowReturnNew);
$model->attachBehavior('BlameableBehavior', ['class' => BlameableBehavior::className()]);
$cmsFields = $this->getCmsFields();
if (!empty($cmsFields)) {
$model->attachBehavior('CmsMediaBehavior', ['class' => CmsMediaBehavior::className(), 'fields' => $cmsFields]);
}
return $model;
}
作者: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();
}]];
}
作者:Liv102
项目:cm
/**
* @inheritdoc
*/
public function behaviors()
{
return array_merge(parent::behaviors(), [BlameableBehavior::className() => ['class' => BlameableBehavior::className(), 'value' => function ($event) {
if (\Yii::$app instanceof \yii\console\Application) {
return null;
} else {
$user = Yii::$app->get('user', false);
return $user && !$user->isGuest ? $user->id : null;
}
}], TimestampBehavior::className() => ['class' => TimestampBehavior::className()], HasTableCache::className() => ['class' => HasTableCache::className(), 'cache' => \Yii::$app->cache]]);
}
作者:serker7
项目:cross-stitc
/**
* @inheritdoc
*/
public function behaviors()
{
return ['dt' => ['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_date', 'updatedAtAttribute' => 'updated_date', 'value' => new Expression('NOW()')], 'us' => ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'created_user', 'updatedByAttribute' => 'updated_user'], 'galleryBehavior' => ['class' => GalleryBehavior::className(), 'type' => 'posts', 'extension' => 'jpg', 'directory' => Yii::getAlias('@webroot') . '/images/posts/gallery', 'url' => Yii::getAlias('@web') . '/images/posts/gallery', 'versions' => ['small' => function ($img) {
/** @var \Imagine\Image\ImageInterface $img */
return $img->copy()->thumbnail(new \Imagine\Image\Box(200, 200));
}, 'medium' => function ($img) {
/** @var Imagine\Image\ImageInterface $img */
$dstSize = $img->getSize();
$maxWidth = 800;
if ($dstSize->getWidth() > $maxWidth) {
$dstSize = $dstSize->widen($maxWidth);
}
return $img->copy()->resize($dstSize);
}]]];
}
作者:rocketyan
项目:hasscms-ap
public function behaviors()
{
$behaviors = ['sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'ensureUnique' => true, "immutable" => true]];
$behaviors['author_id'] = ['class' => BlameableBehavior::className(), 'attributes' => [static::EVENT_BEFORE_INSERT => 'author_id']];
$behaviors['timestamp'] = TimestampBehavior::className();
$behaviors['published_at'] = ['class' => StrToTimeBehavior::className(), 'attribute' => 'published_at'];
$behaviors['taggabble'] = Taggable::className();
$behaviors['meta'] = MetaBehavior::className();
$behaviors['thumbnailFile'] = ['class' => \hass\attachment\behaviors\UploadBehavior::className(), 'attribute' => 'thumbnail'];
$behaviors['taxonomy'] = ['class' => TaxonomyBehavior::className()];
$behaviors['textEditor'] = ['class' => \hass\base\misc\editor\EditorBehavior::className(), 'attribute' => 'content'];
$behaviors['TimestampFormatter'] = TimestampFormatter::className();
$behaviors['commentEnabled'] = ['class' => CommentBehavior::className(), 'defaultStatus' => CommentEnabledEnum::STATUS_ON];
return $behaviors;
}
作者:Liv102
项目:cm
public function checkAdvancedAccess()
{
if (Validate::validate(new HasBehavior(BlameableBehavior::className()), $this->controller->model)->isValid()) {
//Если такая привилегия заведена, нужно ее проверять.
if ($permission = \Yii::$app->authManager->getPermission(CmsManager::PERMISSION_ALLOW_MODEL_UPDATE_ADVANCED)) {
if (!\Yii::$app->user->can($permission->name, ['model' => $this->controller->model])) {
return false;
}
}
} else {
//Если такая привилегия заведена, нужно ее проверять.
if ($permission = \Yii::$app->authManager->getPermission(CmsManager::PERMISSION_ALLOW_MODEL_UPDATE_ADVANCED)) {
if (!\Yii::$app->user->can($permission->name)) {
return false;
}
}
}
return true;
}
作者:zeleni
项目:yii2-request-log-modul
/**
* @inheritdoc
*/
public function behaviors()
{
list($route, $params) = Yii::$app->getRequest()->resolve();
$isWebApp = Yii::$app instanceof \yii\web\Application;
$webAppBehaviors = [];
$commonBehaviors = [['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['app_id']], 'value' => function ($event) {
return Yii::$app->id;
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['route']], 'value' => function ($event) use($route) {
return $route;
}], ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['params']], 'value' => function ($event) use($params) {
array_walk_recursive($params, function (&$value) {
$value = utf8_encode($value);
});
return var_export($params, true);
}], ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['datetime']], 'value' => new Expression('now()')]];
if ($isWebApp) {
$webAppBehaviors = [['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' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['user_agent']], 'value' => function ($event) {
return Yii::$app->getRequest()->getUserAgent();
}]];
}
return ArrayHelper::merge($commonBehaviors, $webAppBehaviors);
}
作者:nando
项目:yii2capa
public function behaviors()
{
return ['timestamp' => ['class' => 'yii\\behaviors\\TimestampBehavior', 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']], 'value' => new Expression('NOW()')], 'blameable' => ['class' => \yii\behaviors\BlameableBehavior::className(), 'createdByAttribute' => 'created_by', 'updatedByAttribute' => 'updated_by'], ['class' => SluggableBehavior::className(), 'attribute' => 'titulo', 'slugAttribute' => 'seo_slug']];
}
作者:poyku
项目:wp
public function behaviors()
{
return [TimestampBehavior::className(), BlameableBehavior::className()];
}
作者:hsleoni
项目:basetec
public function behaviors()
{
return [['class' => TimestampBehavior::className(), 'attributes' => [\yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], \yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']], 'value' => new Expression('NOW()')], 'blameable' => ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'created_by', 'updatedByAttribute' => 'updated_by']];
}
作者:gromve
项目:yii2-platform-new
/**
* @inheritdoc
*/
public function behaviors()
{
return [['class' => TimestampBehavior::className(), 'attributes' => [self::EVENT_BEFORE_INSERT => 'viewed_at']], ['class' => BlameableBehavior::className(), 'attributes' => [self::EVENT_BEFORE_INSERT => 'user_id']]];
}
作者:fernandre
项目:ipcbsa
public function behaviors()
{
return ['stripTags' => ['class' => StripTagsBehavior::className()], 'timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at']], 'value' => new Expression('NOW()')], 'blameable' => ['class' => BlameableBehavior::className()]];
}
作者:yeesof
项目:yii2-yee-medi
/**
* @inheritdoc
*/
public function behaviors()
{
return [BlameableBehavior::className(), TimestampBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title'], 'multilingual' => ['class' => MultilingualBehavior::className(), 'langForeignKey' => 'media_album_id', 'tableName' => "{{%media_album_lang}}", 'attributes' => ['title', 'description']]];
}
作者:openi-ic
项目:api-builde
/**
* @inheritdoc
*/
public function behaviors()
{
return [['class' => TimestampBehavior::className(), 'updatedAtAttribute' => false], ['class' => BlameableBehavior::className(), 'updatedByAttribute' => false]];
}
作者:allhaz
项目:renaul
/**
* @inheritdoc
*/
public function behaviors()
{
return [TimestampBehavior::className(), ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'author_id', 'updatedByAttribute' => 'updater_id'], ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'immutable' => true], ['class' => UploadBehavior::className(), 'attribute' => 'attachments', 'multiple' => true, 'uploadRelation' => 'financeAttachments'], ['class' => UploadBehavior::className(), 'attribute' => 'thumbnail', 'pathAttribute' => 'thumbnail_path', 'baseUrlAttribute' => 'thumbnail_base_url'], ['class' => ChangeLogBehavior::className()]];
}