Пример #1
0
 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;
     }]];
 }
Пример #2
0
 /**
  * @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']]];
 }
 /**
  * Evaluates the value of the user.
  * The return result of this method will be assigned to the current attribute(s).
  * @param Event $event
  * @return mixed the value of the user.
  */
 protected function getValue($event)
 {
     $value = parent::getValue($event);
     if ($value == null) {
         return 1;
     }
     return $value;
 }
Пример #4
0
 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 [['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;
     }]];
 }
Пример #6
0
 /**
  * @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']]];
 }
Пример #7
0
 /**
  * 
  * @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;
 }
Пример #8
0
 /**
  * @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();
     }]];
 }
Пример #9
0
 /**
  * @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]]);
 }
Пример #10
0
 /**
  * @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);
     }]]];
 }
Пример #11
0
 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;
 }
Пример #12
0
 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;
 }
Пример #13
0
 /**
  * @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);
 }
Пример #14
0
 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']];
 }
Пример #15
0
 public function behaviors()
 {
     return [TimestampBehavior::className(), BlameableBehavior::className()];
 }
Пример #16
0
 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']];
 }
Пример #17
0
 /**
  * @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']]];
 }
Пример #18
0
 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()]];
 }
Пример #19
0
 /**
  * @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']]];
 }
Пример #20
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'updatedAtAttribute' => false], ['class' => BlameableBehavior::className(), 'updatedByAttribute' => false]];
 }
Пример #21
0
 /**
  * @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()]];
 }
Пример #22
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [TimestampBehavior::className(), ['class' => AttributeBehavior::className(), 'attributes' => [ActiveRecord::EVENT_AFTER_FIND => 'body'], 'value' => function ($event) {
         return HtmlPurifier::process(Markdown::process($event->sender->content, 'gfm-comment'));
     }], ['class' => BlameableBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'user_id']]];
 }
Пример #23
0
 public function behaviors()
 {
     return [['class' => SluggableBehavior::className(), 'attribute' => 'name'], 'timestamp' => ['class' => TimestampBehavior::className()], ['class' => BlameableBehavior::className()]];
 }
Пример #24
0
 /**
  * Автозаполнение даты создания и редактирования
  * Автозаполнение пользоватлея, кто создал и кто отредактировал
  * @return array
  */
 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => date('Y-m-d H:i:s')], ['class' => BlameableBehavior::className(), 'createdByAttribute' => Yii::$app->user->isGuest ? null : 'created_by', 'updatedByAttribute' => Yii::$app->user->isGuest ? null : 'updated_by']];
 }
Пример #25
0
 public function behaviors()
 {
     return [TimestampBehavior::className(), BlameableBehavior::className(), DateTimeBehavior::className(), CacheBehavior::className(), ['class' => AdminLogBehavior::className(), 'titleAttribute' => 'title', 'icon' => 'fa-bars bg-olive'], ['class' => TranslateableBehavior::className(), 'translationAttributes' => ['title', 'slug', 'description', 'content', 'image_description', 'redirect', 'meta_title', 'meta_keywords', 'meta_description'], 'translationLanguageAttribute' => 'locale'], ['class' => ImageUploadBehavior::className(), 'attribute' => 'image', 'defaultImage' => '/images/no_image.png', 'thumbs' => ['small' => ['width' => 150, 'height' => 100], 'big' => ['width' => 450, 'height' => 150]], 'filePath' => '@frontend/web/uploads/news/[[id_path]]/[[pk]].[[extension]]', 'fileUrl' => '/uploads/news/[[id_path]]/[[pk]].[[extension]]', 'thumbPath' => '@frontend/web/uploads/news/[[id_path]]/[[profile]]_[[pk]].[[extension]]', 'thumbUrl' => '/uploads/news/[[id_path]]/[[profile]]_[[pk]].[[extension]]'], ['class' => ManyToManyBehavior::className(), 'relations' => [['editableAttribute' => 'categories', 'table' => '{{%news_news_category}}', 'ownAttribute' => 'news_id', 'relatedModel' => NewsCategory::className(), 'relatedAttribute' => 'category_id', 'fillingRoute' => ['news/news/create', 'news/news/update']]]], ['class' => TaggableBehavior::className()], ['class' => GalleryBehavior::className(), 'galleryClass' => NewsGallery::className()]];
 }
Пример #26
0
 /**
  * @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' => 'articleAttachments', 'pathAttribute' => 'path', 'baseUrlAttribute' => 'base_url', 'orderAttribute' => 'order', 'typeAttribute' => 'type', 'sizeAttribute' => 'size', 'nameAttribute' => 'name'], ['class' => UploadBehavior::className(), 'attribute' => 'thumbnail', 'pathAttribute' => 'thumbnail_path', 'baseUrlAttribute' => 'thumbnail_base_url']];
 }
Пример #27
0
 public function behaviors()
 {
     return [['class' => TimestampBehavior::className(), 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => new Expression('NOW()')], ['class' => BlameableBehavior::className(), 'createdByAttribute' => 'created_by', 'updatedByAttribute' => 'updated_by']];
 }
Пример #28
0
 public function behaviors()
 {
     return [['class' => TimestampBehavior::className()], ['class' => BlameableBehavior::className()]];
 }
Пример #29
0
 public function behaviors()
 {
     return [TimestampBehavior::className(), BlameableBehavior::className(), TaggableBehavior::className(), NestedSetsBehavior::className(), SearchBehavior::className(), ['class' => VersionBehavior::className(), 'attributes' => ['title', 'alias', 'preview_text', 'detail_text', 'metakey', 'metadesc']], ['class' => UploadBehavior::className(), 'attributes' => ['detail_image' => ['fileName' => '{id}-full.#extension#'], 'preview_image' => ['fileName' => '{id}-thumb.#extension#', 'fileProcessor' => ThumbnailProcessor::className()]], 'options' => ['savePath' => 'upload/categories']]];
 }
Пример #30
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [BlameableBehavior::className(), TimestampBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title'], 'multilingual' => ['class' => MultilingualBehavior::className(), 'langForeignKey' => 'post_category_id', 'tableName' => "{{%post_category_lang}}", 'attributes' => ['title', 'description']], 'nestedInterval' => ['class' => NestedIntervalsBehavior::className(), 'leftAttribute' => 'left_border', 'rightAttribute' => 'right_border', 'amountOptimize' => '25', 'noPrepend' => true]];
 }