kenken999/php
0
1<?php2class FilterPanel 3{4 public $pageObj;5 6 protected $id;7 8 protected $xt;9 10 protected $tName;11 12 /** 13 * The filters fileds names14 * @type Array15 */ 16 protected $filterFileds;17 18 /**19 * The array containig filters states (expan/collpased)20 * @type Array21 */ 22 protected $filterStates;23 24 /**25 * The ViewControlsContainer class instance26 * The pageObj's ViewControlsContainer instance could not be used instead due to 27 * the search highlighting and text truncating features applied to its controls28 * @type Object29 */30 protected $viewControls;31 32 33 public function __construct(&$params)34 {35 RunnerApply($this, $params);36 37 $this->id = $this->pageObj->id; 38 $this->xt = $this->pageObj->xt;39 $this->tName = $this->pageObj->tName;40 41 $this->filterFileds = $this->pageObj->pSet->getFilterFields();42 $this->viewControls = new ViewControlsContainer($this->pageObj->pSet, PAGE_LIST);43 44 $this->xt->enable_section("filterPanel");45 if( !$this->pageObj->controlsMap["filters"] )46 {47 $this->pageObj->controlsMap["filters"] = array("controls" => array());48 }49 }50 51 /**52 * Get filters blocks' data and Assign it to the Filter panel's blocks53 */54 public function buildFilterPanel()55 { 56 $panelVisible = false;57 include_once getabspath("classes/controls/FilterControl.php");58 foreach($this->filterFileds as $fieldName) 59 { 60 $filterFieldName = $fieldName;61 $filterControl = FilterControl::getFilterControl($filterFieldName, $this->pageObj, $this->id, $this->viewControls); 62 if( !$filterControl ) {63 continue;64 }65 66 if( $filterControl->hasDependentFilter() )67 continue;68 69 70 $filterCtrlBlocks = $filterControl->buildFilterCtrlBlockArray($this->pageObj);71 $filterButtonParams = $filterControl->getFilterButtonParams();72 $filterExtraControls = $filterControl->getFilterExtraControls();73 74 while( $filterControl->dependent )75 {76 $filterFieldName = $filterControl->parentFilterName; 77 $filterControl = FilterControl::getFilterControl($filterFieldName, $this->pageObj, $this->id, $this->viewControls);78 if( !$filterControl ) {79 continue;80 }81 82 $filterCtrlBlocks = $filterControl->buildFilterCtrlBlockArray( $this->pageObj, $filterCtrlBlocks ); 83 $filterButtonParams = $filterControl->getFilterButtonParams( $filterButtonParams );84 $filterExtraControls = $filterControl->getFilterExtraControls( $filterExtraControls );85 } 86 87 $filterState = $filterControl->getFilterState();88 if( $filterState["visible"] ) {89 $panelVisible = true;90 }91 92 $this->assignFilterPanelField($filterFieldName, $filterCtrlBlocks, $filterState, $filterButtonParams, $filterExtraControls); 93 94 }95 return $panelVisible;96 }97 98 /**99 * Assign the Filter Panel's blocks100 * @param Strign fieldName101 * @param Array filterCtrlBlocks102 * @param Array filterState103 * @param Array filterButtonParams104 * @param Array filterExtraControls105 */106 protected function assignFilterPanelField($fieldName, $filterCtrlBlocks, $filterState, $filterButtonParams, $filterExtraControls) 107 {108 $postfix = "_".GoodFieldName($fieldName);109 $visibility = $filterState["visible"];110 111 $this->xt->assign("filter_control".$postfix, $visibility);112 if( !$visibility )113 {114 return;115 }116 117 $this->xt->assign_loopsection_byValue("filterCtrlBlock".$postfix, $filterCtrlBlocks);118 119 $this->xt->assign("collapsedClass".$postfix, "filter-collapsed"); 120 121 $this->xt->assign("filterbutton_attrs".$postfix, $filterButtonParams["attrs"]);122 $this->xt->assign("filter_button_apply".$postfix, $filterButtonParams["hasApplyBtn"]);123 $this->xt->assign("filter_button_multiselect".$postfix, $filterButtonParams["hasMultiselectBtn"]);124 125 $this->xt->assign("clearLink".$postfix, $filterExtraControls["filtered"]);126 $this->xt->assign("filter_selected".$postfix, $filterExtraControls["filtered"]);127 $this->xt->assign("filtervalue".$postfix, $filterExtraControls["showValue"]);128 $this->xt->assign("selectAll_attrs".$postfix, $filterExtraControls["selectAllAttrs"]);129 130 $this->xt->assign("filter_button_showmore".$postfix, $filterState["truncated"]);131 $this->xt->assign("show_n_more".$postfix, str_replace( "%n%", $filterExtraControls["numberOfExtraItemsToShow"], "Show %n% more" ) );132 133 if( $filterState["showMoreHidden"] )134 $this->xt->assign("showMoreBtnClass".$postfix, "show-more-hidden");135 }136}137?>