Extension Development, add a startingpoint
From TYPO3Wiki
<< Back to Extension Development << Back to Developer manuals page
How to add a startingpoint
How to add a startingpoint (basic method)
This code is quite limited and supports only 1 entry in the starting point selection
<PHP> :# Get Sysfolder from tt_content table if (strstr($this->cObj->currentRecord,"tt_content")) { $conf["pidList"] = $this->cObj->data["pages"]; } # Get number of records: $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tx_myext_table.*','tx_myext_table','pid='.intval($conf["pidList"])); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $records[]=$row; }
How to add a startingpoint (advanced method)
The following method deals with several starting point entries selected in the list and the value of the recursive parameter
<PHP> ://Retreiving startingpoints list $startingPoints = $this->cObj->data["pages"]; //Retreiving recursivity setting $recursive = $this->cObj->data["recursive"]; //handling void recursive configuration special case if($this->cObj->data["recursive"]=="")$recursive = 0; //establishing the list of all pids to be looked for records according to recursivity settings $selectedPids = ""; $startingPointsArray = explode(",",$startingPoints); foreach($startingPointsArray as $index => $root) $selectedPids .= (($index == 0)?"":",").getRecursiveUidList($root,$recursive); // Get ressource records: $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery ( "*", "tx_myext_table", "pid IN (".$GLOBALS['TYPO3_DB']->cleanIntList($selectedPids).") AND my_criteria=".$criteria); //displaying retreived records while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)){ $content.= "found record uid=".$row['uid']; }
This is the function which retreives recursively all the pages uids below a given pid. It returns the complete list of uids in the branch, with the starting pid included as well.
EDIT : It should be possible to replace this function by the standard funtion tslib_pibase.pi_getPidList($pid_list, $recursive = 0) which appears to have the same parameters/behavior.
<PHP> :function getRecursiveUidList($parentUid,$depth){ if($depth != -1) $depth = $depth-1; //decreasing depth # Get ressource records: $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery ( "uid", "pages", "pid IN (".$GLOBALS['TYPO3_DB']->cleanIntList($parentUid).") AND deleted=0 " ); if($depth > 0){ while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { $parentUid .= ",".getRecursiveUidList($row['uid'],$depth); } } return $parentUid; }
You can do like this if you want to hardcode the sql statement and avoid recursion and gain some speed:
<PHP> :$this->andWhere('uid' => '666'); $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( '*,V.title VT,V.uid VU,S.title ST,S.uid SU,S1.uid S1U, S1.title S1T, S2.uid S2U, S2.title S2T', 'pages WA INNER JOIN pages V ON WA.pid=V.uid INNER JOIN pages S ON V.pid=S.uid INNER JOIN pages S1 ON S.pid=S1.uid INNER JOIN pages S2 ON S1.pid=S2.uid', 'S2.uid='..$GLOBALS['TYPO3_DB']->cleanIntList($parentUid).' AND WA.deleted=0 AND WA.hidden=0'.(count($this->andWhere)?' AND '.implode(' AND ',$this->andWhere):'').(count($this->orWhere)?' AND ('.implode(' OR ',$this->orWhere).')':''), 'S1.uid','WA.pid','');
--Chibox 15:38, 12 February 2008 (CET)
