1 | <?php |
||
38 | class Nestedset_Model |
||
39 | { |
||
40 | /** |
||
41 | * In MySQL and PostgreSQL, 'left' and 'right' are reserved words |
||
42 | * |
||
43 | * This represent the default table structure |
||
44 | */ |
||
45 | protected $_structure = array( |
||
46 | 'id' => 'id', |
||
47 | 'name' => 'name', |
||
48 | 'left' => 'lft', |
||
49 | 'right' => 'rgt', |
||
50 | ); |
||
51 | |||
52 | /** |
||
53 | * Database informations required to locate/save the set |
||
54 | */ |
||
55 | protected $_db; |
||
56 | protected $_tableName; |
||
57 | |||
58 | /** |
||
59 | * @param $tableName|string |
||
60 | * |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function setTableName($tableName) |
||
71 | |||
72 | public function getTableName() |
||
76 | |||
77 | /** |
||
78 | * @param $db|Zend_Db_Adapter |
||
79 | * |
||
80 | * @return $this |
||
81 | */ |
||
82 | public function setDb(Zend_Db_Adapter_Abstract $db) |
||
88 | |||
89 | public function getDb() |
||
93 | |||
94 | /** |
||
95 | * @param $fieldName |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function setStructureId($fieldName) |
||
104 | |||
105 | public function getStructureId() |
||
109 | |||
110 | /** |
||
111 | * @param $fieldName |
||
112 | * |
||
113 | * @return $this |
||
114 | */ |
||
115 | public function setStructureName($fieldName) |
||
120 | |||
121 | public function getStructureName() |
||
125 | |||
126 | /** |
||
127 | * @param $fieldName |
||
128 | * |
||
129 | * @return $this |
||
130 | */ |
||
131 | public function setStructureLeft($fieldName) |
||
136 | |||
137 | public function getStructureLeft() |
||
141 | |||
142 | /** |
||
143 | * @param $fieldName |
||
144 | * |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function setStructureRight($fieldName) |
||
152 | |||
153 | public function getStructureRight() |
||
157 | |||
158 | /** |
||
159 | * @param $name|string Name of the element |
||
160 | * @param $reference|int Id of the reference element |
||
161 | * @param $position|string Position from the reference element. Values are |
||
162 | * 'into', 'before', 'after'. |
||
163 | * |
||
164 | * @return $this |
||
165 | */ |
||
166 | public function add($name, $reference = null, $position = 'into') |
||
178 | |||
179 | /** |
||
180 | * If recursive, delete children, else children move up in the tree |
||
181 | * |
||
182 | * @param $id|int Id of the element to delete |
||
183 | * @param $recursive|boolean Delete element's childrens, default is true |
||
184 | * |
||
185 | * @return $this |
||
186 | */ |
||
187 | public function delete($id, $recursive = true) |
||
211 | |||
212 | /** |
||
213 | * @param $elementId|int Id of the element to move |
||
214 | * @param $referenceId|int Id of the reference element |
||
215 | * @param $position|string Position from the reference element. Values are |
||
216 | * 'into', 'before', 'after'. |
||
217 | * |
||
218 | * @return $this |
||
219 | */ |
||
220 | public function move($elementId, $referenceId, $position = 'into') |
||
240 | |||
241 | /** |
||
242 | * Get width of a node |
||
243 | */ |
||
244 | public function getNodeWidth($elementId) |
||
248 | |||
249 | /** |
||
250 | * Get all nodes without children |
||
251 | * |
||
252 | * @return array |
||
253 | */ |
||
254 | public function getLeafs() |
||
258 | |||
259 | /** |
||
260 | * Get all elements from nested set |
||
261 | * |
||
262 | * @param $depth|array Array of depth wanted. Default is all |
||
263 | * @param $mode|string Mode of depth selection: include/exclude |
||
264 | * @param $order|string Mode of sort |
||
265 | * |
||
266 | * @return array |
||
267 | */ |
||
268 | public function getAll($depth = null, $mode = 'include', $order = 'ASC') |
||
272 | |||
273 | /** |
||
274 | * Convert a tree array (with depth) into a hierarchical array. |
||
275 | * |
||
276 | * @param $nodes|array Array with depth value. |
||
277 | * |
||
278 | * @return array |
||
279 | */ |
||
280 | public function toArray(array $nodes = array()) |
||
288 | |||
289 | /** |
||
290 | * Convert a tree array (with depth) into a hierarchical XML string. |
||
291 | * |
||
292 | * @param $nodes|array Array with depth value. |
||
293 | * |
||
294 | * @return string |
||
295 | */ |
||
296 | public function toXml(array $nodes = array()) |
||
304 | |||
305 | /** |
||
306 | * Return nested set as JSON |
||
307 | * |
||
308 | * @params $nodes|array Original 'flat' nested tree |
||
309 | * |
||
310 | * @return string |
||
311 | */ |
||
312 | public function toJson(array $nodes = array()) |
||
320 | |||
321 | /** |
||
322 | * Returns all elements as <ul>/<li> structure |
||
323 | * |
||
324 | * Possible options: |
||
325 | * - list (simple <ul><li>) |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | public function toHtml(array $nodes = array(), $method = 'list') |
||
337 | |||
338 | /** |
||
339 | * Public method to get an element |
||
340 | * |
||
341 | */ |
||
342 | public function getElement($elementId, $depth = null) |
||
346 | |||
347 | /** |
||
348 | * Get path of an element |
||
349 | * |
||
350 | * @param $elementId|int Id of the element we want the path of |
||
351 | * |
||
352 | * @return array |
||
353 | */ |
||
354 | public function getPath($elementId, $order = 'ASC') |
||
358 | |||
359 | /** |
||
360 | * Get the parent of an element. |
||
361 | * |
||
362 | * @param $elementId|int Element ID |
||
363 | * @param $depth|int Depth of the parent, compared to the child. |
||
364 | * Default is 1 (as immediate) |
||
365 | * |
||
366 | * @return array|false |
||
367 | */ |
||
368 | public function getParent($elementId, $depth = 1) |
||
372 | |||
373 | /** |
||
374 | * Returns the number of descendant of an element. |
||
375 | * |
||
376 | * @params $elementId|int ID of the element |
||
377 | * |
||
378 | * @return int |
||
379 | */ |
||
380 | public function numberOfDescendant($elementId) |
||
387 | |||
388 | /** |
||
389 | * Returns if the element is root. |
||
390 | * |
||
391 | * @param $elementId|int Element ID |
||
392 | * |
||
393 | * @return boolean |
||
394 | */ |
||
395 | public function isRoot($elementId) |
||
399 | } |
||
400 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.