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;
 }
Beispiel #2
0
 public function behaviors()
 {
     return [['class' => NestedSetsBehavior::className(), 'depthAttribute' => 'level'], 'coverBehavior' => ['class' => ImageAttachmentBehavior::className(), 'type' => 'catalogs', 'previewHeight' => 200, 'previewWidth' => 200, 'extension' => 'png', 'directory' => Yii::getAlias('@imagesroot') . '/catalogs/gallery', 'url' => Yii::getAlias('@images') . '/catalogs/gallery', 'versions' => ['original' => function ($img) {
         /** @var ImageInterface $img */
         return $img->copy()->resize($img->getSize());
     }]]];
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['timestamp' => TimestampBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name'], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedImage' => ['filesystem' => 'local', 'path' => '/categories', 'fileName' => '{model.slug}.{file.extension}', 'relation' => 'image', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) {
         $image = ImageManagerStatic::make($file->getPath());
         $image->resize(400, null, function (Constraint $constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         $image->save($file->getPath(), 100);
     }]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['image' => ['deleteOnUnlink' => true]], 'relations' => ['imageRelation' => $this->hasOne(CategoryFile::className(), ['id' => 'image_id'])]]];
 }
Beispiel #4
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], 'files' => ['class' => FilesBehavior::className(), 'attributes' => ['uploadedIcon' => ['filesystem' => 'local', 'path' => '/menus', 'fileName' => function ($fileName, MenuItem $model) {
         return Inflector::slug($model->label) . '.' . pathinfo($fileName, PATHINFO_EXTENSION);
     }, 'relation' => 'icon', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) {
         $image = ImageManagerStatic::make($file->getPath());
         $image->resize(100, null, function (Constraint $constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         $image->save($file->getPath(), 100);
     }], 'uploadedActiveIcon' => ['filesystem' => 'local', 'path' => '/menus', 'fileName' => function ($fileName, MenuItem $model) {
         return Inflector::slug($model->label) . '-active.' . pathinfo($fileName, PATHINFO_EXTENSION);
     }, 'relation' => 'activeIcon', 'deleteOnUnlink' => true, 'on beforeSave' => function (FileInterface $file) {
         $image = ImageManagerStatic::make($file->getPath());
         $image->resize(100, null, function (Constraint $constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         });
         $image->save($file->getPath(), 100);
     }], 'uploadedVideo' => ['filesystem' => 'local', 'path' => '/menus', 'fileName' => function ($fileName, MenuItem $model) {
         return Inflector::slug($model->label) . '.' . pathinfo($fileName, PATHINFO_EXTENSION);
     }, 'relation' => 'video', 'deleteOnUnlink' => true]]], 'relations' => ['class' => RelationsBehavior::className(), 'settings' => ['icon' => ['deleteOnUnlink' => true], 'activeIcon' => ['deleteOnUnlink' => true], 'video' => ['deleteOnUnlink' => true]], 'relations' => ['iconRelation' => $this->hasOne(MenuItemFile::className(), ['id' => 'icon_id']), 'activeIconRelation' => $this->hasOne(MenuItemFile::className(), ['id' => 'active_icon_id']), 'videoRelation' => $this->hasOne(MenuItemFile::className(), ['id' => 'video_id'])]]];
 }
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => CacheFlush::className(), 'key' => [['yii\\widgets\\FragmentCache', 'menu_item']]]];
 }
Beispiel #6
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [['class' => NestedSetsBehavior::className()]];
 }
Beispiel #7
0
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'level']];
 }
Beispiel #8
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return \yii\helpers\ArrayHelper::merge(parent::behaviors(), ['timestamp' => ['class' => \yii\behaviors\TimestampBehavior::className()], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']]);
 }
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className()], 'fileBehavior' => ['class' => FileBehavior::className(), 'storage' => [$this, 'getStoragePath'], 'fileField' => 'image', 'imageSettings' => ['thumb1' => ['method' => 'thumbnail', 'width' => 50, 'height' => 50], 'thumb2' => ['method' => 'thumbnail', 'width' => 100, 'height' => 100], 'thumb3' => ['method' => 'thumbnail', 'width' => 200, 'height' => 200]]]];
 }
Beispiel #10
0
 public function behaviors()
 {
     $behaviors = ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
     $behaviors['meta'] = ['class' => \hass\meta\behaviors\MetaBehavior::className(), 'entityClass' => 'hass\\taxonomy\\models\\Taxonomy'];
     return $behaviors;
 }
