BxBaseSearchExtendedForm.php 4.3 KB

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