Download the PHP package kl83/yii2-sortable-behaviour without Composer
On this page you can find all versions of the php package kl83/yii2-sortable-behaviour. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-sortable-behaviour
Yii2 sortable behaviour
Provides functionality for sorting and moving model instances in a hierarchical structure of adjacency table.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require kl83/yii2-sortable-behaviour ~1.1.0
or add
"kl83/yii2-sortable-behaviour": "~1.1.0"
to the require section of your composer.json file.
Usage
Add behaviour to your model.
public function behaviors()
{
return [
[
'class' => 'kl83\behaviours\SortableBehaviour',
'sortField' => 'sort',
'parentIdField' => 'parent_id',
],
];
}
Behaviour configuration
Option | Default | Description |
---|---|---|
sortField | idx | Table field containing the order of model instances. |
parentIdField | parentId | Table field containing the identifier of the parent model instance. |
titleField | null | Table field containing the name of the model instance. If not set, tries to use "name" or "title". |
defaultSortVal | 4294967295 | The value of the sort field for the new model instance. By default, a new instance of the model will be the last. |
cache | null | The cache object to use. By default, Yii::$app->cache is used, if it is set. If not, then DummyCache is used. |
Behaviour functions
Moves the model instance to the beginning of $parentId
domain. If $parentId
is not set, then the model instance will be the first in its current domain.
Moves the model instance to the end of $parentId
domain. If $parentId
is not set, then the model instance will be the last in its current domain.
Moves the model instance after $model
. If $model
is empty, then moves the model instance to the beginning of his domain.
Moves the model instance before $model
.
Returns an array of instance IDs of child models. If $all
is true, it also includes all sublevels.
Returns ActiveQuery to get child models.
Returns ActiveQuery to get instances of child models, including all sublevels.
Returns an instance of the parent model.
Returns an array of instance IDs of parent models. Ordered by depth level.
Returns ActiveQuery to get instances of parent models.
Returns an instance of the root model.
Returns the full path of the model instance. $callable
is function to stringify model for output as path element. Simple $callable
example:
Returns an instance of the joint parent of the current model and $model
.
Sorting model instances in alphabetical order.
Returns the identifiers of the child model instances, including all sublevels. Also include instance IDs of the parent models, if $includeParents
is true.
Returns ActiveQuery to get child model instances, including all sublevels. And instances of the parent models, if $includeParents
is true.
PHPDoc model class heading
* @method null moveFirst(integer $parentId = false)
* Moves the model instance to the beginning of $parentId domain.
* If $parentId is not set, then the model instance will be the first in its current domain.
*
* @method null moveLast(integer $parentId = false)
* Moves the model instance to the end of $parentId domain.
* If $parentId is not set, then the model instance will be the last in its current domain.
*
* @method null moveAfter(self|integer $model)
* Moves the model instance after $model.
* If $model is empty, then moves the model instance to the beginning of his domain.
*
* @method null moveBefore(self|integer $model)
* Moves the model instance before $model.
*
* @method integer[] getChildrenId(boolean $includeSelf = true, boolean $all = true)
* Returns an array of instance IDs of child models. If $all is true, it also includes all sublevels.
*
* @method \yii\db\ActiveQueryInterface getChildren()
* Returns ActiveQuery to get child models.
*
* @method \yii\db\ActiveQueryInterface getAllChildren(boolean $includeSelf = false)
* Returns ActiveQuery to get instances of child models, including all sublevels.
*
* @method self getParent()
* Returns an instance of the parent model.
*
* @method integer[] getParentsId(boolean $includeSelf = false)
* Returns an array of instance IDs of parent models. Ordered by depth level.
*
* @method \yii\db\ActiveQueryInterface getParents(boolean $includeSelf = false)
* Returns ActiveQuery to get instances of parent models.
*
* @method self getRoot()
* Returns an instance of the root model.
*
* @method string getFullPath(string $delimeter = " → ", callable $callable = false)
* Returns the full path of the model instance.
* $callable is function to stringify model for output as path element.
* Simple $callable example:
* function($model, $isRoot, $isLeaf){
* return $model->title;
* }
*
* @method self|false getJointParent(self $model, boolean $includeSelf = false)
* Returns an instance of the joint parent of the current model and $model.
*
* @method null sortAlphabetically(integer $parentId = false, integer $direction = SORT_ASC)
* Sorting model instances in alphabetical order.
*
* @method integer[] getTreeIds(boolean $includeSelf = true, boolean $includeParents = false)
* Returns the identifiers of the child model instances, including all sublevels.
* Also include instance IDs of the parent models, if $includeParents is true.
*
* @method \yii\db\ActiveQueryInterface getTree(boolean $includeSelf = true, boolean $includeParents = false)
* Returns ActiveQuery to get child model instances, including all sublevels.
* And instances of the parent models, if $includeParents is true.
License
MIT License