1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-07-01 05:55:00 +03:00

NestedSetQuery added

This commit is contained in:
Alexander Kochetov 2013-05-07 11:29:37 +04:00
parent a8618dc48b
commit ab19de1e2a

40
NestedSetQuery.php Normal file
View file

@ -0,0 +1,40 @@
<?php
/**
* @link https://github.com/creocoder/nested-set-behavior-2
* @copyright Copyright (c) 2013 Alexander Kochetov
* @license http://www.yiiframework.com/license/
*/
namespace creocoder\yii\behaviors;
use yii\base\Behavior;
use yii\db\ActiveRecord;
use yii\db\ActiveQuery;
/**
* @author Alexander Kochetov <creocoder@gmail.com>
*/
class NestedSetQuery extends Behavior
{
/**
* @var ActiveQuery the owner of this behavior.
*/
public $owner;
public $hasManyRoots = false;
public $rootAttribute = 'root';
public $leftAttribute = 'lft';
public $rightAttribute = 'rgt';
public $levelAttribute = 'level';
/**
* Named scope. Gets root node(s).
* @param ActiveQuery $query.
* @return ActiveRecord the owner.
*/
public function roots($query)
{
/** @var $modelClass ActiveRecord */
$modelClass=$this->owner->modelClass;
$query->andWhere($modelClass::getDb()->quoteColumnName($this->leftAttribute) . '=1');
}
}