2017 © Pedro Peláez
 

library yii2-sortable-behaviour

Yii2 behaviours to sort and select records inside adjency table

image

kl83/yii2-sortable-behaviour

Yii2 behaviours to sort and select records inside adjency table

  • Monday, November 20, 2017
  • by kl83
  • Repository
  • 1 Watchers
  • 0 Stars
  • 63 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 15 % Grown

The README.md

Yii2 sortable behaviour

Latest Stable Version Total Downloads License, (*1)

Provides functionality for sorting and moving model instances in a hierarchical structure of adjacency table., (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require kl83/yii2-sortable-behaviour ~1.1.0

or add, (*5)

"kl83/yii2-sortable-behaviour": "~1.1.0"

to the require section of your composer.json file., (*6)

Usage

Add behaviour to your model.

~~~ php public function behaviors() { return [ [ 'class' => 'kl83\behaviours\SortableBehaviour', 'sortField' => 'sort', 'parentIdField' => 'parent_id', ], ]; }, (*7)


### 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 ``` null moveFirst(int $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. *** ``` null moveLast(int $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. *** ``` null moveAfter(Model|int $model) ``` Moves the model instance after `$model`. If `$model` is empty, then moves the model instance to the beginning of his domain. *** ``` null moveBefore(Model|int $model) ``` Moves the model instance before `$model`. *** ``` int[] getChildrenId(bool $includeSelf = true, bool $all = true) ``` Returns an array of instance IDs of child models. If `$all` is true, it also includes all sublevels. *** ``` \yii\db\ActiveQueryInterface getChildren() ``` Returns ActiveQuery to get child models. *** ``` \yii\db\ActiveQueryInterface getAllChildren(bool $includeSelf = false) ``` Returns ActiveQuery to get instances of child models, including all sublevels. *** ``` Model getParent() ``` Returns an instance of the parent model. *** ``` int[] getParentsId(bool $includeSelf = false) ``` Returns an array of instance IDs of parent models. Ordered by depth level. *** ``` \yii\db\ActiveQueryInterface getParents(bool $includeSelf = false) ``` Returns ActiveQuery to get instances of parent models. *** ``` Model getRoot() ``` Returns an instance of the root model. *** ``` 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: ``` php function($model, $isRoot, $isLeaf){ return $model->title; } ``` *** ``` Model|false getJointParent(Model $model, bool $includeSelf = false) ``` Returns an instance of the joint parent of the current model and `$model`. *** ``` null sortAlphabetically(int $parentId = false, int $direction = SORT_ASC) ``` Sorting model instances in alphabetical order. *** ``` int[] getTreeIds(bool $includeSelf = true, bool $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. *** ``` \yii\db\ActiveQueryInterface getTree(bool $includeSelf = true, bool $includeParents = false) ``` 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, (*8)

The Versions

20/11 2017

dev-master

9999999-dev

Yii2 behaviours to sort and select records inside adjency table

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

database yii2 behavior data

22/07 2017

v1.1.12

1.1.12.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

22/07 2017

v1.1.11

1.1.11.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

19/07 2017

v1.1.10

1.1.10.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

05/07 2017

v1.1.9

1.1.9.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

04/07 2017

v1.1.8

1.1.8.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

04/07 2017

v1.1.7

1.1.7.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

04/07 2017

v1.1.6

1.1.6.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

04/07 2017

v1.1.5

1.1.5.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

04/07 2017

v1.1.4

1.1.4.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

04/07 2017

v1.1.3

1.1.3.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

03/07 2017

v1.1.2

1.1.2.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

03/07 2017

v1.1.1

1.1.1.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

03/07 2017

v1.1.0

1.1.0.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov

24/06 2017

v1.0.0

1.0.0.0

Yii2 behaviours to sort models

  Sources   Download

MIT

The Requires

 

by Aleksandr Solovyov