BxBaseSearchExtendedForm.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaBaseView UNA Base Representation Classes
  7. * @{
  8. */
  9. /**
  10. * Extended Search Form.
  11. *
  12. * @see BxDolSearchExtended
  13. */
  14. class BxBaseSearchExtendedForm extends BxTemplFormView
  15. {
  16. protected $_iAgeMin;
  17. protected $_iAgeMax;
  18. public function __construct($aInfo, $oTemplate = false)
  19. {
  20. parent::__construct($aInfo, $oTemplate);
  21. $this->_iAgeMin = 1;
  22. $this->_iAgeMax = 75;
  23. }
  24. function getCleanValue($sName)
  25. {
  26. $bType = isset($this->aInputs[$sName]['type']);
  27. //--- Process field with 'Location' type.
  28. if($bType && $this->aInputs[$sName]['type'] == 'location')
  29. return array(
  30. 'string' => parent::getCleanValue($sName),
  31. 'array' => BxDolMetatags::locationsRetrieveFromForm($sName, $this)
  32. );
  33. if($bType && $this->aInputs[$sName]['type'] == 'location_radius'){
  34. $aTmp = BxDolMetatags::locationsRetrieveFromForm($sName, $this);
  35. $sValue = bx_get($sName . '_rad');
  36. $iValue = is_numeric($sValue) ? (int)$sValue : 0;
  37. array_push($aTmp, $iValue);
  38. return array(
  39. 'string' => parent::getCleanValue($sName),
  40. 'array' => $aTmp
  41. );
  42. }
  43. //--- Process field with 'Date Range Age' and 'Date-Time Range Age' type.
  44. if($bType && in_array($this->aInputs[$sName]['type'], array('datepicker_range_age', 'datetime_range_age'))) {
  45. $bTypeDateTime = $this->aInputs[$sName]['type'] == 'datetime_range_age';
  46. $sMethod = $this->aFormAttrs['method'];
  47. $sValue = self::getSubmittedValue($sName, $sMethod);
  48. if(!empty($sValue) && is_string($sValue)) {
  49. $aMatches = array();
  50. if(!preg_match("/^([0-9]+)-([0-9]+)$/i", $sValue, $aMatches))
  51. return array();
  52. $aArgs = array("%s-%s-%s", date('Y'), date('m'), date('d'));
  53. if($bTypeDateTime) {
  54. $aArgs[0] = "%s-%s-%s %s:%s:%s";
  55. $aArgs = array_merge($aArgs, array(date('H'), date('i'), date('s')));
  56. }
  57. $aArgsFrom = $aArgs;
  58. $aArgsFrom[1] -= ($aMatches[2] + 1);
  59. if($bTypeDateTime)
  60. $aArgsFrom[6] += 1;
  61. else
  62. $aArgsFrom[3] += 1;
  63. $aArgsTo = $aArgs;
  64. $aArgsTo[1] -= $aMatches[1];
  65. self::setSubmittedValue($sName, array(
  66. call_user_func_array('sprintf', $aArgsFrom),
  67. call_user_func_array('sprintf', $aArgsTo)
  68. ), $sMethod);
  69. }
  70. }
  71. return parent::getCleanValue($sName);
  72. }
  73. public function genInput(&$aInput)
  74. {
  75. switch($aInput['type'])
  76. {
  77. case 'text_range':
  78. case 'datepicker_range':
  79. case 'datetime_range':
  80. $bValue = !empty($aInput['value']) && is_array($aInput['value']);
  81. $aInput['name'] .= '[]';
  82. $aInput['type'] = str_replace('_range', '', $aInput['type']);
  83. if(!isset($aInput['attrs_wrapper']['class']))
  84. $aInput['attrs_wrapper']['class'] = '';
  85. $aInput['attrs_wrapper']['class'] .= ' range';
  86. $aSubInputs = array($aInput, $aInput);
  87. foreach($aSubInputs as $iKey => $aSubInput) {
  88. if($bValue && isset($aInput['value'][$iKey]))
  89. $aSubInput['value'] = $aInput['value'][$iKey];
  90. $aSubInputs[$iKey] = $this->genInputStandard($aSubInput);
  91. }
  92. return implode(' - ', $aSubInputs);
  93. case 'datepicker_range_age':
  94. case 'datetime_range_age':
  95. $iMin = $this->_iAgeMin;
  96. $iMax = $this->_iAgeMax;
  97. $aInput['type'] = 'doublerange';
  98. if(empty($aInput['value']))
  99. $aInput['value'] = $iMin . '-' . $iMax;
  100. if (!isset($aInput['attrs']['min']) && !isset($aInput['attrs']['max'])){
  101. $aAttrs = array('min' => $iMin, 'max' => $iMax, 'step' => 1);
  102. if(!empty($aInput['attrs']) && is_array($aInput['attrs']))
  103. $aInput['attrs'] = array_merge($aInput['attrs'], $aAttrs);
  104. else
  105. $aInput['attrs'] = $aAttrs;
  106. }
  107. return $this->genInputStandard($aInput);
  108. case 'location_radius':
  109. return $this->genInputLocationRadius($aInput);
  110. }
  111. return parent::genInput($aInput);
  112. }
  113. public function genInputLocation(&$aInput)
  114. {
  115. $aInput['manual_input'] = true;
  116. return parent::genInputLocation($aInput);
  117. }
  118. protected function genCustomInputAuthor($aInput)
  119. {
  120. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . 'searchExtended.php?action=get_authors';
  121. return $this->genCustomInputUsernamesSuggestions($aInput);
  122. }
  123. public function genInputLocationRadius(&$aInput)
  124. {
  125. $aInput['manual_input'] = true;
  126. $aInputRadius = $aInput;
  127. $aInputRadius['type'] = 'text';
  128. $aInputRadius['name'] = $aInputRadius['name'] . '_rad';
  129. $sValue = bx_get($aInputRadius['name']);
  130. $aInputRadius['value'] = is_numeric($sValue) ? $sValue : '';
  131. $aInputRadius['attrs']['placeholder'] = _t('_sys_form_input_location_radius_label');
  132. return $this->oTemplate->parseHtmlByName('form_field_location_radius.html', array (
  133. 'location_input' => parent::genInputLocation($aInput),
  134. 'radius_input' => parent::genInputStandard($aInputRadius),
  135. ));
  136. }
  137. function addCssJsCore ()
  138. {
  139. parent::addCssJsCore();
  140. $this->_addCss('search_extended.css');
  141. }
  142. }
  143. /** @} */