BxDolLocationField.php 2.6 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. /**
  10. * This class allow different implementations for location field.
  11. *
  12. * Add record to sys_objects_location_field table, like you are doing this for Comments or Voting objects:
  13. * - object: your object name, usually it is in the following format - vendor prefix, underscore, module prefix;
  14. * - module: module name
  15. * - title: translatable title
  16. * - class_name: user defined class name which is derived from BxDolLocationField.
  17. * - class_file: the location of the user defined class, leave it empty if class is located in system folders.
  18. */
  19. class BxDolLocationField extends BxDolFactoryObject
  20. {
  21. protected function __construct($aObject)
  22. {
  23. parent::__construct($aObject, null, 'BxDolLocationFieldQuery');
  24. }
  25. /**
  26. * Get object instance by object name
  27. * @param $sObject object name
  28. * @return object instance or false on error
  29. */
  30. public static function getObjectInstance($sObject)
  31. {
  32. return parent::getObjectInstanceByClassNames($sObject, null, 'BxDolLocationField', 'BxDolLocationFieldQuery');
  33. }
  34. public function genInputLocation (&$aInput, $oForm)
  35. {
  36. // override this
  37. return 'not implemented';
  38. }
  39. public function getLocationVal ($aInput, $sIndex, $oForm)
  40. {
  41. $aSpecificValues = $oForm->getSpecificValues();
  42. $s = $aInput['name'] . '_' . $sIndex;
  43. if (isset($aSpecificValues[$s]))
  44. return $aSpecificValues[$s];
  45. return $oForm->getCleanValue($s);
  46. }
  47. public function setLocationVals ($aInput, $aVals, $oForm)
  48. {
  49. $oForm->setSpecificValue($aInput['name'] . '_lat', $aVals['lat']);
  50. $oForm->setSpecificValue($aInput['name'] . '_lng', $aVals['lng']);
  51. $oForm->setSpecificValue($aInput['name'] . '_country', $aVals['country']);
  52. $oForm->setSpecificValue($aInput['name'] . '_state', $aVals['state']);
  53. $oForm->setSpecificValue($aInput['name'] . '_city', $aVals['city']);
  54. $oForm->setSpecificValue($aInput['name'] . '_zip', $aVals['zip']);
  55. $oForm->setSpecificValue($aInput['name'] . '_street', $aVals['street']);
  56. $oForm->setSpecificValue($aInput['name'] . '_street_number', $aVals['street_number']);
  57. return true;
  58. }
  59. public function setLocationVal ($aInput, $sIndex, $sVal, $oForm)
  60. {
  61. $s = $aInput['name'] . '_' . $sIndex;
  62. $oForm->setSpecificValue($s, $sVal);
  63. return true;
  64. }
  65. }
  66. /** @} */