Repository navigation
Expand file tree
/
Copy pathNestedSet.php
More file actions
69 lines (61 loc) · 2.25 KB
/
Copy pathNestedSet.php
File metadata and controls
69 lines (61 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
class EtuDev_Data_NestedSet
{
/**
* @static
*
* @param Zend_Db_Table_Abstract $tableObject
* @param int $id
*
* @return Zend_Db_Select
*/
static public function getSelectPath($tableObject, $id)
{
$tableName = $tableObject->info(Zend_Db_Table_Abstract::NAME);
$select = $tableObject->select(false);
$select->from(array('p' => $tableName));
$select->join(
array('n' => $tableName),
'n.left_ BETWEEN p.left_ AND p.right_ ' . ($id > 1 ? 'AND p.level > 0' : ''),
array()
); //level > 0 para quitar ROOT, siempre que no estemos pidiendo root
$select->where('n.id = ?', $id);
$select->order('p.left_ ASC');
return $select;
}
/**
* @static
*
* @param Zend_Db_Table_Abstract $tableObject
* @param int $id
*
* @return Zend_Db_Select
*/
static public function getSelectChildrenIds($tableObject, $id, $only_direct_children = true, $include_self = false)
{
// $categories = $this->db->GetAll('SELECT * FROM ' . $this->table . ' WHERE left_ BETWEEN \'' . ($row['left_'] + 1) . '\' AND \'' . $row['right_'] . '\'' . (0 < $levels ? 'AND level BETWEEN ' . ($row['level'] + 1) . ' AND ' . ($row['level'] + $levels) : '') . ('' . ' ' . $where . ' ORDER BY left_'));
$tableName = $tableObject->info(Zend_Db_Table_Abstract::NAME);
$select = $tableObject->select(false);
$select->from(array('n' => $tableName), array('id'));
$select->join(
array('p' => $tableName),
'n.left_ BETWEEN p.left_ AND p.right_ ' . ($include_self ? '' : 'AND n.id != p.id ') . ($only_direct_children ? 'AND n.level = p.level + 1' : ''),
array()
); //level > 0 para quitar ROOT
$select->where('p.id = ?', $id);
$select->order('n.left_ ASC');
return $select;
}
/**
* @static
*
* @param Zend_Db_Table_Abstract $tableObject
* @param int $id
*
* @return Zend_Db_Select
*/
static public function getSelectDescendentIds($tableObject, $id)
{
return static::getSelectChildrenIds($tableObject, $id, false, true);
}
}