PageRenderTime 24ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/output/classes/controls/FilterIntervalSlider.php

https://gitlab.com/Lidbary/PHPRunner
PHP | 400 lines | 247 code | 68 blank | 85 comment | 49 complexity | 51f525be930a634474e24bb23104ebcc MD5 | raw file
  1. <?php
  2. class FilterIntervalSlider extends FilterControl
  3. {
  4. protected $separator;
  5. protected $knobsType;
  6. protected $stepValue;
  7. protected $minValue;
  8. protected $maxValue;
  9. protected $minKnobValue;
  10. protected $maxKnobValue;
  11. public function FilterIntervalSlider($fName, $pageObject, $id, $viewControls)
  12. {
  13. parent::FilterControl($fName, $pageObject, $id, $viewControls);
  14. $this->filterFormat = FF_INTERVAL_SLIDER;
  15. $this->useApllyBtn = $this->pSet->isFilterApplyBtnSet($fName);
  16. $this->knobsType = $this->pSet->getFilterKnobsType($fName);
  17. $this->stepValue = $this->pSet->getFilterStepValue($fName);
  18. $this->buildSQL();
  19. $this->addJS_CSSfiles($pageObject);
  20. if( $this->filtered )
  21. $this->assignKnobsValues();
  22. $this->separator = $this->getSeparator();
  23. }
  24. /**
  25. * Assign the control's knobs properties
  26. */
  27. protected function assignKnobsValues()
  28. {
  29. $filterValues = $this->filteredFields[ $this->fName ]['values'];
  30. if($this->knobsType == FS_MIN_ONLY)
  31. {
  32. $this->minKnobValue = $filterValues[0];
  33. return;
  34. }
  35. if($this->knobsType == FS_MAX_ONLY)
  36. {
  37. $this->maxKnobValue = $filterValues[0];
  38. return;
  39. }
  40. $this->minKnobValue = $filterValues[0];
  41. $this->maxKnobValue = $filterValues[1];
  42. }
  43. /**
  44. * Get the separator value
  45. * @return String
  46. */
  47. protected function getSeparator()
  48. {
  49. if($this->knobsType == FS_MIN_ONLY)
  50. return '~moreequal~';
  51. if($this->knobsType == FS_MAX_ONLY)
  52. return '~lessequal~';
  53. return '~slider~';
  54. }
  55. /**
  56. * Form the SQL query string to get then the filter's data
  57. */
  58. protected function buildSQL()
  59. {
  60. $dbfName = $this->getDbFieldName($this->fName);
  61. $sqlHead = "SELECT MIN(".$dbfName.") as " .$this->connection->addFieldWrappers("sliderMin"). ", MAX(".$dbfName.") as " .$this->connection->addFieldWrappers("sliderMax");
  62. $whereComponents = $this->whereComponents;
  63. $gQuery = $this->pSet->getSQLQuery();
  64. $sqlFrom = $gQuery->FromToSql().$whereComponents["joinFromPart"];
  65. $sqlWhere = $this->getCombinedFilterWhere();
  66. $sqlGroupBy = "GROUP BY ".$dbfName;
  67. $sqlHaving = $this->getCombinedFilterHaving();
  68. $notNullWhere = $dbfName." is not NULL";
  69. if( $this->connection->dbType != nDATABASE_Oracle )
  70. {
  71. if( IsCharType($this->fieldType) )
  72. $notNullWhere = $dbfName."<>'' and ".$notNullWhere;
  73. }
  74. $sqlWhere = whereAdd($sqlWhere, $notNullWhere);
  75. $searchCombineType = $whereComponents["searchUnionRequired"] ? "or" : "and";
  76. $this->strSQL = SQLQuery::gSQLWhere_having($sqlHead, $sqlFrom, $sqlWhere, "", "", $whereComponents["searchWhere"], $whereComponents["searchHaving"], $strSearchCriteria);
  77. }
  78. /**
  79. * Get the filter blocks data using the database query
  80. * and add it the the existing blocks
  81. * @param &Array
  82. */
  83. protected function addFilterBlocksFromDB(&$filterCtrlBlocks)
  84. {
  85. //query to database with current where settings
  86. $data = $this->connection->query( $this->strSQL )->fetchAssoc();
  87. $this->decryptDataRow($data);
  88. if( $this->fieldHasNoRange($data) )
  89. return $filterCtrlBlocks;
  90. $filterControl = $this->buildControl($data);
  91. $filterCtrlBlocks[] = $this->getFilterBlockStructure($filterControl);
  92. }
  93. /**
  94. * Check if there are database values for the filter's field
  95. * that are differs from each other for more than a step value
  96. * @param Array data
  97. * @return Boolean
  98. */
  99. protected function fieldHasNoRange($data)
  100. {
  101. if (is_null( $data['sliderMin'] ) && is_null( $data['sliderMax'] ) || $data['sliderMax'] == $data['sliderMin'])
  102. return true;
  103. return false;
  104. }
  105. /**
  106. * Get the html markup representing the control on the page
  107. * @param Array data
  108. * @param Array parentFiltersData (optional)
  109. * @return String
  110. */
  111. protected function buildControl( $data, $parentFiltersData = array() )
  112. {
  113. $this->minValue = $data['sliderMin'];
  114. $this->maxValue = $data['sliderMax'];
  115. if( !$this->filtered )
  116. {
  117. $this->minKnobValue = $data['sliderMin'];
  118. $this->maxKnobValue = $data['sliderMax'];
  119. }
  120. else
  121. {
  122. if($this->knobsType == FS_MAX_ONLY)
  123. $this->minKnobValue = $data['sliderMin'];
  124. if($this->knobsType == FS_MIN_ONLY)
  125. $this->maxKnobValue = $data['sliderMax'];
  126. }
  127. return $this->getSliderHTML();
  128. }
  129. /**
  130. * Get the html markup for the slider knobs' captions
  131. * @return String
  132. */
  133. protected function getCaptionSpansHTML()
  134. {
  135. $minSpan = '<span class="slider-min">'.$this->getMinSpanValue().'</span>';
  136. $maxSpan = '<span class="slider-max">'.$this->getMaxSpanValue().'</span>';
  137. $captionSpans = $minSpan."&nbsp;-&nbsp".$maxSpan;
  138. $prefixSpan = '<span class="slider-caption-prefix"></span>';
  139. $postfixSpan = '<span class="slider-caption-postfix"></span>';
  140. $captionSpans = $prefixSpan . $captionSpans . $postfixSpan;
  141. return $captionSpans;
  142. }
  143. /**
  144. * Get the html markup for the slider's control
  145. * @return String
  146. */
  147. protected function getSliderHTML()
  148. {
  149. $captionSpans = $this->getCaptionSpansHTML();
  150. $filterControl = '<div id="slider_values_'.$this->gfName.'" class="filter-slider-values">'.$captionSpans.'</div>';
  151. $filterControl.= '<div id="slider_'.$this->gfName.'" class="filter-slider"></div>';
  152. return $filterControl;
  153. }
  154. /**
  155. * Get the caption fot the min slider's knob
  156. * @return String
  157. */
  158. protected function getMinSpanValue()
  159. {
  160. $minSpanValue = $this->minKnobValue;
  161. if($minSpanValue < $this->minValue)
  162. $minSpanValue = $this->minValue;
  163. $viewFormat = $this->viewControl->viewFormat;
  164. if($viewFormat == FORMAT_CURRENCY || $viewFormat == FORMAT_NUMBER)
  165. {
  166. $data = array($this->fName => $minSpanValue);
  167. $minSpanValue = $this->viewControl->showDBValue($data, "");
  168. }
  169. return $minSpanValue;
  170. }
  171. /**
  172. * Get the caption fot the max slider's knob
  173. * @return String
  174. */
  175. protected function getMaxSpanValue()
  176. {
  177. $maxSpanValue = $this->maxKnobValue;
  178. if($maxSpanValue > $this->maxValue)
  179. $maxSpanValue = $this->maxValue;
  180. $viewFormat = $this->viewControl->viewFormat;
  181. if($viewFormat == FORMAT_CURRENCY || $viewFormat == FORMAT_NUMBER)
  182. {
  183. $data = array($this->fName => $maxSpanValue);
  184. $maxSpanValue = $this->viewControl->showDBValue($data, "");
  185. }
  186. return $maxSpanValue;
  187. }
  188. /**
  189. * Add filter control's data to the ControlsMap
  190. * @param Object pageObj
  191. */
  192. public function addFilterControlToControlsMap($pageObj)
  193. {
  194. $ctrlsMap = $this->getBaseContolsMapParams();
  195. $ctrlsMap['minValue'] = $this->minValue;
  196. $ctrlsMap['maxValue'] = $this->maxValue;
  197. $ctrlsMap['roundedMin'] = $this->round( $this->minValue, true);
  198. $ctrlsMap['roundedMax'] = $this->round( $this->maxValue, false );
  199. $ctrlsMap['roundedMinKnobValue'] = $this->round( $this->minKnobValue, true );
  200. $ctrlsMap['roundedMaxKnobValue'] = $this->round( $this->maxKnobValue, false );
  201. if($this->filtered)
  202. {
  203. $ctrlsMap['defaultValuesArray'] = $this->filteredFields[ $this->fName ]["values"];
  204. $ctrlsMap['minKnobValue'] = $this->minKnobValue;
  205. $ctrlsMap['maxKnobValue'] = $this->maxKnobValue;
  206. }
  207. $viewFomat = $this->viewControl->viewFormat;
  208. $ctrlsMap['viewAsNumber'] = $viewFomat == FORMAT_NUMBER;
  209. $ctrlsMap['viewAsCurrency'] = $viewFomat == FORMAT_CURRENCY;
  210. if($viewFomat === FORMAT_CURRENCY)
  211. $ctrlsMap['formatSettings'] = $this->getCurrencySettings();
  212. else if ($viewFomat == FORMAT_NUMBER)
  213. $ctrlsMap['formatSettings'] = $this->getNumberSettings();
  214. if($viewFomat === FORMAT_CURRENCY || $viewFomat == FORMAT_NUMBER)
  215. $ctrlsMap['commonFormatSettings'] = $this->getCommonFormatSettings($viewFomat);
  216. $pageObj->controlsMap["filters"]["controls"][] = $ctrlsMap;
  217. }
  218. /**
  219. * Get currency local settings
  220. * @return Array
  221. */
  222. protected function getCurrencySettings()
  223. {
  224. global $locale_info;
  225. $currencySettings = array();
  226. $currencySettings["LOCALE_ICURRENCY"] = $locale_info["LOCALE_ICURRENCY"];
  227. $currencySettings["LOCALE_INEGCURR"] = $locale_info["LOCALE_INEGCURR"];
  228. $currencySettings["LOCALE_SCURRENCY"] = $locale_info["LOCALE_SCURRENCY"];
  229. return $currencySettings;
  230. }
  231. /**
  232. * Get number format local settings
  233. * @return Array
  234. */
  235. protected function getNumberSettings()
  236. {
  237. global $locale_info;
  238. $numberSettings = array();
  239. $numberSettings['LOCALE_SPOSITIVESIGN'] = $locale_info["LOCALE_SPOSITIVESIGN"];
  240. $numberSettings['LOCALE_INEGNUMBER'] = $locale_info["LOCALE_INEGNUMBER"];
  241. return $numberSettings;
  242. }
  243. /**
  244. * Get common format settings
  245. * @param Boolean viewFormat
  246. * @return Array
  247. */
  248. protected function getCommonFormatSettings($viewFomat)
  249. {
  250. global $locale_info;
  251. $formatSettings = array();
  252. if($viewFomat === FORMAT_CURRENCY)
  253. {
  254. $formatSettings['decimalDigits'] = $locale_info["LOCALE_ICURRDIGITS"];
  255. $formatSettings['grouping'] = explode(";", $locale_info['LOCALE_SMONGROUPING']);
  256. $formatSettings['thousandSep'] = $locale_info["LOCALE_SMONTHOUSANDSEP"];
  257. $formatSettings['decimalSep'] = $locale_info["LOCALE_SMONDECIMALSEP"];
  258. }
  259. if ($viewFomat == FORMAT_NUMBER)
  260. {
  261. $formatSettings['decimalDigits'] = $this->pSet->isDecimalDigits($this->fName);
  262. $formatSettings['grouping'] = explode(";", $locale_info['LOCALE_SGROUPING']);
  263. $formatSettings['thousandSep'] = $locale_info["LOCALE_STHOUSAND"];
  264. $formatSettings['decimalSep'] = $locale_info["LOCALE_SDECIMAL"];
  265. }
  266. return $formatSettings;
  267. }
  268. /**
  269. * Get filter control's base ControlsMap array
  270. * @return array
  271. */
  272. protected function getBaseContolsMapParams()
  273. {
  274. $ctrlsMap = array();
  275. $ctrlsMap['fieldName'] = $this->fName;
  276. $ctrlsMap['gfieldName'] = $this->gfName;
  277. $ctrlsMap['filterFormat'] = $this->filterFormat;
  278. $ctrlsMap['filtered'] = $this->filtered;
  279. $ctrlsMap['separator'] = $this->separator;
  280. $ctrlsMap['knobsType'] = $this->knobsType;
  281. $ctrlsMap['useApllyBtn'] = $this->useApllyBtn;
  282. $ctrlsMap['step'] = $this->getStepValue();
  283. return $ctrlsMap;
  284. }
  285. /**
  286. * Get the slider's step value
  287. * @return number
  288. */
  289. protected function getStepValue()
  290. {
  291. return $this->stepValue;
  292. }
  293. /**
  294. * Get the rounded to the upper or lower limit value
  295. * basing on the step value
  296. * @param number value
  297. * @return number
  298. */
  299. protected function round($value, $min)
  300. {
  301. $step = $this->stepValue;
  302. if($min)
  303. return floor( $value / $step ) * $step;
  304. return ceil( $value / $step ) * $step;
  305. }
  306. /**
  307. * Add extra js and css files
  308. * @param object pageObject
  309. */
  310. protected function addJS_CSSfiles($pageObject)
  311. {
  312. $pageObject->AddJSFile("include/jquery-ui/jquery-ui-1.10.4.custom.min.js");
  313. $pageObject->AddCSSFile("include/jquery-ui/smoothness/jquery-ui-1.10.4.custom.min.css");
  314. }
  315. /**
  316. * Get the Filter's control block data.
  317. * @param Object pageObj
  318. * @param Array $dFilterBlocks (optional)
  319. * @return Array
  320. */
  321. public function buildFilterCtrlBlockArray( $pageObj, $dFilterBlocks = null )
  322. {
  323. $filterCtrlBlocks = array();
  324. $this->addFilterBlocksFromDB($filterCtrlBlocks);
  325. if( !count($filterCtrlBlocks) )
  326. $this->visible = false;
  327. if($this->visible)
  328. $this->addFilterControlToControlsMap($pageObj);
  329. return $filterCtrlBlocks;
  330. }
  331. }
  332. ?>