Skip to content
Permalink
Browse files

add scope for generateTreeList - resolves ticket 4028

  • Loading branch information...
dereuromark committed Sep 1, 2013
1 parent fec646b commit eb71eeeac547a8830e071488e6087b42da183f8f
@@ -375,6 +375,12 @@ public function generateTreeList(Model $Model, $conditions = null, $keyPath = nu
} else {
array_unshift($valuePath, '%s' . $valuePath[0], '{n}.tree_prefix');
}
$conditions = (array)$conditions;
if ($scope) {
$conditions[] = $scope;
}
$order = $Model->escapeField($left) . " asc";
$results = $Model->find('all', compact('conditions', 'fields', 'order', 'recursive'));
$stack = array();
@@ -340,4 +340,44 @@ public function testAliasesWithScopeInTwoTreeAssociations() {
));
$this->assertEquals($expected, $result);
}
/**
* testGenerateTreeListWithScope method
*
* @return void
*/
public function testGenerateTreeListWithScope() {
extract($this->settings);
$this->Tree = new $modelClass();
$this->Tree->order = null;
$this->Tree->initialize(2, 3);
$this->Tree->id = 1;
$this->Tree->saveField('flag', 1);
$this->Tree->id = 2;
$this->Tree->saveField('flag', 1);
$this->Tree->Behaviors->attach('Tree', array('scope' => array('FlagTree.flag' => 1)));
$result = $this->Tree->generateTreeList();
$expected = array(
1 => '1. Root',
2 => '_1.1'
);
$this->assertEquals($expected, $result);
// As string.
$this->Tree->Behaviors->attach('Tree', array('scope' => 'FlagTree.flag = 1'));
$result = $this->Tree->generateTreeList();
$this->assertEquals($expected, $result);
// Merging conditions.
$result = $this->Tree->generateTreeList(array('FlagTree.id >' => 1));
$expected = array(
2 => '1.1'
);
$this->assertEquals($expected, $result);
}
}

0 comments on commit eb71eee

Please sign in to comment.
You can’t perform that action at this time.