Address.class.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * Define a address.
  4. * @author Valentin CARRUESCO
  5. * @category Plugin
  6. * @license copyright
  7. */
  8. class Address extends Entity{
  9. public $id,$entity_id,$entity,$label,$type,$street,$complement,$city,$zip,$country,$state;
  10. public $fields =
  11. array(
  12. 'id' => 'key',
  13. 'entity_id' => 'int',
  14. 'entity' => 'string',
  15. 'label' => 'string',
  16. 'type' => 'string',
  17. 'street' => 'string',
  18. 'complement' => 'string',
  19. 'city' => 'string',
  20. 'zip' => 'string',
  21. 'country' => 'string',
  22. 'state' => 'string'
  23. );
  24. public function mapUrl(){
  25. $encoded = urlencode($this->street).', '.urlencode($this->zip).' '.urlencode($this->city);
  26. return 'https://www.google.com/maps/place/'.$encoded;
  27. }
  28. //retourne l'adresse sur une seule ligne au format street, complement, zip city country
  29. public function fullName(){
  30. if($this->id==0) return '';
  31. $fullname = '';
  32. if(!empty($this->street)) $fullname .= $this->street;
  33. if(!empty($this->complement)) $fullname .= ', '.$this->complement;
  34. if($fullname!='') $fullname .= ', ';
  35. if(!empty($this->zip)) $fullname .= $this->zip;
  36. if(!empty($this->city)) $fullname .= ' '.$this->city;
  37. if(!empty($this->country)) $fullname .= ' '.$this->country;
  38. return $fullname;
  39. }
  40. //remplis un composant location à partir des infos de la classe courante
  41. public function toDataAttributes($plainText = true){
  42. $array = array();
  43. $plain = '';
  44. foreach (array('street','complement','city','zip','country') as $key) {
  45. $array[$key] = $this->$key;
  46. $plain = ' data-'.$key.' = "'.(empty($this->$key) ? '' : $this->$key).'"';
  47. }
  48. return !$plainText ? $array : $plain;
  49. }
  50. }
  51. ?>