Beispiel #11
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [TimestampBehavior::className(), 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => SluggableBehavior::className(), 'attribute' => ['title', 'alias'], 'slugAttribute' => 'alias', 'ensureUnique' => true]];
 }
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $treeStructure = ['treeAttribute' => 'root', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'lvl'];
     $settings = ['class' => NestedSetsBehavior::className()] + $treeStructure;
     return ['tree' => $settings];
 }
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['slug' => ['class' => 'Zelenin\\yii\\behaviors\\Slug', 'slugAttribute' => 'slug', 'attribute' => ['title', 'slug'], 'ensureUnique' => true, 'replacement' => '-', 'lowercase' => true, 'immutable' => true, 'transliterateOptions' => 'Russian-Latin/BGN; Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC;'], ['class' => TimestampBehavior::className()], ['class' => BlameableBehavior::className()], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth']];
 }
Beispiel #14
0
 public function behaviors()
 {
     return [['class' => NestedSetsBehavior::className()], 'timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at']]], 'userHash' => UserHashBehavior::className()];
 }
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['timestamp' => ['class' => TimestampBehavior::className()], 'tree' => ['class' => NestedSetsBehavior::className(), 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth', 'treeAttribute' => 'tree'], 'slug' => ['class' => SluggableBehavior::className(), 'slugAttribute' => 'alias', 'attribute' => 'title', 'immutable' => true, 'ensureUnique' => true]];
 }
Beispiel #16
0
 public function behaviors()
 {
     return ['metaBehavior' => MetaBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name', 'ensureUnique' => true, "immutable" => true], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
 }
Beispiel #17
0
 public function behaviors()
 {
     return [['class' => SluggableBehavior::className(), 'attribute' => 'name'], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth']];
 }
Beispiel #18
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [['class' => SluggableBehavior::className(), 'attribute' => 'slug', 'slugAttribute' => 'slug', 'ensureUnique' => true], ['class' => TimestampBehavior::className()], ['class' => BlameableBehavior::className()], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth']];
 }
Beispiel #19
0
 public function behaviors()
 {
     return ['cacheflush' => ['class' => CacheFlush::className(), 'key' => [static::tableName() . '_tree', static::tableName() . '_flat']], 'seoBehavior' => SeoBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'ensureUnique' => true], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
 }
Beispiel #20
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $module = TreeView::module();
     $settings = ['class' => NestedSetsBehavior::className()] + $module->treeStructure;
     return empty($module->treeBehaviorName) ? [$settings] : [$module->treeBehaviorName => $settings];
 }
Beispiel #21
0
 /**
  * Automatically insert created_at, created_by, updated_at, updated_by
  *
  * @see \yii\base\Component::behaviors()
  */
 public function behaviors()
 {
     return ['Blameable' => \yii\behaviors\BlameableBehavior::className(), 'Timestamp' => \yii\behaviors\TimestampBehavior::className(), 'NestedSets' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'root']];
 }
Beispiel #22
0
 public function behaviors()
 {
     return ['cacheflush' => ['class' => CacheFlush::className(), 'key' => [static::tableName() . '_tree', static::tableName() . '_flat']], 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'ensureUnique' => true], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], 'timestamp' => ['class' => TimestampBehavior::className()], 'blame' => ['class' => BlameableBehavior::className()], 'audit' => ['class' => ARLogBehavior::className()]];
 }
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $module = TreeView::module();
     $settings = ['class' => NestedSetsBehavior::className()] + $module->treeStructure;
     $times = ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_time', 'updated_time'], ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_time']], 'value' => function ($event) {
         return date("Y-m-d H:i:s");
     }];
     return empty($module->treeBehaviorName) ? [$settings, $times] : [$module->treeBehaviorName => $settings, $times];
 }
Beispiel #24
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'slugAttribute' => 'alias', 'immutable' => true]];
 }
Beispiel #25
0
 public function behaviors()
 {
     return ['root' => ['class' => \creocoder\nestedsets\NestedSetsBehavior::className(), 'treeAttribute' => 'root'], 'slug' => ['class' => 'Zelenin\\yii\\behaviors\\Slug', 'slugAttribute' => 'name', 'attribute' => 'title', 'ensureUnique' => true, 'replacement' => '-', 'lowercase' => true, 'immutable' => false, 'transliterateOptions' => 'Russian-Latin/BGN; Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC;']];
 }
Beispiel #26
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [['class' => NestedSetsBehavior::className(), 'leftAttribute' => $this->leftAttribute, 'rightAttribute' => $this->rightAttribute, 'treeAttribute' => $this->treeAttribute, 'depthAttribute' => $this->depthAttribute]];
 }
Beispiel #27
0
 public function behaviors()
 {
     return ['cacheflush' => ['class' => CacheFlush::className(), 'key' => [static::tableName() . '_tree', static::tableName() . '_flat']], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
 }
Beispiel #28
0
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
 }
 /**
  * @return array
  */
 public function behaviors()
 {
     return ['trans' => ['class' => TranslateableBehavior::className(), 'translationAttributes' => ['name', 'content']], 'timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'], ActiveRecord::EVENT_BEFORE_UPDATE => 'updated_at'], 'value' => function () {
         return time();
     }], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'root', 'depthAttribute' => 'level']];
 }