BxDolLocationFieldGoogle.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 UnaCore UNA Core
  7. * @{
  8. */
  9. class BxDolLocationFieldGoogle extends BxDolLocationField
  10. {
  11. public function genInputLocation (&$aInput, $oForm)
  12. {
  13. $aVars = $this->_getInputLocationVars($aInput, $oForm);
  14. return $oForm->getTemplate()->parseHtmlByName('location_field_google.html', $aVars);
  15. }
  16. protected function _getInputLocationVars(&$aInput, $oForm)
  17. {
  18. $isManualInput = (int)(isset($aInput['manual_input']) && $aInput['manual_input']);
  19. $sIdStatus = $oForm->getInputId($aInput) . '_status';
  20. $sIdInput = $oForm->getInputId($aInput) . '_location';
  21. $aVars = array (
  22. 'key' => trim(getParam('sys_maps_api_key')),
  23. 'lang' => bx_lang_name(),
  24. 'name' => $aInput['name'],
  25. 'id_status' => $sIdStatus,
  26. 'id_input' => $sIdInput,
  27. 'manual_input' => $isManualInput,
  28. 'bx_if:manual_input' => array(
  29. 'condition' => $isManualInput,
  30. 'content' => array(),
  31. ),
  32. 'bx_if:auto_input' => array(
  33. 'condition' => !$isManualInput,
  34. 'content' => array(
  35. 'id_status' => $sIdStatus,
  36. 'location_string' => _t('_sys_location_field_label'),
  37. ),
  38. ),
  39. 'api_field_name_short' => 'short_name',
  40. 'api_field_name_long' => 'long_name',
  41. 'api_field_name_2_length' => json_encode(array()),
  42. );
  43. $aLocationIndexes = BxDolForm::$LOCATION_INDEXES;
  44. foreach ($aLocationIndexes as $sKey)
  45. $aVars[$sKey] = $this->getLocationVal($aInput, $sKey, $oForm);
  46. if ($isManualInput) {
  47. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  48. $aInput2 = $aInput;
  49. $aInput2['type'] = 'text';
  50. $aInput2['attrs']['id'] = $sIdInput;
  51. $aInput2['attrs'] = array_merge($aAttrs, $aInput2['attrs']);
  52. $aVars['input'] = $oForm->genInputStandard($aInput2);
  53. }
  54. else {
  55. if ($this->getLocationVal($aInput, 'lat', $oForm) && $this->getLocationVal($aInput, 'lng', $oForm))
  56. $aInput['checked'] = true;
  57. else
  58. $aInput['checked'] = $oForm->getCleanValue($aInput['name'] . '_lat') && $oForm->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  59. $aVars['input'] = $oForm->genInputSwitcher($aInput);
  60. $sLocationString = _t($aInput['checked'] ? '_sys_location_undefined' : '_sys_location_field_label');
  61. if ($aVars['country']) {
  62. $aCountries = BxDolFormQuery::getDataItems('Country');
  63. $sLocationString = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  64. }
  65. $aVars['bx_if:auto_input']['content']['location_string'] = $sLocationString;
  66. }
  67. return $aVars;
  68. }
  69. }
  70. /** @} */