BxDolLocationFieldGoogle.php 3.2 KB

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