kenken999/php
0
1<?php2/**3 * Search panel builder4 */5class SearchPanelSimple {6 protected $pageObj = null;7 8 protected $searchClauseObj = null;9 protected $tName = '';10 protected $pSet = null; 11 protected $id = 1;12 13 /**14 * The page's xTeml instance15 */16 protected $xt; 17 18 /**19 * Object of PanelSearchControl class.20 * @var object21 */22 protected $controlBuilder = null;23 24 25 /**26 * Fields that used for search on panel, and should be open on every page load27 * @var array28 */29 protected $panelSearchFields = array();30 31 /**32 * Array of key's fields33 * @var array34 */35 protected $allSearchFields = array();36 37 38 protected $searchOptions = array(); 39 40 41 /**42 * Constructor, accepts array of parametres, which will be copied to object properties by link43 *44 * @param array $params45 * @return SearchPanel46 */47 function __construct( &$params ) {48 $this->pageObj = $params['pageObj'];49 50 $this->searchClauseObj = &$this->pageObj->searchClauseObj; 51 52 $this->id = $this->pageObj->id;53 $this->pSet = $this->pageObj->pSetSearch;54 $this->tName = $this->pageObj->searchTableName;55 $this->xt = $this->pageObj->xt;56 57 if( !isset( $params['panelSearchFields'] ) )58 $this->panelSearchFields = $this->pSet->getPanelSearchFields();59 else60 $this->panelSearchFields = $params['panelSearchFields']; 61 62 if( !isset( $params['allSearchFields'] ) )63 $this->allSearchFields = $this->pSet->getAllSearchFields();64 else65 $this->allSearchFields = $params['allSearchFields'];66 67 $this->controlBuilder = new PanelSearchControl( $this->id, $this->tName, $this->searchClauseObj, $this->pageObj ); 68 }69 70 /**71 *72 */73 public function buildSearchPanel() { 74 /*$searchPerm = true;75 if( isEnableSection508() ) {76 $searchPerm = array();77 $searchPerm["begin"] = "<a name=\"skipsearch\"></a>";78 }79 $this->xt->assign( "searchformbuttons_block", $searchPerm );*/80 81 if( $this->pSet->showSearchPanel() ) { 82 $this->searchOptions = $this->pSet->getSearchPanelOptions();83 $this->displaySearchPanel();84 }85 }86 87 /**88 * Show search panel89 */90 function displaySearchPanel() {91 $this->xt->assign('id', $this->id);92 $this->xt->assign('searchPanel', true);93 94 // 'show\hide search panel' buttons95 $this->xt->assign('searchPanelTopButtons', true );96 97 if( !$this->pSet->isFlexibleSearch() )98 $this->xt->assign('controls_block_class', 'flexibleSearchPanel');99 100 // assign the search panel radio buttons 101 $radio = $this->controlBuilder->getSearchRadio();102 $this->xt->assign_section( "all_checkbox_label", $radio['all_checkbox_label'][0], $radio['all_checkbox_label'][1] );103 $this->xt->assign_section( "any_checkbox_label", $radio['any_checkbox_label'][0], $radio['any_checkbox_label'][1] );104 $this->xt->assignbyref( "all_checkbox", $radio['all_checkbox'] );105 $this->xt->assignbyref( "any_checkbox", $radio['any_checkbox'] );106 107 $srchPanelAttrs = $this->searchClauseObj->getSrchPanelAttrs();108 // assign the 'Show/Hide options' button 109 $showHideOpt_mess = $srchPanelAttrs['ctrlTypeComboStatus'] ? 110 "Hide options" : "Show options"; 111 $this->xt->assign("showHideOpt_mess", $showHideOpt_mess);112 $this->xt->assign("showHideCtrlsOpt_attrs", 'style="display: none;"');113 114 if( $this->searchClauseObj->getUsedCtrlsCount() <= 0 )115 $this->xt->assign("bottomSearchButt_attrs", 'style="display: none;"');116 117 $this->assignSearchBlocks();118 119 $this->pageObj->controlsMap["search"]["searchPanelRunByUserApi"] = $this->searchClauseObj->isSearchPanelByUserApiRun();120 121 $showallbutton_attrs = 'id="showAll'.$this->id.'"';122 123 if( !$this->searchClauseObj->isShowAll() ) {124 $dispNoneStyle = 'style="display: none;"';125 $showallbutton_attrs.= ' '.$dispNoneStyle;126 $this->xt->assign("showAllCont_attrs", $dispNoneStyle);127 }128 129 $this->xt->assign( 'showallbutton_attrs', $showallbutton_attrs );130 }131 132 /**133 * Assign controls blocks for the search panel's,134 * added-by-user and cached fields 135 */136 function assignSearchBlocks() {137 global $gLoadSearchControls;138 139 $searchPanelFieldsBlocks = array();140 $otherFieldsBlocks = array();141 $notAddedFileds = array();142 $srchCtrlBlocksNumber = 0;143 144 $recId = $this->pageObj->genId();145 146 // build search controls for each field, first we need to build used controls, because cached must have last index 147 foreach( $this->allSearchFields as $searchField ) {148 $srchFields = $this->searchClauseObj->getSearchCtrlParams($searchField);149 $isSrchPanelField = in_array($searchField, $this->panelSearchFields);150 151 if( !$srchFields ) {152 $defaultValue = $this->pSet->getDefaultValue( $searchField );153 154 if( $isSrchPanelField ) {155 $opt = '';156 //set the field's option chosen for the inflexible search panel 157 if( !$this->pSet->isFlexibleSearch() )158 $opt = $this->searchOptions[$searchField];159 160 // add a search panel field that should be always shown on the panel 161 $srchFields[] = array('opt' => $opt, 'not' => '', 'value1' => $defaultValue, 'value2' => '');162 }163 }164 165 if( $srchFields ) {166 if( $isSrchPanelField ) 167 $srchFields[ count($srchFields) - 1 ]['immutable'] = true;168 169 foreach( $srchFields as $srchField ) {170 // build used ctrl171 $block = $this->controlBuilder->buildSearchCtrlBlockArr(172 $recId, 173 $searchField, 174 0, 175 $srchField['opt'], 176 $srchField['not'], 177 false, 178 $srchField['value1'], 179 $srchField['value2'], 180 $isSrchPanelField, 181 $this->pSet->isFlexibleSearch(), 182 $srchField['immutable']183 );184 185 if($isSrchPanelField)186 $searchPanelFieldsBlocks[$searchField][] = $block;187 else188 $otherFieldsBlocks[] = $block;189 190 $srchCtrlBlocksNumber++;191 $this->addSearchFieldToControlsMap($searchField, $recId);192 }193 } 194 else195 $notAddedFileds[] = $searchField; 196 }197 198 // assign search panel fields (default and added-by-user) 199 foreach( $searchPanelFieldsBlocks as $name => $namedBlocks ) { 200 $this->xt->assign_loopsection_byValue('searchCtrlBlock_'.GoodFieldName($name), $namedBlocks);201 }202 203 if( !$this->pSet->isFlexibleSearch() )204 return;205 206 //add cached searhc fields207 if( $srchCtrlBlocksNumber > 0 && $srchCtrlBlocksNumber < $gLoadSearchControls ) {208 $otherSearchControlsMaxNumber = $gLoadSearchControls - $srchCtrlBlocksNumber + count($otherFieldsBlocks);209 foreach( $notAddedFileds as $searchField ) { 210 $defaultValue = $this->pSet->getDefaultValue( $searchField );211 // add cached ctrl212 $otherFieldsBlocks[] = $this->controlBuilder->buildSearchCtrlBlockArr(213 $recId, 214 $searchField, 215 0, 216 '', 217 false, 218 true, 219 $defaultValue, 220 ''221 );222 223 $this->addSearchFieldToControlsMap($searchField, $recId);224 225 if( count($otherFieldsBlocks) >= $otherSearchControlsMaxNumber )226 break;227 } 228 }229 230 // assign cached and non search panel fields' blocks231 $this->xt->assign_loopsection('searchCtrlBlock', $otherFieldsBlocks);232 }233 234 /**235 * Add the search field block's data to the page's ControlsMap array236 * Generate the new value for the recId237 * @param String fName238 * @param &Number recId239 */240 function addSearchFieldToControlsMap( $fName, &$recId ) {241 $isFieldNeedSecCtrl = $this->controlBuilder->isNeedSecondCtrl($fName);242 $searchBlock = array('fName'=>$fName, 'recId'=>$recId);243 $ctrlInd = 0;244 245 $searchBlock['ctrlsMap'][0] = $ctrlInd;246 if($isFieldNeedSecCtrl)247 $searchBlock['ctrlsMap'][1] = $ctrlInd + 1;248 249 if( !$this->pSet->isFlexibleSearch() )250 $searchBlock['inflexSearchOption'] = $this->searchOptions[$fName];251 252 $this->pageObj->controlsMap["search"]["searchBlocks"][] = $searchBlock;253 $recId = $this->pageObj->genId();254 }255 256 /**257 * Refine the open seach panel fields array:258 * It removes all non search fields and each one 259 * of the always shown fields (search panel fields)260 * from the array.261 * @param Array openFilters262 * @return Array263 */264 function refineOpenFilters( $openFilters ) {265 $openFiltersRefined = array();266 267 foreach( $this->panelSearchFields as $panelFiled ) {268 $key = array_search($panelFiled, $openFilters);269 if( $key !== FALSE )270 array_splice($openFilters, $key, 1);271 }272 273 foreach( $openFilters as $field ) {274 if( in_array($field, $this->allSearchFields) ) 275 $openFiltersRefined[] = $field;276 }277 278 return $openFiltersRefined;279 }280}281 282?>