*** empty log message ***
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_treeview.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2002 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Base class for creating a page/folder tree in HTML
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 August/2003 by Kasper Skaarhoj
32 * Maintained by René Fritz
33 *
34 * @author Kasper Skaarhoj <kasper@typo3.com>
35 * @coauthor René Fritz <r.fritz@colorcube.de>
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 103: class t3lib_treeView
43 * 250: function init($clause='')
44 * 267: function reset()
45 * 281: function getBrowsableTree($addClause='')
46 * 356: function printTree($treeArr='')
47 * 394: function PMicon(&$row,$a,$c,$nextCount,$exp)
48 * 416: function PM_ATagWrap($icon,$cmd,$bMark='')
49 * 434: function wrapTitle($title,$v)
50 * 447: function wrapIcon($icon,&$row)
51 * 472: function wrapStop($str,&$row)
52 * 486: function getCount($uid)
53 * 507: function addField($field,$noCheck=0)
54 * 523: function expandNext($id)
55 * 533: function savePosition()
56 *
57 * SECTION: functions that might be overwritten by extended classes
58 * 550: function getRootRecord($uid)
59 * 560: function getRootIcon($rec)
60 * 570: function getRecord($uid)
61 * 584: function getId($v)
62 * 594: function getJumpToParm($v)
63 * 604: function getIcon(&$row)
64 * 619: function getTitleStr(&$row)
65 * 630: function getTitleAttrib(&$row)
66 *
67 * SECTION: data handling
68 * 663: function getTree($uid, $depth=999, $depthData='',$blankLineCode='')
69 * 738: function getDataInit($parentId)
70 * 765: function getDataCount($res)
71 * 780: function getDataNext($res)
72 * 799: function getDataFree($res)
73 * 815: function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0)
74 *
75 * TOTAL FUNCTIONS: 27
76 * (This index is automatically created/updated by the extension "extdeveval")
77 *
78 */
79
80
81
82
83
84
85
86
87
88
89
90 require_once (PATH_t3lib.'class.t3lib_iconworks.php');
91 require_once (PATH_t3lib.'class.t3lib_befunc.php');
92 require_once (PATH_t3lib.'class.t3lib_div.php');
93
94 /**
95 * Base class for creating a page/folder tree in HTML
96 *
97 * @author Kasper Skaarhoj <kasper@typo3.com>
98 * @coauthor René Fritz <r.fritz@colorcube.de>
99 * @package TYPO3
100 * @subpackage t3lib
101 * @see t3lib_browsetree, t3lib_pagetree, t3lib_foldertree
102 */
103 class t3lib_treeView {
104
105 /**
106 * Needs to be initialized with $GLOBALS['BE_USER']
107 */
108 var $BE_USER='';
109
110 /**
111 * Needs to be initialized with e.g. $GLOBALS['WEBMOUNTS']
112 */
113 var $MOUNTS='';
114
115 /**
116 * A prefix for table cell id's which will be wrapped around an item.
117 * Can be used for highlighting by JavaScript.
118 * Needs to be unique if multiple pages are on one HTML page.
119 */
120 var $domIdPrefix = 'row';
121
122 /**
123 * Database table to get the tree data from.
124 * Leave blank if data comes from an array.
125 */
126 var $table='';
127
128 /**
129 * Defines the field of $table which is the parent id field (like pid for table pages).
130 */
131 var $parentField='pid';
132
133 /**
134 * Unique name for the tree.
135 * Used as key for storing the tree into the BE users settings.
136 * Used as key to pass parameters in links.
137 * etc.
138 */
139 var $treeName = '';
140
141 /**
142 * Icon file name for item icons.
143 */
144 var $iconName = 'default.gif';
145
146 /**
147 * Icon file path.
148 */
149 var $iconPath = '';
150
151 /**
152 * Back path for icons
153 */
154 var $backPath;
155
156
157 /**
158 * If true, HTML code is also accumulated in ->tree array during rendering of the tree.
159 */
160 var $makeHTML=1;
161
162 /**
163 * If true, records as selected will be stored internally in the ->recs array
164 */
165 var $setRecs = 0;
166
167 /**
168 * WHERE clause used for selecting records for the tree. Is set by function init
169 * @see init()
170 */
171 var $clause=' AND NOT deleted';
172
173
174 /**
175 * Default set of fields selected from the tree table.
176 * @see addField()
177 */
178 var $fieldArray = Array('uid','title');
179
180 /**
181 * List of other fields which are ALLOWED to set
182 * @see addField()
183 */
184 var $defaultList = 'uid,pid,tstamp,sorting,deleted,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,crdate,cruser_id';
185
186
187 // *********
188 // internal
189 // *********
190 // For record trees:
191 var $ids = Array(); // one-dim array of the id's selected.
192 var $ids_hierarchy = array(); // The hierarchy of page ids
193 var $buffer_idH = array(); // Temporary, internal array
194
195 // For FOLDER trees:
196 var $specUIDmap=array(); // Special UIDs for folders (integer-hashes of paths)
197
198 // For both types
199 var $tree = Array(); // Tree is accumulated in this variable
200
201
202
203
204
205 /**
206 * The tree array. Stored for the BE user.
207 */
208 var $stored = array();
209
210
211 var $bank=0;
212 var $thisScript='';
213 var $expandAll=0;
214 var $expandFirst=0;
215
216
217
218
219
220
221
222 // which HTML attribute to use: alt/title
223 var $titleAttrib = 'title';
224
225 // $ext_IconMode = $BE_USER->getTSConfigVal("options.pageTree.disableIconLinkToContextmenu");
226 var $ext_IconMode = false;
227
228 var $addSelfId = 0;
229
230 // used if the tree is made of records (not folders for ex.)
231 var $title='no title';
232
233 var $data = array();
234 var $currData = array();
235 var $currDataC = 0;
236
237 // internal
238 var $recs = array();
239
240 var $dbres;
241
242
243 /**
244 * Initialize the tree class. Needs to be overwritten
245 * Will set ->fieldsArray, ->backPath and ->clause
246 *
247 * @param string record select clause
248 * @return void
249 */
250 function init($clause='') {
251 $this->BE_USER = $GLOBALS['BE_USER'];
252 $this->titleAttrib = t3lib_BEfunc::titleAttrib();
253 $this->backPath = $GLOBALS['BACK_PATH'];
254
255 $this->clause = $clause ? $clause : $this->clause;
256
257 if(!is_array($this->MOUNTS)){
258 $this->MOUNTS = array(0 => 0); // dummy
259 }
260 }
261
262 /**
263 * Resets the tree, recs, ids, and ids_hierarchy internal variables
264 *
265 * @return void
266 */
267 function reset() {
268 $this->tree = array();
269 $this->recs = array();
270 $this->ids = array();
271 $this->ids_hierarchy = array();
272 }
273
274 /**
275 * Will create and return the HTML code for a browsable tree
276 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
277 *
278 * @param string Additional WHERE clause (this is additional clauses you can set!)
279 * @return string HTML code for the browsable tree
280 */
281 function getBrowsableTree($addClause='') {
282 #TODO: $this->init($addClause);
283 #TODO: $this->init(' AND '.$this->permsC().$addClause);
284
285 // Get stored tree structure:
286 $this->stored=unserialize($this->BE_USER->uc[$this->treeName]);
287 #debug($this->stored);
288 // PM action
289 // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree):
290 $PM = explode('_',t3lib_div::GPvar('PM'));
291 #debug($PM);
292
293 if (count($PM)==4 && $PM[3]==$this->treeName) {
294 if (isset($this->MOUNTS[$PM[0]])) {
295 if ($PM[1]) { // set
296 $this->stored[$PM[0]][$PM[2]]=1;
297 $this->savePosition();
298 } else { // clear
299 unset($this->stored[$PM[0]][$PM[2]]);
300 $this->savePosition();
301 }
302 }
303 }
304
305 // traverse mounts:
306 $titleLen=intval($this->BE_USER->uc['titleLen']);
307 $treeArr=array();
308 reset($this->MOUNTS);
309 while(list($idx,$uid)=each($this->MOUNTS)) {
310 // Set first:
311 $this->bank=$idx;
312 $isOpen = $this->stored[$idx][$uid] || $this->expandFirst;
313
314 $curIds = $this->ids; // save ids
315 $this->reset();
316 $this->ids = $curIds;
317
318 // Set PM icon:
319 $cmd=$this->bank.'_'.($isOpen?"0_":"1_").$uid.'_'.$this->treeName;
320 $icon='<img src="'.$this->backPath.'t3lib/gfx/ol/'.($isOpen?'minus':'plus').'only.gif" width="18" height="16" align="top" border="0" alt="" />';
321 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
322
323 // Preparing rootRec for the mount
324 if ($uid>0) {
325 $rootRec=$this->getRecord($uid);
326 $firstHtml.=$this->getIcon($rootRec);
327 } else {
328 // Artificial record for the tree root, id=0
329 $rootRec=$this->getRootRecord($uid);
330 $firstHtml.=$this->getRootIcon($rootRec);
331 }
332
333 // Add the root of the mount to ->tree
334 $this->tree[]=array('HTML'=>$firstHtml,'row'=>$rootRec);
335
336 // If the mount is expanded, go down:
337 if ($isOpen) {
338 // Set depth:
339 $depthD='<img src="'.$this->backPath.'t3lib/gfx/ol/blank.gif" width="18" height="16" align="top" alt="" />';
340 if ($this->addSelfId) $this->ids[] = $uid;
341 $this->getTree($uid,999,$depthD);
342 }
343
344 // Add tree:
345 $treeArr=array_merge($treeArr,$this->tree);
346 }
347 return $this->printTree($treeArr);
348 }
349
350 /**
351 * Compiles the HTML code for displaying the structure found inside the ->tree array
352 *
353 * @param array "tree-array" - if blank string, the internal ->tree array is used.
354 * @return string The HTML code for the tree
355 */
356 function printTree($treeArr='') {
357 $titleLen=intval($this->BE_USER->uc['titleLen']);
358 if (!is_array($treeArr)) $treeArr=$this->tree;
359 reset($treeArr);
360 $out='';
361
362 // put a table around it with IDs to access the rows from JS
363 // not a problem if you don't need it
364 // In XHTML there is no "name" attribute of <td> elements - but Mozilla will not be able to highlight rows if the name attribute is NOT there.
365 $out .= '<table cellpadding="0" cellspacing="0" border="0" width="100%">';
366 while(list($k,$v)=each($treeArr)) {
367 $idAttr = htmlspecialchars($this->domIdPrefix.$this->getId($v['row']));
368 $out.='
369 <tr>
370 <td name="'.$idAttr.'" id="'.$idAttr.'" nowrap="nowrap">'.
371 $v['HTML'].
372 $this->wrapTitle(t3lib_div::fixed_lgd($this->getTitleStr($v['row']),$titleLen),$v['row']).
373 '</td>
374 </tr>
375 ';
376 }
377 $out .= '</table>';
378 return $out;
379 }
380
381 /**
382 * Generate the plus/minus icon for the browsable tree.
383 * Extending parent function
384 *
385 * @param array record for the entry
386 * @param integer The current entry number
387 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
388 * @param integer The number of sub-elements to the current element.
389 * @param boolean The element was expanded to render subelements if this flag is set.
390 * @return string Image tag with the plus/minus icon.
391 * @access private
392 * @see t3lib_pageTree::PMicon()
393 */
394 function PMicon(&$row,$a,$c,$nextCount,$exp) {
395 $PM = $nextCount ? ($exp?'minus':'plus') : 'join';
396 $BTM = ($a==$c)?'bottom':'';
397 $icon = '<img src="'.$this->backPath.'t3lib/gfx/ol/'.$PM.$BTM.'.gif" width="18" height="16" align="top" border="0" alt="" />';
398
399 if ($nextCount) {
400 $cmd=$this->bank.'_'.($exp?'0_':'1_').$row['uid'].'_'.$this->treeName;
401 $bMark=($this->bank.'_'.$row['uid']);
402 $icon = $this->PM_ATagWrap($icon,$cmd,$bMark);
403 }
404 return $icon;
405 }
406
407 /**
408 * Wrap the plus/minus icon in a link
409 *
410 * @param string HTML string to wrap, probably an image tag.
411 * @param string Command for 'PM' get var
412 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
413 * @return string Link-wrapped input string
414 * @access private
415 */
416 function PM_ATagWrap($icon,$cmd,$bMark='') {
417 if ($bMark) {
418 $anchor = '#'.$bMark;
419 $name=' name="'.$bMark.'"';
420 }
421 $aUrl = $this->thisScript.'?PM='.$cmd.$anchor;
422 return '<a href="'.htmlspecialchars($aUrl).'"'.$name.'>'.$icon.'</a>';
423 }
424
425 /**
426 * Wrapping $title in a-tags.
427 * $v is the array with item and other info.
428 *
429 * @param string Title string
430 * @param string Not used, ignore
431 * @return string Either htmlspecialchar()'ed version of input value OR (if input was empty) a label like "[no title]"
432 * @access private
433 */
434 function wrapTitle($title,$v) {
435 $aOnClick = 'return jumpTo('.$this->getJumpToParm($v).',this);';
436 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
437 }
438
439 /**
440 * Wrapping the image tag, $icon, for the row, $row
441 *
442 * @param string The image tag for the icon
443 * @param array The row for the current element
444 * @return string The processed icon input value.
445 * @access private
446 */
447 function wrapIcon($icon,&$row) {
448 // Add title attribute to input icon tag
449 $lockIcon='';
450 $theIcon = substr($icon,0,-1);
451 $theIcon .= $this->titleAttrib? (' '.$this->titleAttrib.'="'.$this->getTitleAttrib($row)).'"' : '';
452 $theIcon .= ' border="0" />';
453
454 // Wrap icon in click-menu link.
455 if (!$this->ext_IconMode) {
456 $theIcon = $GLOBALS['TBE_TEMPLATE']->wrapClickMenuOnIcon($theIcon,$this->treeName,$this->getId($row),0);
457 } elseif (!strcmp($this->ext_IconMode,'titlelink')) {
458 $aOnClick = 'return jumpTo('.$this->getJumpToParm($row).',this);';
459 $theIcon='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$theIcon.'</a>';
460 }
461 return $theIcon.$lockIcon;
462 }
463
464 /**
465 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set
466 *
467 * @param string Input string, like a page title for the tree
468 * @param array record row with "php_tree_stop" field
469 * @return string Modified string
470 * @access private
471 */
472 function wrapStop($str,&$row) {
473 if ($row['php_tree_stop']) {
474 $str.='<span class="typo3-red">+ </span>';
475 }
476 return $str;
477 }
478
479 /**
480 * Returns the number of records having the parent id, $uid
481 *
482 * @param integer id to count subitems for
483 * @return integer
484 * @access private
485 */
486 function getCount($uid) {
487 if ($this->table) {
488 $query = 'SELECT count(*) FROM '.$this->table.
489 ' WHERE '.$this->parentField.'="'.addslashes($uid).'"'.
490 $this->clause;
491 $res = mysql(TYPO3_db, $query);
492 $row=mysql_fetch_row($res);
493 return $row[0];
494 } else {
495 $res = $this->getDataInit($uid);
496 return $this->getDataCount($res);
497 }
498 }
499
500 /**
501 * Adds a fieldname to the internal array ->fieldArray
502 *
503 * @param string Field name to
504 * @param boolean If set, the fieldname will be set no matter what. Otherwise the field name must either be found as key in $TCA['pages']['columns'] or in the list ->defaultList
505 * @return void
506 */
507 function addField($field,$noCheck=0) {
508 global $TCA;
509 if ($noCheck || is_array($TCA[$this->table]['columns'][$field]) || t3lib_div::inList($this->defaultList,$field)) {
510 $this->fieldArray[]=$field;
511 }
512 }
513
514 /**
515 * Returns true/false if the next level for $id should be expanded - based on data in $this->stored[][] and ->expandAll flag.
516 * Extending parent function
517 *
518 * @param integer record id/key
519 * @return boolean
520 * @access private
521 * @see t3lib_pageTree::expandNext()
522 */
523 function expandNext($id) {
524 return ($this->stored[$this->bank][$id] || $this->expandAll)? 1 : 0;
525 }
526
527 /**
528 * Saves the content of ->stored (keeps track of expanded positions in the tree)
529 * $this->treeName will be used as key for BE_USER->uc[] to store it in
530 *
531 * @return void
532 */
533 function savePosition() {
534 $this->BE_USER->uc[$this->treeName] = serialize($this->stored);
535 $this->BE_USER->writeUC();
536 }
537
538
539
540 /******************************
541 *
542 * functions that might be overwritten by extended classes
543 *
544 ********************************/
545
546 /**
547 * @param [type] $uid: ...
548 * @return [type] ...
549 */
550 function getRootRecord($uid) {
551 return array( 'title'=>$this->title, 'uid'=>0 );
552 }
553
554 /**
555 * [Describe function...]
556 *
557 * @param [type] $rec: ...
558 * @return [type] ...
559 */
560 function getRootIcon($rec) {
561 return $this->wrapIcon('<img src="'.$this->backPath.'gfx/i/_icon_website.gif" width="18" height="16" align="top" alt="" />',$rec);
562 }
563
564 /**
565 * [Describe function...]
566 *
567 * @param [type] $uid: ...
568 * @return [type] ...
569 */
570 function getRecord($uid) {
571 if($this->table) {
572 return t3lib_befunc::getRecord($this->table,$uid);
573 } else {
574 return $this->data[$uid];
575 }
576 }
577
578 /**
579 * [Describe function...]
580 *
581 * @param [type] $v: ...
582 * @return [type] ...
583 */
584 function getId($v) {
585 return $v['uid'];
586 }
587
588 /**
589 * [Describe function...]
590 *
591 * @param [type] $v: ...
592 * @return [type] ...
593 */
594 function getJumpToParm($v) {
595 return "'".$this->getId($v)."'";
596 }
597
598 /**
599 * [Describe function...]
600 *
601 * @param [type] $$row: ...
602 * @return [type] ...
603 */
604 function getIcon(&$row) {
605 if ($this->iconPath && $this->iconName) {
606 return '<img src="'.$this->iconPath.$this->iconName.'" width="18" height="16" align="top" alt="" />';
607 } else {
608 // rene[290903]: removed $this->wrapIcon() here, I don't think it have some side effects
609 return '<img src="'.$this->backPath.t3lib_iconWorks::getIcon($this->table,$row).'" width="18" height="16" align="top" alt="" />';
610 }
611 }
612
613 /**
614 * [Describe function...]
615 *
616 * @param [type] $$row: ...
617 * @return [type] ...
618 */
619 function getTitleStr(&$row) {
620 $title = (!strcmp(trim($row['title']),'')) ? '<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>' : htmlspecialchars($row['title']);
621 return $title;
622 }
623
624 /**
625 * [Describe function...]
626 *
627 * @param [type] $$row: ...
628 * @return [type] ...
629 */
630 function getTitleAttrib(&$row) {
631 return $row['title'];
632 }
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647 /********************************
648 *
649 * data handling
650 * works with records and arrays
651 *
652 ********************************/
653
654 /**
655 * fetches the data for the tree
656 *
657 * @param integer item id for which to select subitems.
658 * @param integer Max depth (recursivity limit)
659 * @param string HTML-code prefix for recursive calls.
660 * @param string ? (internal)
661 * @return integer The count of pages on the level
662 */
663 function getTree($uid, $depth=999, $depthData='',$blankLineCode='') {
664 // Buffer for id hierarchy is reset:
665 $this->buffer_idH=array();
666
667 // Init vars
668 $depth=intval($depth);
669 $HTML='';
670 $a=0;
671
672 $res = $this->getDataInit($uid);
673 $c = $this->getDataCount($res);
674
675 // Traverse the records:
676 while ($row = $this->getDataNext($res)) {
677 # IF $row is NOT an array then this will go into some eternal loop which consumes huge amounts of memory - not good.
678 # PROBABLY this could happend anyways if the input array contains the same id many times. However this is not cleared yet - investigate this!
679 if (is_array($row)) {
680 $a++;
681
682 $newID =$row['uid'];
683 $this->tree[]=array(); // Reserve space.
684 end($this->tree);
685 $treeKey = key($this->tree); // Get the key for this space
686 $LN = ($a==$c)?'blank':'line';
687
688 // If records should be accumulated, do so
689 if ($this->setRecs) {
690 $this->recs[$row['uid']] = $row;
691 }
692
693 // accumulate the id of the page in the internal arrays
694 $this->ids[]=$idH[$row['uid']]['uid']=$row['uid'];
695 $this->ids_hierarchy[$depth][]=$row['uid'];
696
697 // Make a recursive call to the next level
698 if ($depth>1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
699 $nextCount=$this->getTree(
700 $newID,
701 $depth-1,
702 $this->makeHTML?$depthData.'<img src="'.$this->backPath.'t3lib/gfx/ol/'.$LN.'.gif" width="18" height="16" align="top" alt="" />':'',
703 $blankLineCode.','.$LN
704 );
705 if (count($this->buffer_idH)) $idH[$row['uid']]['subrow']=$this->buffer_idH;
706 $exp=1; // Set "did expanded" flag
707 } else {
708 $nextCount=$this->getCount($newID);
709 $exp=0; // Clear "did expanded" flag
710 }
711 // Set HTML-icons, if any:
712 if ($this->makeHTML) {
713 $HTML = $depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
714 $HTML.=$this->wrapStop($this->wrapIcon($this->getIcon($row),$row),$row);
715 }
716
717 // Finally, add the row/HTML content to the ->tree array in the reserved key.
718 $this->tree[$treeKey] = Array(
719 'row'=>$row,
720 'HTML'=>$HTML,
721 'invertedDepth'=>$depth,
722 'blankLineCode'=>$blankLineCode
723 );
724 }
725 }
726
727 $this->getDataFree($res);
728 $this->buffer_idH=$idH;
729 return $c;
730 }
731
732 /**
733 * getting the tree data: init
734 *
735 * @param integer parent item id
736 * @return mixed data handle
737 */
738 function getDataInit($parentId) {
739 if ($this->table) {
740 $query = 'SELECT '.implode($this->fieldArray,',').' FROM '.$this->table.
741 ' WHERE '.$this->parentField.'="'.addslashes($parentId).'"'.
742 $this->clause;
743 $res = mysql(TYPO3_db, $query);
744 if (mysql_error()) {
745 echo mysql_error();
746 debug($query);
747 }
748 return $res;
749 } else {
750 if (!is_array($this->dataLookup[$parentId]['subLevel'])) {
751 $parentId = -1;
752 } else {
753 reset($this->dataLookup[$parentId]['subLevel']);
754 }
755 return $parentId;
756 }
757 }
758
759 /**
760 * getting the tree data: count
761 *
762 * @param mixed data handle
763 * @return integer number of items
764 */
765 function getDataCount($res) {
766 if ($this->table) {
767 $c=mysql_num_rows($res);
768 return $c;
769 } else {
770 return count($this->dataLookup[$res]['subLevel']);
771 }
772 }
773
774 /**
775 * getting the tree data: next entry
776 *
777 * @param mixed data handle
778 * @return array item data array
779 */
780 function getDataNext($res){
781 if ($this->table) {
782 return @mysql_fetch_assoc($res);
783 } else {
784 if ($res<0) {
785 $row=FALSE;
786 } else {
787 list(,$row) = each($this->dataLookup[$res]['subLevel']);
788 }
789 return $row;
790 }
791 }
792
793 /**
794 * getting the tree data: frees data handle
795 *
796 * @param mixed data handle
797 * @return void
798 */
799 function getDataFree($res){
800 if ($this->table) {
801 mysql_free_result($res);
802 } else {
803 # unset();
804 }
805 }
806
807 /**
808 * [Describe function...]
809 *
810 * @param [type] $$dataArr: ...
811 * @param [type] $traverse: ...
812 * @param [type] $pid: ...
813 * @return [type] ...
814 */
815 function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0) {
816
817 if (!$traverse) {
818 $this->data = &$dataArr;
819 $this->dataLookup=array();
820 // add root
821 $this->dataLookup[0]['subLevel']=&$dataArr;
822 }
823
824 foreach($dataArr as $uid => $val) {
825
826 $dataArr[$uid]['uid']=$uid;
827 $dataArr[$uid]['pid']=$pid;
828
829 // gives quick access to id's
830 $this->dataLookup[$uid] = &$dataArr[$uid];
831
832 if (is_array($val['subLevel'])) {
833 $this->setDataFromArray($dataArr[$uid]['subLevel'],TRUE,$uid);
834 }
835 }
836 }
837
838
839 /*
840 array(
841 [id1] => array(
842 'title'=>'title...',
843 'id' => 'id1',
844 'icon' => 'icon ref, relative to typo3/ folder...'
845 ),
846 [id2] => array(
847 'title'=>'title...',
848 'id' => 'id2',
849 'icon' => 'icon ref, relative to typo3/ folder...'
850 ),
851 [id3] => array(
852 'title'=>'title...',
853 'id' => 'id3',
854 'icon' => 'icon ref, relative to typo3/ folder...'
855 'subLevel' => array(
856 [id3_asdf#1] => array(
857 'title'=>'title...',
858 'id' => 'asdf#1',
859 'icon' => 'icon ref, relative to typo3/ folder...'
860 ),
861 [5] => array(
862 'title'=>'title...',
863 'id' => 'id...',
864 'icon' => 'icon ref, relative to typo3/ folder...'
865 ),
866 [6] => array(
867 'title'=>'title...',
868 'id' => 'id...',
869 'icon' => 'icon ref, relative to typo3/ folder...'
870 ),
871 )
872 ),
873 )
874 */
875
876
877 }
878
879
880 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']) {
881 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_treeview.php']);
882 }
883 ?>