[TYPO3-dev] Views in TYPO3 database

Rik Willems rik at actiview.nl
Tue Mar 8 17:23:33 CET 2011


Op 7-3-2011 17:11, Ernesto Baschny [cron IT] schreef:
>
>> One other though was to hook/xclass the class.db_list.php or
>> class.db_list_extra.php to create the lists I wish in stead of default
>> lists.
>
> I would go with this approach, as it is probably most easy to understand.

So that is the road I choose to take. I used a hook inside 
class.db_list.inc to create a custom select query.

Each advert record has a true m2m relation with pages. So, each advert 
has a pid where it was placed, and an extra placement on 0,1,x 
additional pages. The code below makes that the lists in TYPO3 show all 
records.

Thanks for you insights!


	function makeQueryArray_post(&$queryParts, $pObj, $table, $id, 
$addWhere, $fieldList, $_params) {

		if ( $table == 'tx_ext_adverts' ) {
		
			$uids = $this->getUids($id);
			if ( count($uids) ) $uidList =  ' OR uid IN ('.implode(',', $uids).')';
			
			$queryParts['WHERE'] =
				'(' . $pObj->pidSelect . ' ' . $uidList . ')' .
				$_params['pC'].
				t3lib_BEfunc::deleteClause($table).
				t3lib_BEfunc::versioningPlaceholderClause($table).
				' '.$addWhere.
				' '.$_params['search'];
				
			#print_r($queryParts);
			#exit;
		}
	}

	
	/**
	 * Returns an array with all Uids that should be read
	 *
	 * @param int $uid - UID to be added and recursed
	 * @param array $array - Array of uids
	 * @return array
	 */
	protected function getUids($uid, &$array = null) {
		if (null == $array) $array = array();
		
		$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('uid_local AS uid', 
'tx_ext_adverts_pages_mm', 'uid_foreign = '.$uid);
				
		while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
			$array[] = $row['uid'];
			$this->getRecursiveUids($row['uid'], $array);
		}
		
		return $array;
	}




More information about the TYPO3-dev mailing list