BxBaseSearchExtendedForm.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 BxDolMetatags::locationsRetrieveFromForm($sName, $this);
  30. //--- Process field with 'Date Range Age' and 'Date-Time Range Age' type.
  31. if($bType && in_array($this->aInputs[$sName]['type'], array('datepicker_range_age', 'datetime_range_age'))) {
  32. $bTypeDateTime = $this->aInputs[$sName]['type'] == 'datetime_range_age';
  33. $sMethod = $this->aFormAttrs['method'];
  34. $sValue = self::getSubmittedValue($sName, $sMethod);
  35. $aMatches = array();
  36. if(!preg_match("/^([0-9]+)-([0-9]+)$/i", $sValue, $aMatches))
  37. return array();
  38. $aArgs = array("%s-%s-%s", date('Y'), date('m'), date('d'));
  39. if($bTypeDateTime) {
  40. $aArgs[0] = "%s-%s-%s %s:%s:%s";
  41. $aArgs = array_merge($aArgs, array(date('H'), date('i'), date('s')));
  42. }
  43. $aArgsFrom = $aArgs;
  44. $aArgsFrom[1] -= ($aMatches[2] + 1);
  45. if($bTypeDateTime)
  46. $aArgsFrom[6] += 1;
  47. else
  48. $aArgsFrom[3] += 1;
  49. $aArgsTo = $aArgs;
  50. $aArgsTo[1] -= $aMatches[1];
  51. self::setSubmittedValue($sName, array(
  52. call_user_func_array('sprintf', $aArgsFrom),
  53. call_user_func_array('sprintf', $aArgsTo)
  54. ), $sMethod);
  55. }
  56. return parent::getCleanValue($sName);
  57. }
  58. public function genInput(&$aInput)
  59. {
  60. switch($aInput['type'])
  61. {
  62. case 'datepicker_range':
  63. case 'datetime_range':
  64. $bValue = !empty($aInput['value']) && is_array($aInput['value']);
  65. $aInput['name'] .= '[]';
  66. $aInput['type'] = str_replace('_range', '', $aInput['type']);
  67. $aSubInputs = array($aInput, $aInput);
  68. foreach($aSubInputs as $iKey => $aSubInput) {
  69. if($bValue && isset($aInput['value'][$iKey]))
  70. $aSubInput['value'] = $aInput['value'][$iKey];
  71. $aSubInputs[$iKey] = $this->genInputStandard($aSubInput);
  72. }
  73. return implode(' - ', $aSubInputs);
  74. case 'datepicker_range_age':
  75. case 'datetime_range_age':
  76. $iMin = $this->_iAgeMin;
  77. $iMax = $this->_iAgeMax;
  78. $aInput['type'] = 'doublerange';
  79. if(empty($aInput['value']))
  80. $aInput['value'] = $iMin . '-' . $iMax;
  81. $aAttrs= array('min' => $iMin, 'max' => $iMax, 'step' => 1);
  82. if(!empty($aInput['attrs']) && is_array($aInput['attrs']))
  83. $aInput['attrs'] = array_merge($aInput['attrs'], $aAttrs);
  84. else
  85. $aInput['attrs'] = $aAttrs;
  86. return $this->genInputStandard($aInput);
  87. }
  88. return parent::genInput($aInput);
  89. }
  90. public function genInputLocation(&$aInput)
  91. {
  92. $aInput['manual_input'] = true;
  93. return parent::genInputLocation($aInput);
  94. }
  95. protected function genCustomInputAuthor($aInput)
  96. {
  97. $aInput['ajax_get_suggestions'] = BX_DOL_URL_ROOT . 'searchExtended.php?action=get_authors';
  98. return $this->genCustomInputUsernamesSuggestions($aInput);
  99. }
  100. }
  101. /** @} */