CoolFace
Apppublic

kenken999/php

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
searchcontrol.php383 linesDownload Raw Back to classes
1<?php2/**3 * Base class for all search control builders4 */5class SearchControl 6{	7	var $tName = '';8 9	var $globSrchParams = array();10 11	var $getSrchPanelAttrs = array();12 13	var $dispNoneStyle = 'style="display: none;"';14 15	var $pageObj = null;16 17	var $pSet = null;18 19	var $searchClauseObj = false;20 21	var $id = 1;22	23	/**24	 * The instance of the EditControlsContainer class25	 * @type Object26	 */		27	var $controlsContainer;28		29	function __construct($id, $tName = '', &$searchClauseObj, &$pageObj)30	{31		$this->tName = $tName;32		33		$this->searchClauseObj = $searchClauseObj;34		$this->getSrchPanelAttrs = $this->searchClauseObj->getSrchPanelAttrs();35		$this->globSrchParams = $this->searchClauseObj->getSearchGlobalParams();36		37		$this->id = $id;38		$this->pageObj = &$pageObj;39		40		$this->pSet = $this->pageObj->pageType != PAGE_SEARCH ? new ProjectSettings($tName, PAGE_SEARCH) : $this->pageObj->pSetSearch;41		$this->controlsContainer = new EditControlsContainer($this->pageObj, $this->pSet, PAGE_SEARCH, $this->pageObj->cipherer);	42	}43	44	/**45	 * @param String fName 				The search field's name	46	 * @param Number recId 				The search field row's Id47	 * @param Number fieldNum 			The search field control's index (0 for the first, 1 for the second)48	 * @param String value 				The search control's value49	 * @param String opt 				The search control's search option 50	 * @param Boolean renderHidden 		Indicator showing if the search control is visible	51	 * @param Boolean isCached 			Indicator showing if the search control is cached52	 * @return Array53	 */54	function buildCtrlParamsArr($fName, $recId, $fieldNum, $value, $opt, $renderHidden = false, $isCached = true) 55	{56		$hidden = $renderHidden;57		$fType = $this->pSet->getEditFormat($fName);58		$format = $fType;	59		60		if ($fType == EDIT_FORMAT_TEXT_AREA	|| $fType == EDIT_FORMAT_PASSWORD || $fType == EDIT_FORMAT_HIDDEN61			|| $fType == EDIT_FORMAT_READONLY || $fType == EDIT_FORMAT_FILE)62		{63			$format = EDIT_FORMAT_TEXT_FIELD;64		}65		66		$parameters = array();67		$parameters["field"] = $fName;68		$parameters["mode"] = "search";69		$parameters["ptype"] = PAGE_SEARCH;70		$parameters["id"] = $recId;71		$parameters["fieldNum"] = $fieldNum;72		$parameters["format"] = $format;73		// the SearchControl object is passed instead off the page's object in order to74		// not mix 'Controls' instances fot the search and edit controls on the same page75		$parameters["pageObj"] = $this; 76		$parameters["value"]= $value;77		$parameters["additionalCtrlParams"] = array('hidden' => $hidden, 'option' => $opt);78		79		$ctrlsMap = $this->getControlMap($fName, $format, $recId, $fieldNum, $hidden, $value);80		$this->pageObj->fillControlsMap($ctrlsMap);	81		82		return $parameters;83	}84	85	/**86	 * @param String fName 				The search field's name	87	 * @param Number recId 				The search field row's Id88	 * @param Number fieldNum 			The search field control's index (0 for the first, 1 for the second)89	 * @param String value 				The search control's value90	 * @param Boolean renderHidden 		Indicator showing if the search control is visible	91	 * @param Boolean isCached 			Indicator showing if the search control is cached92	 * @return Array93	 */94	function getCtrlParamsArr($fName, $recId, $fieldNum, $value, $opt, $renderHidden = false, $isCached = true) 95	{96		$parameters = $this->buildCtrlParamsArr($fName, $recId, $fieldNum, $value, $opt, $renderHidden, $isCached);97		98		return XTempl::create_function_assignment( "xt_buildeditcontrol", $parameters);99	}100	101	/**102	 * Get the bas search control's map array 103	 * @return Array104	 */ 105	protected function getControlMap($fName, $format, $recId, $fieldNum, $hidden, $value)106	{107		$ctrlsMap = array( 'controls' => array() );108		$ctrlsMap['controls']['fieldName'] = $fName;109		$ctrlsMap['controls']['mode'] = MODE_SEARCH;110		$ctrlsMap['controls']['editFormat'] = $format;111		$ctrlsMap['controls']['id'] = $recId;112		$ctrlsMap['controls']['ctrlInd'] = $fieldNum;113		$ctrlsMap['controls']["hidden"] = $hidden;114		$ctrlsMap['controls']["table"] = $this->tName;115		116		$preload = $this->pageObj->fillPreload($fName, array($fName), array($fName => $value), $this->controlsContainer);117		if($preload !== false)118			$ctrlsMap["controls"]['preloadData'] = $preload;119				120		return $ctrlsMap;121	}122	123	/**124	 * Get a new edit control or the existing one125	 * The method is also invoked from the 'xt_buildeditcontrol' function only126	 *127	 * @param String field		Field name128	 * @param String id			Field id129	 * @return Object			Edit control130	 */131	public function getControl($field, $id = "", $extraParams = array())132	{133		return $this->controlsContainer->getControl($field, $id);134	}135 136	/**137	 * Get the current record data to build correct edit controls (xt_buildeditcontrol)138	 * @return Array139	 */140	public function getFieldControlsData()141	{142		return array();143	}144	145	/**146	 * If the search field needs the second control It returns second search control's params.147	 * Otherwise It returns false148	 *	 149	 * @param String fName 				The search field's name	150	 * @param Number recId 				The search field row's Id151	 * @param Number fieldNum 			The second search field control's index (=1)152	 * @param String value 				The second search control's value153	 * @param String opt 				The second search control's option154	 * @param Boolean renderHidden 		Indicator showing if the search control is visible	155	 * @param Boolean isCached 			Indicator showing if the search control is cached156	 * @return Array || Boolean157	 */	158	function getSecCtrlParamsArr($fName, $recId, $fieldNum = 0, $value, $opt, $renderHidden = false, $isCached=true) 159	{160		$fType = $this->pSet->getEditFormat($fName);	161		162		if( $this->isNeedSecondCtrl($fName) )163			return $this->getCtrlParamsArr($fName, $recId, $fieldNum + 1, $value, $opt, $renderHidden, $isCached);164 165		return false;166	}167	168	/**169	 * Check if the search field needs the second control 170	 * @param String fName171	 * @return Boolean172	 */173	function isNeedSecondCtrl($fName)174	{175		$fType = $this->pSet->getEditFormat($fName);176		177		$lookupType = $this->pSet->lookupControlType($fName);178		if( $this->pageObj->mobileTemplateMode() && $lookupType == LCT_AJAX )179			$lookupType = LCT_DROPDOWN;180		181		if ($fType == EDIT_FORMAT_DATE || $fType == EDIT_FORMAT_TIME || $fType == EDIT_FORMAT_TEXT_FIELD 182			|| $fType == EDIT_FORMAT_TEXT_AREA || $fType == EDIT_FORMAT_PASSWORD || $fType == EDIT_FORMAT_HIDDEN 183			|| $fType == EDIT_FORMAT_READONLY || $fType == EDIT_FORMAT_LOOKUP_WIZARD && $lookupType == LCT_AJAX)184		{185			return true;186		}187		188		return false;189	}	190	191	/**192	 * Get the search options193	 * @param String fName194	 * @param String selOpt195	 * @param Boolean not196	 * @param Boolean flexible (optional)197	 * @param Boolean both 		It indicates if the control needs 'NOT'-options198	 * @return String199	 */200	function getCtrlSearchTypeOptions($fName, $selOpt, $not, $flexible = false, $both = false) 201	{202		return $this->getControl($fName)->getSearchOptions($selOpt, $not, $both);203	}204	205	/**206	 * Get the control's search options list207	 * @param String fName208	 * @param Number recId209	 * @param Number fieldNum	The contol's indes ( 0: the first control; 1: the second one)210	 * @param String selOpt		The control's search option211	 * @param Boolean not		The search field's 'not' param indicating if it's necessary to invert an search option212	 * @param Boolean both		It indicates if the control needs 'NOT'-options213	 * @return String214	 */215	function getCtrlSearchType($fName, $recId, $fieldNum=0, $selOpt, $not, $flexible, $both) 216	{217		$emptyOption = $selOpt == EMPTY_SEARCH || $selOpt == NOT_EMPTY; 218		$visibility = !$flexible || $this->getSrchPanelAttrs['ctrlTypeComboStatus'] || $emptyOption ? '' : 'style="display: none;"';219		220		$searchtype = '<span id="'.$this->getCtrlComboContId($recId, $fName).'" '.$visibility.'>';221		$searchtype.= '<select class="form-control" '.$class.' id="'.$this->getSearchOptionId($fName, $recId).'" name="'.$this->getSearchOptionId($fName, $recId).'" size=1 '.$visibility.'>';222		$searchtype.= $this->getCtrlSearchTypeOptions($fName, $selOpt, $not, $flexible, $both);223		$searchtype.= "</select></span>";224		225		return $searchtype;226	}227	228	function getSearchOptionId($fName, $recId) 229	{230		return 'srchOpt_'.$recId.'_'.GoodFieldName($fName);231	}232	233	/**234	 * @param String fName235	 * @param Number recId236	 * @param Boolean not237	 * @return String238	 */239	function getNotBox($fName, $recId, $not)240	{241		$notbox = 'id="not_'.$recId.'_'.GoodFieldName($fName).'"';242		if($not)243			$notbox .=" checked";244			245		return $notbox;246	}247	248	function  getDelButtonHtml($fName, $recId)249	{250		$text = "";251		$text = '<span class="glyphicon glyphicon-remove"></span>';252		253		$html = '<a id = "'.$this->getDelButtonId($fName, $recId).'" ctrlId="'.$recId.'" fName="'.GoodFieldName($fName)254			.'" class="searchPanelButton" href="#" title="'."Delete control".'">' . $text . '</a>';255		return $html;256	}257	258	function getDelButtonId($fName, $recId) 259	{260		return 'delCtrlButt_'.$recId.'_'.GoodFieldName($fName);261	}262	263	function getSearchRadio()264	{	265		$resArr = array();266		// search panel radio button assign267		$resArr['all_checkbox_label'] = array(0=>'', 1=>'');268		$resArr['any_checkbox_label'] = array(0=>'', 1=>'');269		270		if(isEnableSection508())271		{272			$resArr['all_checkbox_label'] = array(0=>"<label for=\"all_checkbox\">", 1=>"</label>");273			$resArr['any_checkbox_label'] = array(0=>"<label for=\"any_checkbox\">", 1=>"</label>");			274		}275		276		$id508l="id=\"all_checkbox\" ";277		$id508n="id=\"any_checkbox\" ";278		279		$resArr['all_checkbox']	= $id508l;280		$resArr['any_checkbox']	= $id508n;281		282		$resArr['all_checkbox'] .= "value=\"and\" ";283		$resArr['any_checkbox'] .= "value=\"or\" ";284		285		if(isset($this->globSrchParams['srchTypeRadio']) && $this->globSrchParams['srchTypeRadio']=="or")286			$resArr['any_checkbox'] .=" checked";287		else288			$resArr['all_checkbox'] .=" checked";289		290		return $resArr;291	}292	293	function getFilterRowId($recId, $fName)294	{295		return 'filter_'.$recId.'_'.GoodFieldName($fName);296	}297	298	function getCtrlComboContId($recId, $fName)299	{300		return 'searchType_'.$recId.'_'.GoodFieldName($fName);301	}302	303	function buildSearchCtrlBlockArr($recId, $fName, $ctrlInd, $opt, $not, $isChached, $val1, $val2, $panelField = false, $flexible = true, $immutable = false, $both = false)304	{305		$srchCtrlBlock = array();306		307		$postfix = '';308		if($panelField)309			$postfix = '_'.GoodFieldName($fName);310		311		// if the search option isn't set by search params use the user's search option settings312		if($opt == "")313			$opt = $this->pSet->getDefaultSearchOption($fName);314		315		// create the first control316		$renderHidden = strtolower($opt) == 'empty' || strtolower($opt) == 'not empty';317		$srchCtrlBlock['searchcontrol'.$postfix] = $this->getCtrlParamsArr($fName, $recId, $ctrlInd, $val1, $opt, $renderHidden, $isChached);318 319		$renderHidden = strtolower($opt) != 'between' && strtolower($opt) != 'not between';320		if($flexible || !$renderHidden)321		{322			// create the second control323			$srchCtrlBlock['searchcontrol1'.$postfix] = $this->getSecCtrlParamsArr($fName, $recId, $ctrlInd, $val2, $opt, $renderHidden, $isChached);324		}325		326		// del button327		if( !$immutable )328			$srchCtrlBlock['delCtrlButt'] = $this->getDelButtonHtml($fName, $recId);329		330		// one control with options container attr331		$filterRowId = $this->getFilterRowId($recId, $fName);332		$filterRowAttrs = 'id="'.$filterRowId.'" ';333		if($isChached)334			$filterRowAttrs.= $this->dispNoneStyle;335			336		$srchCtrlBlock['filterRow_attrs'.$postfix] = $filterRowAttrs;337		338		if($immutable)339			$srchCtrlBlock['filterRow_class'.$postfix] = 'rnr-basic-search-field';340		341		$srchCtrlBlock['fName'] = $fName;342		// combo with attrs343		$srchCtrlBlock['searchtype'.$postfix] = $this->getCtrlSearchType($fName, $recId, $ctrlInd, $opt, $not, $flexible, $both);344		// checkbox attrs345		$srchCtrlBlock['notbox'] = $this->getNotBox($fName, $recId, $not);346		$srchCtrlBlock['fLabel'.$postfix] = GetFieldLabel(GoodFieldName($this->tName),GoodFieldName($fName));347		348		return $srchCtrlBlock;349	}350	351	/**352	 * get markup of simple search type control 353	 */354	public static function getSimpleSearchTypeCombo( $selOpt, $not, $id ) {355		$options = "<option value=\"Contains\" ".( $selOpt == "Contains" && !$not ? "selected" : "" ).">"."Contains"."</option>";356		$options.= "<option value=\"Equals\" ".( $selOpt == "Equals" && !$not ? "selected" : "" ).">"."Equals"."</option>";357		$options.= "<option value=\"Starts with\" ".( $selOpt == "Starts with" && !$not ? "selected" : "" ).">"."Starts with"."</option>";358		$options.= "<option value=\"More than\" ".( $selOpt == "More than" && !$not ? "selected" : "" ).">"."More than"."</option>";359		$options.= "<option value=\"Less than\" ".( $selOpt == "Less than" && !$not ? "selected" : "" ).">"."Less than"."</option>";360		$options.= "<option value=\"Empty\" ".( $selOpt == "Empty" && !$not ? "selected" : "" ).">"."Empty"."</option>";361		362		return '<select class="form-control" id="simpleSrchTypeCombo'. $id .'" name="simpleSrchTypeCombo'. $id .'" size="1">' 363			. $options . "</select>";364	}365	366	/**367	 * get markup of simple search field control 368	 */369	public static function simpleSearchFieldCombo( $fNamesArr, $googleLikeFields, $selOpt, $tName, $id ) {370		$options = "";371		if( $googleLikeFields )372			$options = '<option value="" >'."Any field".'</option>';373		374		foreach( $fNamesArr as $fName ) {375			$fLabel = GetFieldLabel( GoodFieldName( $tName ), GoodFieldName( $fName ) );376			$options .= '<option value="'.$fName.'" '.($selOpt == $fName ? 'selected' : '').'>'.$fLabel.'</option>';377		}378		379		return '<select class="form-control" id="simpleSrchFieldsCombo'. $id .'" name="simpleSrchFieldsCombo'. $id.'" size="1">' 380			. $options . "</select>";381	}382}383?>