[TYPO3-ect] USER/USER_INT Switch, WAS: The Big Plan

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Tue Aug 1 20:16:24 CEST 2006


JoH wrote:
> Recently I did some testing to speed up the rendering of pages containing
> tt_products plugin with various parts (BASKET, LIST, MINIBASKET ...)
> The major task was to optimize the way things are rendered from/into the
> cache and only prevent those elements form caching that really need dynamic
> output for each call and to get rid of set_no_cache().

[...]

>     20 = USER
>     20 {
>         userFunc = tx_cachetest_pi1->main
>         userFunc {
>             basket = COA_INT
>             basket {
[...]
>                 20 = USER
>                 20.userFunc = tx_cachetest_pi1->callTimeBasket
>             }
> 

Today I used this concept for an extension. It works fine.

plugin.tx_topsi = USER
plugin.tx_topsi {
	userFunc = tx_topsi_controllers_switch->main
	userFunc {
		list = USER_INT
		list {
			userFunc = tx_topsi_controllers_list->main

[...]


This is the switching controller. I have stolen 3 functions from pi_base to
 access a flexform field where I can select the controller to switch to.


require_once(t3lib_extMgm::extPath('topsi') .
'controllers/class.tx_topsi_controllers_list.php');
require_once(t3lib_extMgm::extPath('topsi') .
'controllers/class.tx_topsi_controllers_details.php');
[....]

class tx_topsi_controllers_switch{

	function main($content, $conf){
		$this->initPIflexForm();
		$key = $this->getFFvalue($this->cObj->data['pi_flexform'], 'controller',
'sGeneral');
		$return = $this->cObj->cObjGetSingle($conf['userFunc.'][$key],
$conf['userFunc.'][$key.'.']);
		return $return;
	}	
	
	/**
	 * Converts $this->cObj->data['pi_flexform'] from XML string to flexForm
array.
	 *
	 * @param	string		Field name to convert
	 * @return	void
	 */
	function initPIflexForm($field='pi_flexform')	{
			// Converting flexform data into array:
		if (!is_array($this->cObj->data[$field]) && $this->cObj->data[$field])	{
			$this->cObj->data[$field] = t3lib_div::xml2array($this->cObj->data[$field]);
			if (!is_array($this->cObj->data[$field]))	$this->cObj->data[$field]=array();
		}
	}

	/**
	 * Return value from somewhere inside a FlexForm structure
	 *
	 * @param	array		FlexForm data
	 * @param	string		Field name to extract. Can be given like
"test/el/2/test/el/field_templateObject" where each part will dig a level
deeper in the FlexForm data.
	 * @param	string		Sheet pointer, eg. "sDEF"
	 * @param	string		Language pointer, eg. "lDEF"
	 * @param	string		Value pointer, eg. "vDEF"
	 * @return	string		The content.
	 */
	function
getFFvalue($T3FlexForm_array,$fieldName,$sheet='sDEF',$lang='lDEF',$value='vDEF')
{
		$sheetArray = is_array($T3FlexForm_array) ?
$T3FlexForm_array['data'][$sheet][$lang] : '';
		if (is_array($sheetArray))	{
			return
$this->getFFvalueFromSheetArray($sheetArray,explode('/',$fieldName),$value);
		}
	}

	/**
	 * Returns part of $sheetArray pointed to by the keys in $fieldNameArray
	 *
	 * @param	array		Multidimensiona array, typically FlexForm contents
	 * @param	array		Array where each value points to a key in the FlexForms
content - the input array will have the value returned pointed to by these
keys. All integer keys will not take their integer counterparts, but rather
traverse the current position in the array an return element number X
(whether this is right behavior is not settled yet...)
	 * @param	string		Value for outermost key, typ. "vDEF" depending on language.
	 * @return	mixed		The value, typ. string.
	 * @access private
	 * @see getFFvalue()
	 */
	function getFFvalueFromSheetArray($sheetArray,$fieldNameArr,$value)	{

		$tempArr=$sheetArray;
		foreach($fieldNameArr as $k => $v)	{
			if (t3lib_div::testInt($v))	{
				if (is_array($tempArr))	{
					$c=0;
					foreach($tempArr as $values)	{
						if ($c==$v)	{
							#debug($values);
							$tempArr=$values;
							break;
						}
						$c++;
					}
				}
			} else {
				$tempArr = $tempArr[$v];
			}
		}
		return $tempArr[$value];
	}
	
	
}





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