コード例 #1
0
 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;
 }
コード例 #2
0
ファイル: Catalogs.php プロジェクト: sapgv/distributive
 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());
     }]]];
 }
コード例 #3
0
ファイル: Category.php プロジェクト: manyoubaby123/imshop
 /**
  * @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'])]]];
 }
コード例 #4
0
ファイル: MenuItem.php プロジェクト: manyoubaby123/imshop
 /**
  * @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'])]]];
 }
コード例 #5
0
ファイル: Categories.php プロジェクト: roman1970/lis
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'level']];
 }
コード例 #6
0
ファイル: Comment.php プロジェクト: tolik505/bl
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return \yii\helpers\ArrayHelper::merge(parent::behaviors(), ['timestamp' => ['class' => \yii\behaviors\TimestampBehavior::className()], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']]);
 }
コード例 #7
0
ファイル: Category.php プロジェクト: bigbrush/yii2-big
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [TimestampBehavior::className(), 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => SluggableBehavior::className(), 'attribute' => ['title', 'alias'], 'slugAttribute' => 'alias', 'ensureUnique' => true]];
 }
コード例 #8
0
ファイル: Taxonomy.php プロジェクト: rocketyang/hasscms-app
 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;
 }
コード例 #9
0
ファイル: CategoryModel.php プロジェクト: solbianca/easyii
 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']];
 }
コード例 #10
0
ファイル: NestedSetsBehavior.php プロジェクト: yujin1st/core
 /**
  * @inheritDoc
  * @throws \yii\base\NotSupportedException
  * @throws \yii\db\Exception
  */
 public function afterDelete()
 {
     if (!$this->ownDeleteHandler) {
         parent::afterDelete();
     }
 }
コード例 #11
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']];
 }
コード例 #12
0
ファイル: Comment.php プロジェクト: testbots/openbay
 public function behaviors()
 {
     return [['class' => NestedSetsBehavior::className()], 'timestamp' => ['class' => TimestampBehavior::className(), 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => ['created_at']]], 'userHash' => UserHashBehavior::className()];
 }
コード例 #13
0
 /**
  * @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]];
 }
コード例 #14
0
ファイル: Taxonomy.php プロジェクト: rocketyang/hasscms-app
 public function behaviors()
 {
     return ['metaBehavior' => MetaBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name', 'ensureUnique' => true, "immutable" => true], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
 }
コード例 #15
0
 /**
  * Wrapper function to be able to use the protected method of the NestedSetsBehavior
  *
  * @param integer $value
  * @param integer $depth
  */
 public function nodeMove($value, $depth)
 {
     $this->node = $this->owner;
     parent::moveNode($value, $depth);
 }
コード例 #16
0
ファイル: Category.php プロジェクト: alfarioekaputra/yii2_cms
 public function behaviors()
 {
     return [['class' => SluggableBehavior::className(), 'attribute' => 'name'], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth']];
 }
コード例 #17
0
ファイル: Category.php プロジェクト: miptliot/vps-tools
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [['class' => NestedSetsBehavior::className()]];
 }
コード例 #18
0
 /**
  * @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']];
 }
コード例 #19
0
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => CacheFlush::className(), 'key' => [['yii\\widgets\\FragmentCache', 'menu_item']]]];
 }
コード例 #20
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $treeStructure = ['treeAttribute' => 'root', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'lvl'];
     $settings = ['class' => NestedSetsBehavior::className()] + $treeStructure;
     return ['tree' => $settings];
 }
コード例 #21
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $module = TreeView::module();
     $settings = ['class' => NestedSetsBehavior::className()] + $module->treeStructure;
     return empty($module->treeBehaviorName) ? [$settings] : [$module->treeBehaviorName => $settings];
 }
コード例 #22
0
ファイル: Tree.php プロジェクト: manyoubaby123/imshop
 /**
  * @param Tree|NestedSetsBehavior $node
  * @param array $items
  * @return TreeRecursiveIterator
  */
 public static function buildNodeTree($node, $items = [])
 {
     $items = $items ?: $node->children()->all();
     $tree = self::buildTree($items, $node->{$node->leftAttribute}, $node->{$node->rightAttribute});
     return $tree;
 }
コード例 #23
0
ファイル: CategoryModel.php プロジェクト: tqsq2005/Yii2adv
 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()]];
 }
コード例 #24
0
 /**
  * @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];
 }
コード例 #25
0
ファイル: Menu.php プロジェクト: bitxseven/yii2-big
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'slugAttribute' => 'alias', 'immutable' => true]];
 }
コード例 #26
0
ファイル: Category.php プロジェクト: simplator/articles
 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;']];
 }
コード例 #27
0
ファイル: TreeModel.php プロジェクト: phpsong/yii2-gtreetable
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [['class' => NestedSetsBehavior::className(), 'leftAttribute' => $this->leftAttribute, 'rightAttribute' => $this->rightAttribute, 'treeAttribute' => $this->treeAttribute, 'depthAttribute' => $this->depthAttribute]];
 }
コード例 #28
0
ファイル: CategoryModel.php プロジェクト: oakcms/oakcms
 public function behaviors()
 {
     return ['cacheflush' => ['class' => CacheFlush::className(), 'key' => [static::tableName() . '_tree', static::tableName() . '_flat']], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
 }
コード例 #29
0
ファイル: Categories.php プロジェクト: askeroff/blogyii2
 public function behaviors()
 {
     return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']];
 }
コード例 #30
0
ファイル: Category.php プロジェクト: karsel/yii2-shop-module
 /**
  * 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']];
 }