1
0
Fork 0
mirror of https://github.com/Oreolek/yii2-nested-sets.git synced 2024-07-08 17:34:24 +03:00
yii2-nested-sets/NestedSetQuery.php

42 lines
924 B
PHP
Raw Normal View History

2013-05-07 10:29:37 +03:00
<?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';
/**
2013-05-07 14:10:05 +03:00
* Gets root node(s).
2013-05-07 10:29:37 +03:00
* @return ActiveRecord the owner.
*/
2013-05-07 14:10:05 +03:00
public function roots()
2013-05-07 10:29:37 +03:00
{
/** @var $modelClass ActiveRecord */
$modelClass=$this->owner->modelClass;
2013-05-07 14:10:05 +03:00
$this->owner->andWhere($modelClass::getDb()->quoteColumnName($this->leftAttribute) . '=1');
return $this->owner;
2013-05-07 10:29:37 +03:00
}
}