BxBaseSearchExtendedForm.php 5.9 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. //--- Process field with 'Location Radius' type.
  34. if($bType && $this->aInputs[$sName]['type'] == 'location_radius') {
  35. $aLocation = BxDolMetatags::locationsRetrieveFromForm($sName, $this);
  36. $aLocation[] = (int)$this->getLocationVal($this->aInputs[$sName], 'rad');
  37. return array(
  38. 'string' => parent::getCleanValue($sName),
  39. 'array' => $aLocation
  40. );
  41. }
  42. //--- Process field with 'Date Range Age' and 'Date-Time Range Age' type.
  43. if($bType && in_array($this->aInputs[$sName]['type'], array('datepicker_range_age', 'datetime_range_age'))) {
  44. $bTypeDateTime = $this->aInputs[$sName]['type'] == 'datetime_range_age';
  45. $sMethod = $this->aFormAttrs['method'];
  46. $sValue = self::getSubmittedValue($sName, $sMethod);
  47. if(!empty($sValue) && is_string($sValue)) {
  48. $aMatches = array();
  49. if(!preg_match("/^([0-9]+)-([0-9]+)$/i", $sValue, $aMatches))
  50. return array();
  51. $aArgs = array("%s-%s-%s", date('Y'), date('m'), date('d'));
  52. if($bTypeDateTime) {
  53. $aArgs[0] = "%s-%s-%s %s:%s:%s";
  54. $aArgs = array_merge($aArgs, array(date('H'), date('i'), date('s')));
  55. }
  56. $aArgsFrom = $aArgs;
  57. $aArgsFrom[1] -= ($aMatches[2] + 1);
  58. if($bTypeDateTime)
  59. $aArgsFrom[6] += 1;
  60. else
  61. $aArgsFrom[3] += 1;
  62. $aArgsTo = $aArgs;
  63. $aArgsTo[1] -= $aMatches[1];
  64. self::setSubmittedValue($sName, array(
  65. call_user_func_array('sprintf', $aArgsFrom),
  66. call_user_func_array('sprintf', $aArgsTo)
  67. ), $sMethod);
  68. }
  69. }
  70. return parent::getCleanValue($sName);
  71. }
  72. public function genInput(&$aInput)
  73. {
  74. switch($aInput['type'])
  75. {
  76. case 'text_range':
  77. case 'datepicker_range':
  78. case 'datetime_range':
  79. $bValue = !empty($aInput['value']) && is_array($aInput['value']);
  80. $aInput['name'] .= '[]';
  81. $aInput['type'] = str_replace('_range', '', $aInput['type']);
  82. if(!isset($aInput['attrs_wrapper']['class']))
  83. $aInput['attrs_wrapper']['class'] = '';
  84. $aInput['attrs_wrapper']['class'] .= ' range';
  85. $aSubInputs = array($aInput, $aInput);
  86. foreach($aSubInputs as $iKey => $aSubInput) {
  87. if($bValue && isset($aInput['value'][$iKey]))
  88. $aSubInput['value'] = $aInput['value'][$iKey];
  89. $aSubInputs[$iKey] = $this->genInputStandard($aSubInput);
  90. }
  91. return implode(' - ', $aSubInputs);
  92. case 'datepicker_range_age':
  93. case 'datetime_range_age':
  94. $iMin = $this->_iAgeMin;
  95. $iMax = $this->_iAgeMax;
  96. $aInput['type'] = 'doublerange';
  97. if(empty($aInput['value']))
  98. $aInput['value'] = $iMin . '-' . $iMax;
  99. if (!isset($aInput['attrs']['min']) && !isset($aInput['attrs']['max'])){
  100. $aAttrs = array('min' => $iMin, 'max' => $iMax, 'step' => 1);
  101. if(!empty($aInput['attrs']) && is_array($aInput['attrs']))
  102. $aInput['attrs'] = array_merge($aInput['attrs'], $aAttrs);
  103. else
  104. $aInput['attrs'] = $aAttrs;
  105. }
  106. return $this->genInputStandard($aInput);
  107. case 'location_radius':
  108. return $this->genInputLocationRadius($aInput);
  109. }
  110. return parent::genInput($aInput);
  111. }
  112. public function genInputLocation(&$aInput)
  113. {
  114. $aInput['manual_input'] = true;
  115. return parent::genInputLocation($aInput);
  116. }
  117. protected function genCustomInputAuthor($aInput)
  118. {
  119. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . 'searchExtended.php?action=get_authors';
  120. return $this->genCustomInputUsernamesSuggestions($aInput);
  121. }
  122. public function genInputLocationRadius(&$aInput)
  123. {
  124. $aInput['manual_input'] = true;
  125. $aInputRadius = $aInput;
  126. $aInputRadius['type'] = 'text';
  127. $aInputRadius['name'] = $aInputRadius['name'] . '_rad';
  128. $aInputRadius['value'] = $this->getLocationVal($aInput, 'rad');
  129. $aInputRadius['attrs']['placeholder'] = _t('_sys_form_input_location_radius_label');
  130. return $this->oTemplate->parseHtmlByName('form_field_location_radius.html', array (
  131. 'location_input' => parent::genInputLocation($aInput),
  132. 'radius_input' => parent::genInputStandard($aInputRadius),
  133. ));
  134. }
  135. function addCssJsCore ()
  136. {
  137. parent::addCssJsCore();
  138. $this->_addCss('search_extended.css');
  139. }
  140. }
  141. /** @} */