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; }
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()); }]]]; }
/** * @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'])]]]; }
/** * @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', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'level']]; }
/** * @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 [TimestampBehavior::className(), 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => SluggableBehavior::className(), 'attribute' => ['title', 'alias'], 'slugAttribute' => 'alias', 'ensureUnique' => true]]; }
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; }
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']]; }
/** * @inheritDoc * @throws \yii\base\NotSupportedException * @throws \yii\db\Exception */ public function afterDelete() { if (!$this->ownDeleteHandler) { parent::afterDelete(); } }
/** * @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']]; }
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]]; }
public function behaviors() { return ['metaBehavior' => MetaBehavior::className(), 'sluggable' => ['class' => SluggableBehavior::className(), 'attribute' => 'name', 'ensureUnique' => true, "immutable" => true], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']]; }
/** * 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); }
public function behaviors() { return [['class' => SluggableBehavior::className(), 'attribute' => 'name'], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree', 'leftAttribute' => 'lft', 'rightAttribute' => 'rgt', 'depthAttribute' => 'depth']]; }
/** * @inheritdoc */ public function behaviors() { return [['class' => NestedSetsBehavior::className()]]; }
/** * @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']]; }
public function behaviors() { return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => CacheFlush::className(), 'key' => [['yii\\widgets\\FragmentCache', 'menu_item']]]]; }
/** * @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() { $module = TreeView::module(); $settings = ['class' => NestedSetsBehavior::className()] + $module->treeStructure; return empty($module->treeBehaviorName) ? [$settings] : [$module->treeBehaviorName => $settings]; }
/** * @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; }
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]; }
/** * @inheritdoc */ public function behaviors() { return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree'], ['class' => SluggableBehavior::className(), 'attribute' => 'title', 'slugAttribute' => 'alias', 'immutable' => true]]; }
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;']]; }
/** * @inheritdoc */ public function behaviors() { return [['class' => NestedSetsBehavior::className(), 'leftAttribute' => $this->leftAttribute, 'rightAttribute' => $this->rightAttribute, 'treeAttribute' => $this->treeAttribute, 'depthAttribute' => $this->depthAttribute]]; }
public function behaviors() { return ['cacheflush' => ['class' => CacheFlush::className(), 'key' => [static::tableName() . '_tree', static::tableName() . '_flat']], 'tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']]; }
public function behaviors() { return ['tree' => ['class' => NestedSetsBehavior::className(), 'treeAttribute' => 'tree']]; }
/** * 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']]; }