BxDolLocationFieldGoogle.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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_undefined'),
  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 ($aVars['country']) {
  47. $aCountries = BxDolFormQuery::getDataItems('Country');
  48. $s = ($aVars['street_number'] ? $aVars['street_number'] . ', ' : '') . ($aVars['street'] ? $aVars['street'] . ', ' : '') . ($aVars['city'] ? $aVars['city'] . ', ' : '') . ($aVars['state'] ? $aVars['state'] . ', ' : '') . $aCountries[$aVars['country']];
  49. $aVars['bx_if:auto_input']['content']['location_string'] = $s;
  50. }
  51. if ($isManualInput) {
  52. $aAttrs = empty($aInput['attrs']) ? array() : $aInput['attrs'];
  53. $aInput['type'] = 'text';
  54. $aInput['attrs']['id'] = $sIdInput;
  55. $aInput['attrs'] = array_merge($aAttrs, $aInput['attrs']);
  56. $aVars['input'] = $oForm->genInputStandard($aInput);
  57. }
  58. else {
  59. if ($this->getLocationVal($aInput, 'lat', $oForm) && $this->getLocationVal($aInput, 'lng', $oForm))
  60. $aInput['checked'] = true;
  61. else
  62. $aInput['checked'] = $oForm->getCleanValue($aInput['name'] . '_lat') && $oForm->getCleanValue($aInput['name'] . '_lng') ? 1 : 0;
  63. $aVars['input'] = $oForm->genInputSwitcher($aInput);
  64. }
  65. return $aVars;
  66. }
  67. }
  68. /** @} */