菜单

multiple displayCond in TCA

2011年09月20日 - typo3

How to use:
‘displayCond’ => ‘FIELD:sys_language_uid:IN:0,1,2&&FIELD:t_type:=:0||FIELD:sys_language_uid:=:0&&FIELD:t_type:=:1’,

t3lib/class.t3lib_tceforms.php

line 6092: isDisplayCondition()

/**
	 * Returns true, if the evaluation of the required-field code is OK.
	 *
	 * @param	string		The required-field code
	 * @param	array		The record to evaluate
	 * @param	string		FlexForm value key, eg. vDEF
	 * @return	boolean
	 */
	function isDisplayCondition($displayCond, $row, $ffValueKey = '') {
		$output = FALSE;
		
		$flag = false;
		if($displayCond == 'FIELD:sys_language_uid:IN:0,1,2&&FIELD:t_type:=:0||FIELD:sys_language_uid:=:0&&FIELD:t_type:=:1'){
			$flag = true;
		}
		
		$tempOr = FALSE;
		$tempArrayOr = explode("||", $displayCond);
		foreach($tempArrayOr as $tempArrayAnd){
			//add by bobo
			$tempArray = explode("&&", $tempArrayAnd);
			$tempAnd = TRUE;
			foreach($tempArray as $displayCondSingle){
				$parts = explode(':', $displayCondSingle);
				switch ((string) $parts[0]){ // Type of condition:
					case 'FIELD':
						if ($ffValueKey) {
							if (strpos($parts[1], 'parentRec.') !== FALSE) {
								$fParts = explode('.', $parts[1]);
								$theFieldValue = $row['parentRec'][$fParts[1]];
							} else {
								$theFieldValue = $row[$parts[1]][$ffValueKey];
							}
						} else {
							$theFieldValue = $row[$parts[1]];
						}

						switch ((string) $parts[2]) {
							case 'REQ':
								if (strtolower($parts[3]) == 'true') {
									$output = $theFieldValue ? TRUE : FALSE;
								} elseif (strtolower($parts[3]) == 'false') {
									$output = !$theFieldValue ? TRUE : FALSE;
								}
							break;
							case '>':
								$output = $theFieldValue > $parts[3];
							break;
							case '<':
								$output = $theFieldValue < $parts[3];
							break;
							case '>=':
								$output = $theFieldValue >= $parts[3];
							break;
							case '<=':
								$output = $theFieldValue <= $parts[3];
							break;
							case '-':
							case '!-':
								$cmpParts = explode('-', $parts[3]);
								$output = $theFieldValue >= $cmpParts[0] && $theFieldValue <= $cmpParts[1];
								if ($parts[2]{0} == '!') {
									$output = !$output;
								}
							break;
							case 'IN':
							case '!IN':
								$output = t3lib_div::inList($parts[3], $theFieldValue);
								if ($parts[2]{0} == '!') {
									$output = !$output;
								}
							break;
							case '=':
							case '!=':
								$output = t3lib_div::inList($parts[3], $theFieldValue);
								if ($parts[2]{0} == '!') {
									$output = !$output;
								}
							break;
						}
					break;
					case 'EXT':
						switch ((string) $parts[2]) {
							case 'LOADED':
								if (strtolower($parts[3]) == 'true') {
									$output = t3lib_extMgm::isLoaded($parts[1]) ? TRUE : FALSE;
								} elseif (strtolower($parts[3]) == 'false') {
									$output = !t3lib_extMgm::isLoaded($parts[1]) ? TRUE : FALSE;
								}
							break;
						}
					break;
					case 'REC':
						switch ((string) $parts[1]) {
							case 'NEW':
								if (strtolower($parts[2]) == 'true') {
									$output = !(intval($row['uid']) > 0) ? TRUE : FALSE;
								} elseif (strtolower($parts[2]) == 'false') {
									$output = (intval($row['uid']) > 0) ? TRUE : FALSE;
								}
							break;
						}
					break;
					case 'HIDE_L10N_SIBLINGS':
						if ($ffValueKey === 'vDEF') {
							$output = TRUE;
						} elseif ($parts[1] === 'except_admin' && $GLOBALS['BE_USER']->isAdmin()) {
							$output = TRUE;
						}
					break;
					case 'HIDE_FOR_NON_ADMINS':
						$output = $GLOBALS['BE_USER']->isAdmin() ? TRUE : FALSE;
					break;
					case 'VERSION':
						switch ((string) $parts[1]) {
							case 'IS':
								$isNewRecord = (intval($row['uid']) > 0 ? FALSE : TRUE);

									// detection of version can be done be detecting the workspace of the user
								$isUserInWorkspace = ($GLOBALS['BE_USER']->workspace > 0 ? TRUE : FALSE);
								if (intval($row['pid']) == -1 || intval($row['_ORIG_pid']) == -1) {
									$isRecordDetectedAsVersion = TRUE;
								} else {
									$isRecordDetectedAsVersion = FALSE;
								}

									// New records in a workspace are not handled as a version record
									// if it's no new version, we detect versions like this:
									// -- if user is in workspace: always true
									// -- if editor is in live ws: only true if pid == -1
								$isVersion = ($isUserInWorkspace || $isRecordDetectedAsVersion) && !$isNewRecord;

								if (strtolower($parts[2]) == 'true') {
									$output = $isVersion;
								} else {
									if (strtolower($parts[2]) == 'false') {
										$output = !$isVersion;
									}
								}
							break;
						}
					break;
				}
				if(!$output){
					$tempAnd = FALSE;
				}
			}
			if($tempAnd){
				$tempOr = TRUE;
			}
			// if($flag)echo $tempAnd.'
'; } $output = $tempOr?TRUE:FALSE; return $output; }

发表评论

电子邮件地址不会被公开。 必填项已用*标注