BxBaseSearchExtendedForm.php 3.8 KB

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