2 /***************************************************************
5 * (c) 1999-2008 Kasper Skaarhoj (kasperYYYY@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
28 * Contains base class for creating a browsable array/page/folder tree in HTML
31 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
33 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
34 * @coauthor René Fritz <r.fritz@colorcube.de>
37 * [CLASS/FUNCTION INDEX of SCRIPT]
41 * 115: class t3lib_treeView
42 * 270: function init($clause='', $orderByFields='')
43 * 301: function setTreeName($treeName='')
44 * 315: function addField($field,$noCheck=0)
45 * 329: function reset()
48 * 349: function getBrowsableTree()
49 * 412: function printTree($treeArr='')
51 * SECTION: rendering parts
52 * 467: function PMicon($row,$a,$c,$nextCount,$exp)
53 * 489: function PM_ATagWrap($icon,$cmd,$bMark='')
54 * 511: function wrapTitle($title,$row,$bank=0)
55 * 524: function wrapIcon($icon,$row)
56 * 535: function addTagAttributes($icon,$attr)
57 * 547: function wrapStop($str,$row)
59 * SECTION: tree handling
60 * 575: function expandNext($id)
61 * 585: function initializePositionSaving()
62 * 612: function savePosition()
64 * SECTION: Functions that might be overwritten by extended classes
65 * 641: function getRootIcon($rec)
66 * 654: function getIcon($row)
67 * 673: function getTitleStr($row,$titleLen=30)
68 * 685: function getTitleAttrib($row)
69 * 695: function getId($row)
70 * 705: function getJumpToParam($row)
72 * SECTION: tree data buidling
73 * 739: function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='')
75 * SECTION: Data handling
76 * 839: function getCount($uid)
77 * 865: function getRootRecord($uid)
78 * 878: function getRecord($uid)
79 * 898: function getDataInit($parentId,$subCSSclass='')
80 * 929: function getDataCount(&$res)
81 * 947: function getDataNext(&$res,$subCSSclass='')
82 * 986: function getDataFree(&$res)
83 * 1006: function setDataFromArray(&$dataArr,$traverse=FALSE,$pid=0)
84 * 1035: function setDataFromTreeArray(&$treeArr, &$treeLookupArr)
87 * (This index is automatically created/updated by the extension "extdeveval")
101 require_once (PATH_t3lib
.'class.t3lib_iconworks.php');
102 require_once (PATH_t3lib
.'class.t3lib_befunc.php');
103 require_once (PATH_t3lib
.'class.t3lib_div.php');
107 * Base class for creating a browsable array/page/folder tree in HTML
109 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
110 * @coauthor René Fritz <r.fritz@colorcube.de>
113 * @see t3lib_browsetree, t3lib_pagetree, t3lib_foldertree
115 class t3lib_treeView
{
118 var $expandFirst=0; // If set, the first element in the tree is always expanded.
119 var $expandAll=0; // If set, then ALL items will be expanded, regardless of stored settings.
120 var $thisScript=''; // Holds the current script to reload to.
121 var $titleAttrib = 'title'; // Which HTML attribute to use: alt/title. See init().
122 var $ext_IconMode = false
; // If true, no context menu is rendered on icons. If set to "titlelink" the icon is linked as the title is.
123 var $addSelfId = 0; // If set, the id of the mounts will be added to the internal ids array
124 var $title='no title'; // Used if the tree is made of records (not folders for ex.)
125 var $showDefaultTitleAttribute = FALSE
; // If true, a default title attribute showing the UID of the record is shown. This cannot be enabled by default because it will destroy many applications where another title attribute is in fact applied later.
126 var $highlightPagesWithVersions = TRUE
; // If true, pages containing child records which has versions will be highlighted in yellow. This might be too expensive in terms of processing power.
129 * Needs to be initialized with $GLOBALS['BE_USER']
130 * Done by default in init()
132 * @var t3lib_beUserAuth
137 * Needs to be initialized with e.g. $GLOBALS['WEBMOUNTS']
138 * Default setting in init() is 0 => 0
139 * The keys are mount-ids (can be anything basically) and the values are the ID of the root element (COULD be zero or anything else. For pages that would be the uid of the page, zero for the pagetree root.)
146 * Database table to get the tree data from.
147 * Leave blank if data comes from an array.
152 * Defines the field of $table which is the parent id field (like pid for table pages).
154 var $parentField='pid';
157 * WHERE clause used for selecting records for the tree. Is set by function init.
158 * Only makes sense when $this->table is set.
164 * Field for ORDER BY. Is set by function init.
165 * Only makes sense when $this->table is set.
168 var $orderByFields='';
171 * Default set of fields selected from the tree table.
172 * Make SURE that these fields names listed herein are actually possible to select from $this->table (if that variable is set to a TCA table name)
175 var $fieldArray = Array('uid','title');
178 * List of other fields which are ALLOWED to set (here, based on the "pages" table!)
181 var $defaultList = 'uid,pid,tstamp,sorting,deleted,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,crdate,cruser_id';
185 * Unique name for the tree.
186 * Used as key for storing the tree into the BE users settings.
187 * Used as key to pass parameters in links.
188 * MUST NOT contain underscore chars.
194 * A prefix for table cell id's which will be wrapped around an item.
195 * Can be used for highlighting by JavaScript.
196 * Needs to be unique if multiple trees are on one HTML page.
199 var $domIdPrefix = 'row';
202 * Back path for icons
213 * Icon file name for item icons.
215 var $iconName = 'default.gif';
218 * If true, HTML code is also accumulated in ->tree array during rendering of the tree.
219 * If 2, then also the icon prefix code (depthData) is stored
224 * If true, records as selected will be stored internally in the ->recs array
229 * Sets the associative array key which identifies a new sublevel if arrays are used for trees.
230 * This value has formerly been "subLevel" and "--sublevel--"
232 var $subLevelID = '_SUB_LEVEL';
241 var $ids = Array(); // one-dim array of the uid's selected.
242 var $ids_hierarchy = array(); // The hierarchy of element uids
243 var $orig_ids_hierarchy = array(); // The hierarchy of versioned element uids
244 var $buffer_idH = array(); // Temporary, internal array
247 var $specUIDmap=array(); // Special UIDs for folders (integer-hashes of paths)
250 var $data = false
; // Holds the input data array
251 var $dataLookup = false
; // Holds an index with references to the data array.
254 var $tree = Array(); // Tree is accumulated in this variable
255 var $stored = array(); // Holds (session stored) information about which items in the tree are unfolded and which are not.
256 var $bank=0; // Points to the current mountpoint key
257 var $recs = array(); // Accumulates the displayed records.
266 * Initialize the tree class. Needs to be overwritten
267 * Will set ->fieldsArray, ->backPath and ->clause
269 * @param string record WHERE clause
270 * @param string record ORDER BY field
273 function init($clause='', $orderByFields='') {
274 $this->BE_USER
= $GLOBALS['BE_USER']; // Setting BE_USER by default
275 $this->titleAttrib
= 'title'; // Setting title attribute to use.
276 $this->backPath
= $GLOBALS['BACK_PATH']; // Setting backpath.
278 if ($clause) $this->clause
= $clause; // Setting clause
279 if ($orderByFields) $this->orderByFields
= $orderByFields;
281 if (!is_array($this->MOUNTS
)) {
282 $this->MOUNTS
= array(0 => 0); // dummy
285 $this->setTreeName();
288 t3lib_div
::loadTCA($this->table
);
291 // setting this to false disables the use of array-trees by default
293 $this->dataLookup
= false
;
298 * Sets the tree name which is used to identify the tree
299 * Used for JavaScript and other things
301 * @param string Default is the table name. Underscores are stripped.
304 function setTreeName($treeName='') {
305 $this->treeName
= $treeName ?
$treeName : $this->treeName
;
306 $this->treeName
= $this->treeName ?
$this->treeName
: $this->table
;
307 $this->treeName
= str_replace('_','',$this->treeName
);
312 * Adds a fieldname to the internal array ->fieldArray
314 * @param string Field name to
315 * @param boolean If set, the fieldname will be set no matter what. Otherwise the field name must either be found as key in $TCA[$table]['columns'] or in the list ->defaultList
318 function addField($field,$noCheck=0) {
320 if ($noCheck ||
is_array($TCA[$this->table
]['columns'][$field]) || t3lib_div
::inList($this->defaultList
,$field)) {
321 $this->fieldArray
[]=$field;
328 * Resets the tree, recs, ids, ids_hierarchy and orig_ids_hierarchy internal variables. Use it if you need it.
333 $this->tree
= array();
334 $this->recs
= array();
335 $this->ids
= array();
336 $this->ids_hierarchy
= array();
337 $this->orig_ids_hierarchy
= array();
341 /*******************************************
345 *******************************************/
348 * Will create and return the HTML code for a browsable tree
349 * Is based on the mounts found in the internal array ->MOUNTS (set in the constructor)
351 * @return string HTML code for the browsable tree
353 function getBrowsableTree() {
355 // Get stored tree structure AND updating it if needed according to incoming PM GET var.
356 $this->initializePositionSaving();
359 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
363 foreach($this->MOUNTS
as $idx => $uid) {
367 $isOpen = $this->stored
[$idx][$uid] ||
$this->expandFirst
;
369 // Save ids while resetting everything else.
370 $curIds = $this->ids
;
372 $this->ids
= $curIds;
374 // Set PM icon for root of mount:
375 $cmd=$this->bank
.'_'.($isOpen?
"0_":"1_").$uid.'_'.$this->treeName
;
376 $icon='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.($isOpen?
'minus':'plus').'only.gif','width="18" height="16"').' alt="" />';
377 $firstHtml= $this->PM_ATagWrap($icon,$cmd);
379 // Preparing rootRec for the mount
381 $rootRec = $this->getRecord($uid);
382 $firstHtml.=$this->getIcon($rootRec);
384 // Artificial record for the tree root, id=0
385 $rootRec = $this->getRootRecord($uid);
386 $firstHtml.=$this->getRootIcon($rootRec);
389 if (is_array($rootRec)) {
390 $uid = $rootRec['uid']; // In case it was swapped inside getRecord due to workspaces.
392 // Add the root of the mount to ->tree
393 $this->tree
[]=array('HTML'=>$firstHtml, 'row'=>$rootRec, 'bank'=>$this->bank
);
395 // If the mount is expanded, go down:
398 $depthD='<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/blank.gif','width="18" height="16"').' alt="" />';
399 if ($this->addSelfId
) $this->ids
[] = $uid;
400 $this->getTree($uid,999,$depthD,'',$rootRec['_SUBCSSCLASS']);
404 $treeArr=array_merge($treeArr,$this->tree
);
407 return $this->printTree($treeArr);
411 * Compiles the HTML code for displaying the structure found inside the ->tree array
413 * @param array "tree-array" - if blank string, the internal ->tree array is used.
414 * @return string The HTML code for the tree
416 function printTree($treeArr='') {
417 $titleLen=intval($this->BE_USER
->uc
['titleLen']);
418 if (!is_array($treeArr)) $treeArr=$this->tree
;
421 // put a table around it with IDs to access the rows from JS
422 // not a problem if you don't need it
423 // 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.
427 TYPO3 tree structure.
429 <table cellpadding="0" cellspacing="0" border="0" id="typo3-tree">';
431 foreach($treeArr as $k => $v) {
432 $idAttr = htmlspecialchars($this->domIdPrefix
.$this->getId($v['row']).'_'.$v['bank']);
436 <td id="'.$idAttr.'"'.
437 ($v['row']['_CSSCLASS'] ?
' class="'.$v['row']['_CSSCLASS'].'"' : '').'>'.
439 $this->wrapTitle($this->getTitleStr($v['row'],$titleLen),$v['row'],$v['bank']).
451 /*******************************************
455 *******************************************/
460 * Generate the plus/minus icon for the browsable tree.
462 * @param array record for the entry
463 * @param integer The current entry number
464 * @param integer The total number of entries. If equal to $a, a "bottom" element is returned.
465 * @param integer The number of sub-elements to the current element.
466 * @param boolean The element was expanded to render subelements if this flag is set.
467 * @return string Image tag with the plus/minus icon.
469 * @see t3lib_pageTree::PMicon()
471 function PMicon($row,$a,$c,$nextCount,$exp) {
472 $PM = $nextCount ?
($exp?
'minus':'plus') : 'join';
473 $BTM = ($a==$c)?
'bottom':'';
474 $icon = '<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$PM.$BTM.'.gif','width="18" height="16"').' alt="" />';
477 $cmd=$this->bank
.'_'.($exp?
'0_':'1_').$row['uid'].'_'.$this->treeName
;
478 $bMark=($this->bank
.'_'.$row['uid']);
479 $icon = $this->PM_ATagWrap($icon,$cmd,$bMark);
485 * Wrap the plus/minus icon in a link
487 * @param string HTML string to wrap, probably an image tag.
488 * @param string Command for 'PM' get var
489 * @param boolean If set, the link will have a anchor point (=$bMark) and a name attribute (=$bMark)
490 * @return string Link-wrapped input string
493 function PM_ATagWrap($icon,$cmd,$bMark='') {
494 if ($this->thisScript
) {
496 $anchor = '#'.$bMark;
497 $name=' name="'.$bMark.'"';
499 $aUrl = $this->thisScript
.'?PM='.$cmd.$anchor;
500 return '<a href="'.htmlspecialchars($aUrl).'"'.$name.'>'.$icon.'</a>';
507 * Wrapping $title in a-tags.
509 * @param string Title string
510 * @param string Item record
511 * @param integer Bank pointer (which mount point number)
515 function wrapTitle($title,$row,$bank=0) {
516 $aOnClick = 'return jumpTo(\''.$this->getJumpToParam($row).'\',this,\''.$this->domIdPrefix
.$this->getId($row).'\','.$bank.');';
517 return '<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.$title.'</a>';
521 * Wrapping the image tag, $icon, for the row, $row (except for mount points)
523 * @param string The image tag for the icon
524 * @param array The row for the current element
525 * @return string The processed icon input value.
528 function wrapIcon($icon,$row) {
533 * Adds attributes to image tag.
535 * @param string Icon image tag
536 * @param string Attributes to add, eg. ' border="0"'
537 * @return string Image tag, modified with $attr attributes added.
539 function addTagAttributes($icon,$attr) {
540 return ereg_replace(' ?\/?>$','',$icon).' '.$attr.' />';
544 * Adds a red "+" to the input string, $str, if the field "php_tree_stop" in the $row (pages) is set
546 * @param string Input string, like a page title for the tree
547 * @param array record row with "php_tree_stop" field
548 * @return string Modified string
551 function wrapStop($str,$row) {
552 if ($row['php_tree_stop']) {
553 $str.='<span class="typo3-red">+ </span>';
563 /*******************************************
567 *******************************************/
571 * Returns true/false if the next level for $id should be expanded - based on data in $this->stored[][] and ->expandAll flag.
572 * Extending parent function
574 * @param integer record id/key
577 * @see t3lib_pageTree::expandNext()
579 function expandNext($id) {
580 return ($this->stored
[$this->bank
][$id] ||
$this->expandAll
)?
1 : 0;
584 * Get stored tree structure AND updating it if needed according to incoming PM GET var.
589 function initializePositionSaving() {
590 // Get stored tree structure:
591 $this->stored
=unserialize($this->BE_USER
->uc
['browseTrees'][$this->treeName
]);
594 // (If an plus/minus icon has been clicked, the PM GET var is sent and we must update the stored positions in the tree):
595 $PM = explode('_',t3lib_div
::_GP('PM')); // 0: mount key, 1: set/clear boolean, 2: item ID (cannot contain "_"), 3: treeName
596 if (count($PM)==4 && $PM[3]==$this->treeName
) {
597 if (isset($this->MOUNTS
[$PM[0]])) {
599 $this->stored
[$PM[0]][$PM[2]]=1;
600 $this->savePosition();
602 unset($this->stored
[$PM[0]][$PM[2]]);
603 $this->savePosition();
610 * Saves the content of ->stored (keeps track of expanded positions in the tree)
611 * $this->treeName will be used as key for BE_USER->uc[] to store it in
616 function savePosition() {
617 $this->BE_USER
->uc
['browseTrees'][$this->treeName
] = serialize($this->stored
);
618 $this->BE_USER
->writeUC();
633 /******************************
635 * Functions that might be overwritten by extended classes
637 ********************************/
640 * Returns the root icon for a tree/mountpoint (defaults to the globe)
642 * @param array Record for root.
643 * @return string Icon image tag.
645 function getRootIcon($rec) {
646 return $this->wrapIcon('<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/i/_icon_website.gif','width="18" height="16"').' alt="" />',$rec);
652 * Get icon for the row.
653 * If $this->iconPath and $this->iconName is set, try to get icon based on those values.
655 * @param array Item row.
656 * @return string Image tag.
658 function getIcon($row) {
659 if ($this->iconPath
&& $this->iconName
) {
660 $icon = '<img'.t3lib_iconWorks
::skinImg('',$this->iconPath
.$this->iconName
,'width="18" height="16"').' alt=""'.($this->showDefaultTitleAttribute ?
' title="UID: '.$row['uid'].'"':'').' />';
662 $icon = t3lib_iconWorks
::getIconImage($this->table
,$row,$this->backPath
,'align="top" class="c-recIcon"'.($this->showDefaultTitleAttribute ?
' title="UID: '.$row['uid'].'"':''));
665 return $this->wrapIcon($icon,$row);
670 * Returns the title for the input record. If blank, a "no title" label (localized) will be returned.
671 * Do NOT htmlspecialchar the string from this function - has already been done.
673 * @param array The input row array (where the key "title" is used for the title)
674 * @param integer Title length (30)
675 * @return string The title.
677 function getTitleStr($row,$titleLen=30) {
678 if ($this->ext_showNavTitle
&& strlen(trim($row['nav_title'])) > 0) {
679 $title = '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_tca.xml:title',1).' '.htmlspecialchars(trim($row['title'])).'">'.htmlspecialchars(t3lib_div
::fixed_lgd_cs($row['nav_title'],$titleLen)).'</span>';
681 $title = htmlspecialchars(t3lib_div
::fixed_lgd_cs($row['title'],$titleLen));
682 if (strlen(trim($row['nav_title'])) > 0) {
683 $title = '<span title="'.$GLOBALS['LANG']->sL('LLL:EXT:cms/locallang_tca.xml:pages.nav_title',1).' '.htmlspecialchars(trim($row['nav_title'])).'">'.$title.'</span>';
685 $title = (strlen(trim($row['title'])) == 0) ?
'<em>['.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.no_title',1).']</em>' : $title;
692 * Returns the value for the image "title" attribute
694 * @param array The input row array (where the key "title" is used for the title)
695 * @return string The attribute value (is htmlspecialchared() already)
698 function getTitleAttrib($row) {
699 return htmlspecialchars($row['title']);
703 * Returns the id from the record (typ. uid)
705 * @param array Record array
706 * @return integer The "uid" field value.
708 function getId($row) {
713 * Returns jump-url parameter value.
715 * @param array The record array.
716 * @return string The jump-url parameter.
718 function getJumpToParam($row) {
719 return $this->getId($row);
736 /********************************
740 ********************************/
743 * Fetches the data for the tree
745 * @param integer item id for which to select subitems (parent id)
746 * @param integer Max depth (recursivity limit)
747 * @param string HTML-code prefix for recursive calls.
748 * @param string ? (internal)
749 * @param string CSS class to use for <td> sub-elements
750 * @return integer The count of items on the level
752 function getTree($uid, $depth=999, $depthData='',$blankLineCode='',$subCSSclass='') {
754 // Buffer for id hierarchy is reset:
755 $this->buffer_idH
=array();
758 $depth=intval($depth);
762 $res = $this->getDataInit($uid,$subCSSclass);
763 $c = $this->getDataCount($res);
764 $crazyRecursionLimiter = 999;
766 // Traverse the records:
767 while ($crazyRecursionLimiter>0 && $row = $this->getDataNext($res,$subCSSclass)) {
769 $crazyRecursionLimiter--;
771 $newID = $row['uid'];
774 t3lib_BEfunc
::typo3PrintError ('Endless recursion detected', 'TYPO3 has detected an error in the database. Please fix it manually (e.g. using phpMyAdmin) and change the UID of '.$this->table
.':0 to a new value.<br /><br />See <a href="http://bugs.typo3.org/view.php?id=3495" target="_blank">bugs.typo3.org/view.php?id=3495</a> to get more information about a possible cause.',0);
778 $this->tree
[]=array(); // Reserve space.
780 $treeKey = key($this->tree
); // Get the key for this space
781 $LN = ($a==$c)?
'blank':'line';
783 // If records should be accumulated, do so
784 if ($this->setRecs
) {
785 $this->recs
[$row['uid']] = $row;
788 // Accumulate the id of the element in the internal arrays
789 $this->ids
[] = $idH[$row['uid']]['uid'] = $row['uid'];
790 $this->ids_hierarchy
[$depth][] = $row['uid'];
791 $this->orig_ids_hierarchy
[$depth][] = $row['_ORIG_uid'] ?
$row['_ORIG_uid'] : $row['uid'];
793 // Make a recursive call to the next level
794 $HTML_depthData = $depthData.'<img'.t3lib_iconWorks
::skinImg($this->backPath
,'gfx/ol/'.$LN.'.gif','width="18" height="16"').' alt="" />';
795 if ($depth>1 && $this->expandNext($newID) && !$row['php_tree_stop']) {
796 $nextCount=$this->getTree(
799 $this->makeHTML ?
$HTML_depthData : '',
800 $blankLineCode.','.$LN,
803 if (count($this->buffer_idH
)) $idH[$row['uid']]['subrow']=$this->buffer_idH
;
804 $exp=1; // Set "did expand" flag
806 $nextCount=$this->getCount($newID);
807 $exp=0; // Clear "did expand" flag
810 // Set HTML-icons, if any:
811 if ($this->makeHTML
) {
812 $HTML = $depthData.$this->PMicon($row,$a,$c,$nextCount,$exp);
813 $HTML.=$this->wrapStop($this->getIcon($row),$row);
814 # $HTML.=$this->wrapStop($this->wrapIcon($this->getIcon($row),$row),$row);
817 // Finally, add the row/HTML content to the ->tree array in the reserved key.
818 $this->tree
[$treeKey] = Array(
821 'HTML_depthData' => $this->makeHTML
==2 ?
$HTML_depthData : '',
822 'invertedDepth'=>$depth,
823 'blankLineCode'=>$blankLineCode,
824 'bank' => $this->bank
828 $this->getDataFree($res);
829 $this->buffer_idH
=$idH;
844 /********************************
847 * Works with records and arrays
849 ********************************/
852 * Returns the number of records having the parent id, $uid
854 * @param integer id to count subitems for
858 function getCount($uid) {
859 if (is_array($this->data
)) {
860 $res = $this->getDataInit($uid);
861 return $this->getDataCount($res);
863 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
866 $this->parentField
.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($uid, $this->table
).
867 t3lib_BEfunc
::deleteClause($this->table
).
868 t3lib_BEfunc
::versioningPlaceholderClause($this->table
).
869 $this->clause
// whereClauseMightContainGroupOrderBy
871 $row = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
879 * Returns root record for uid (<=0)
881 * @param integer uid, <= 0 (normally, this does not matter)
882 * @return array Array with title/uid keys with values of $this->title/0 (zero)
884 function getRootRecord($uid) {
885 return array('title' => $this->title
, 'uid' => 0);
890 * Returns the record for a uid.
891 * For tables: Looks up the record in the database.
892 * For arrays: Returns the fake record for uid id.
894 * @param integer UID to look up
895 * @return array The record
897 function getRecord($uid) {
898 if (is_array($this->data
)) {
899 return $this->dataLookup
[$uid];
901 return t3lib_BEfunc
::getRecordWSOL($this->table
, $uid);
906 * Getting the tree data: Selecting/Initializing data pointer to items for a certain parent id.
907 * For tables: This will make a database query to select all children to "parent"
908 * For arrays: This will return key to the ->dataLookup array
910 * @param integer parent item id
911 * @param string Class for sub-elements.
912 * @return mixed data handle (Tables: An sql-resource, arrays: A parentId integer. -1 is returned if there were NO subLevel.)
915 function getDataInit($parentId,$subCSSclass='') {
916 if (is_array($this->data
)) {
917 if (!is_array($this->dataLookup
[$parentId][$this->subLevelID
])) {
920 reset($this->dataLookup
[$parentId][$this->subLevelID
]);
924 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
925 implode(',',$this->fieldArray
),
927 $this->parentField
.'='.$GLOBALS['TYPO3_DB']->fullQuoteStr($parentId, $this->table
).
928 t3lib_BEfunc
::deleteClause($this->table
).
929 t3lib_BEfunc
::versioningPlaceholderClause($this->table
).
930 $this->clause
, // whereClauseMightContainGroupOrderBy
939 * Getting the tree data: Counting elements in resource
941 * @param mixed data handle
942 * @return integer number of items
946 function getDataCount(&$res) {
947 if (is_array($this->data
)) {
948 return count($this->dataLookup
[$res][$this->subLevelID
]);
950 $c = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
956 * Getting the tree data: next entry
958 * @param mixed data handle
959 * @param string CSS class for sub elements (workspace related)
960 * @return array item data array OR FALSE if end of elements.
964 function getDataNext(&$res,$subCSSclass='') {
965 if (is_array($this->data
)) {
969 list(,$row) = each($this->dataLookup
[$res][$this->subLevelID
]);
971 // Passing on default <td> class for subelements:
972 if (is_array($row) && $subCSSclass!=='') {
973 $row['_CSSCLASS'] = $row['_SUBCSSCLASS'] = $subCSSclass;
978 while($row = @$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
979 t3lib_BEfunc
::workspaceOL($this->table
, $row, $this->BE_USER
->workspace
, TRUE
);
980 if (is_array($row)) break;
983 // Passing on default <td> class for subelements:
984 if (is_array($row) && $subCSSclass!=='') {
986 if ($this->table
==='pages' && $this->highlightPagesWithVersions
&& !isset($row['_CSSCLASS']) && count(t3lib_BEfunc
::countVersionsOfRecordsOnPage($this->BE_USER
->workspace
, $row['uid'], TRUE
))) {
987 $row['_CSSCLASS'] = 'ver-versions';
990 if (!isset($row['_CSSCLASS'])) $row['_CSSCLASS'] = $subCSSclass;
991 if (!isset($row['_SUBCSSCLASS'])) $row['_SUBCSSCLASS'] = $subCSSclass;
999 * Getting the tree data: frees data handle
1001 * @param mixed data handle
1005 function getDataFree(&$res) {
1006 if (!is_array($this->data
)) {
1007 $GLOBALS['TYPO3_DB']->sql_free_result($res);
1012 * Used to initialize class with an array to browse.
1013 * The array inputted will be traversed and an internal index for lookup is created.
1014 * The keys of the input array are perceived as "uid"s of records which means that keys GLOBALLY must be unique like uids are.
1015 * "uid" and "pid" "fakefields" are also set in each record.
1016 * All other fields are optional.
1018 * @param array The input array, see examples below in this script.
1019 * @param boolean Internal, for recursion.
1020 * @param integer Internal, for recursion.
1023 function setDataFromArray(&$dataArr,$traverse=FALSE
,$pid=0) {
1025 $this->data
= &$dataArr;
1026 $this->dataLookup
=array();
1028 $this->dataLookup
[0][$this->subLevelID
]=&$dataArr;
1031 foreach($dataArr as $uid => $val) {
1033 $dataArr[$uid]['uid']=$uid;
1034 $dataArr[$uid]['pid']=$pid;
1036 // gives quick access to id's
1037 $this->dataLookup
[$uid] = &$dataArr[$uid];
1039 if (is_array($val[$this->subLevelID
])) {
1040 $this->setDataFromArray($dataArr[$uid][$this->subLevelID
],TRUE
,$uid);
1046 * Sets the internal data arrays
1048 * @param array Content for $this->data
1049 * @param array Content for $this->dataLookup
1052 function setDataFromTreeArray(&$treeArr, &$treeLookupArr) {
1053 $this->data
= &$treeArr;
1054 $this->dataLookup
=&$treeLookupArr;
1061 'title'=>'title...',
1063 'icon' => 'icon ref, relative to typo3/ folder...'
1066 'title'=>'title...',
1068 'icon' => 'icon ref, relative to typo3/ folder...'
1071 'title'=>'title...',
1073 'icon' => 'icon ref, relative to typo3/ folder...'
1074 $this->subLevelID => array(
1075 [id3_asdf#1] => array(
1076 'title'=>'title...',
1078 'icon' => 'icon ref, relative to typo3/ folder...'
1081 'title'=>'title...',
1083 'icon' => 'icon ref, relative to typo3/ folder...'
1086 'title'=>'title...',
1088 'icon' => 'icon ref, relative to typo3/ folder...'
1097 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_treeview.php']) {
1098 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['t3lib/class.t3lib_treeview.php']);