|
@@ 33-56 (lines=24) @@
|
| 30 |
|
* @param int $depth the depth. |
| 31 |
|
* @return CActiveRecord the owner. |
| 32 |
|
*/ |
| 33 |
|
public function descendants($depth=null) |
| 34 |
|
{ |
| 35 |
|
$owner=$this->getOwner(); |
| 36 |
|
$db=$owner->getDbConnection(); |
| 37 |
|
$criteria=$owner->getDbCriteria(); |
| 38 |
|
$alias=$db->quoteColumnName($owner->getTableAlias()); |
| 39 |
|
|
| 40 |
|
$criteria->mergeWith(array( |
| 41 |
|
'condition'=>$alias.'.'.$db->quoteColumnName($this->leftAttribute).'>'.$owner->{$this->leftAttribute}. |
| 42 |
|
' AND '.$alias.'.'.$db->quoteColumnName($this->rightAttribute).'<'.$owner->{$this->rightAttribute}, |
| 43 |
|
'order'=>$alias.'.'.$db->quoteColumnName($this->leftAttribute), |
| 44 |
|
)); |
| 45 |
|
|
| 46 |
|
if($depth!==null) |
| 47 |
|
$criteria->addCondition($alias.'.'.$db->quoteColumnName($this->levelAttribute).'<='.($owner->{$this->levelAttribute}+$depth)); |
| 48 |
|
|
| 49 |
|
if($this->hasManyRoots) |
| 50 |
|
{ |
| 51 |
|
$criteria->addCondition($alias.'.'.$db->quoteColumnName($this->rootAttribute).'='.CDbCriteria::PARAM_PREFIX.CDbCriteria::$paramCount); |
| 52 |
|
$criteria->params[CDbCriteria::PARAM_PREFIX.CDbCriteria::$paramCount++]=$owner->{$this->rootAttribute}; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
|
return $owner; |
| 56 |
|
} |
| 57 |
|
|
| 58 |
|
/** |
| 59 |
|
* Named scope. Gets children for node (direct descendants only). |
|
@@ 72-95 (lines=24) @@
|
| 69 |
|
* @param int $depth the depth. |
| 70 |
|
* @return CActiveRecord the owner. |
| 71 |
|
*/ |
| 72 |
|
public function ancestors($depth=null) |
| 73 |
|
{ |
| 74 |
|
$owner=$this->getOwner(); |
| 75 |
|
$db=$owner->getDbConnection(); |
| 76 |
|
$criteria=$owner->getDbCriteria(); |
| 77 |
|
$alias=$db->quoteColumnName($owner->getTableAlias()); |
| 78 |
|
|
| 79 |
|
$criteria->mergeWith(array( |
| 80 |
|
'condition'=>$alias.'.'.$db->quoteColumnName($this->leftAttribute).'<'.$owner->{$this->leftAttribute}. |
| 81 |
|
' AND '.$alias.'.'.$db->quoteColumnName($this->rightAttribute).'>'.$owner->{$this->rightAttribute}, |
| 82 |
|
'order'=>$alias.'.'.$db->quoteColumnName($this->leftAttribute), |
| 83 |
|
)); |
| 84 |
|
|
| 85 |
|
if($depth!==null) |
| 86 |
|
$criteria->addCondition($alias.'.'.$db->quoteColumnName($this->levelAttribute).'>='.($owner->{$this->levelAttribute}-$depth)); |
| 87 |
|
|
| 88 |
|
if($this->hasManyRoots) |
| 89 |
|
{ |
| 90 |
|
$criteria->addCondition($alias.'.'.$db->quoteColumnName($this->rootAttribute).'='.CDbCriteria::PARAM_PREFIX.CDbCriteria::$paramCount); |
| 91 |
|
$criteria->params[CDbCriteria::PARAM_PREFIX.CDbCriteria::$paramCount++]=$owner->{$this->rootAttribute}; |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
return $owner; |
| 95 |
|
} |
| 96 |
|
|
| 97 |
|
/** |
| 98 |
|
* Named scope. Gets root node(s). |