BxBaseSearchExtendedForm.php 4.2 KB

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