[TYPO3-ect] recursive pid function for tx_div

Steve Ryan stever at syntithenai.com
Mon Aug 13 05:11:52 CEST 2007


Something that is useful in pibase is recursive pid search

.....
something needs to be done with finding the cObj if this function is
deemed to belong in tx_div statically....

useful?



    // return an array of pids
    function getPidListRecursive($pidList,$recursive) {
	    // ensure array format
	    if (!is_array($pidList)) {
		    if (strlen(trim($pidList))==0) return array();
		    $pidList=explode(',',$pidList);
	    }
	    // dump on empty pidlist
	    if (count($pidList)==0) return $pidList;
	    // dump when recursion reaches 0
	    if ($recursive==0) {
		    return $pidList;
	    } else {
		// prep unique array
		$unique=array();
		foreach ($pidList as $thispid) {
			$unique[$thispid]=$thispid;	
		}
		// get next level of pids
		$pidQuery='(pid='.implode(' or pid=',$pidList).')';
		$cObj=$this->findCObject();
		$query=$pidQuery.$cObj->enableFields('pages');
	
$res=$GLOBALS['TYPO3_DB']->exec_SELECTquery('uid,pid','pages',$query,'','','');
		while ($row=$GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$unique[$row['uid']]=$row['uid'];
		}
		return $this->getPidListRecursive(array_keys($unique),$recursive-1);
	    }
    }


More information about the TYPO3-team-extension-coordination mailing list