X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Faddress.php;h=a834a1dccf40cd6390bdfb1be40d295d22c7f67a;hb=7ea0c31bce93dddcd4999c1171071cdd9469c022;hp=3be8b91063375849b15aa1d77d175741b9f36501;hpb=d3ce1117c43e2463f109c8f0b82b8aeee42407db;p=platal.git diff --git a/classes/address.php b/classes/address.php index 3be8b91..a834a1d 100644 --- a/classes/address.php +++ b/classes/address.php @@ -364,7 +364,7 @@ class Address return $this->phones; } - public function addPhone(Phone &$phone) + public function addPhone(Phone $phone) { if ($phone->linkType() == Phone::LINK_ADDRESS && $phone->pid() == $this->pid) { $this->phones[$phone->uniqueId()] = $phone; @@ -584,9 +584,14 @@ class Address } } $this->text = trim($this->text); + $this->phones = Phone::formatFormArray($this->phones, $this->error, new ProfileVisibility($this->pub)); if ($this->removed == 1) { - $this->text = ''; - return true; + if (!S::user()->checkPerms('directory_private') && Phone::hasPrivate($this->phones)) { + Platal::page()->trigWarning("L'adresse ne peut être supprimée car elle contient des informations pour lesquelles vous n'avez le droit d'édition."); + } else { + $this->text = ''; + return true; + } } if ($format['requireGeocoding'] || $this->changed == 1) { @@ -596,20 +601,19 @@ class Address $this->error = !empty($this->geocodedText); } if ($format['stripGeocoding'] || ($this->type == self::LINK_COMPANY && $this->error) || $this->geocodeChosen === '0') { - $gmapsGeocoder = new GMapsGeocoder(); - $gmapsGeocoder->stripGeocodingFromAddress($this); if ($this->geocodeChosen === '0') { $mailer = new PlMailer('profile/geocoding.mail.tpl'); $mailer->assign('text', $this->text); $mailer->assign('geoloc', $this->geocodedText); $mailer->send(); } + $gmapsGeocoder = new GMapsGeocoder(); + $gmapsGeocoder->stripGeocodingFromAddress($this); } if ($this->countryId == '') { $this->countryId = null; } $this->geocodeChosen = null; - $this->phones = Phone::formatFormArray($this->phones, $this->error, new ProfileVisibility($this->pub)); if ($format['postalText']) { $this->formatPostalAddress(); } @@ -719,13 +723,13 @@ class Address Geocoder::getAreaId($this, $area); } - XDB::execute('INSERT INTO profile_addresses (pid, jobid, type, id, flags, accuracy, - text, postalText, postalCode, localityId, - subAdministrativeAreaId, administrativeAreaId, - countryId, latitude, longitude, pub, comment, - north, south, east, west) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, - {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT IGNORE INTO profile_addresses (pid, jobid, type, id, flags, accuracy, + text, postalText, postalCode, localityId, + subAdministrativeAreaId, administrativeAreaId, + countryId, latitude, longitude, pub, comment, + north, south, east, west) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, + {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $this->pid, $this->jobid, $this->type, $this->id, $this->flags, $this->accuracy, $this->text, $this->postalText, $this->postalCode, $this->localityId, $this->subAdministrativeAreaId, $this->administrativeAreaId, @@ -826,7 +830,9 @@ class Address } } - return self::formArrayWalk($data, 'toFormArray', $success, true); + $addresses = self::formArrayWalk($data, 'toFormArray', $success, true); + usort($addresses, 'ProfileVisibility::comparePublicity'); + return $addresses; } static public function formArrayToString(array $data) @@ -834,6 +840,16 @@ class Address return implode(', ', self::formArrayWalk($data, 'toString')); } + static public function hasPrivate(array $addresses) + { + foreach ($addresses as $address) { + if ($address['pub'] == 'private') { + return true; + } + } + return false; + } + static public function iterate(array $pids = array(), array $types = array(), array $jobids = array(), array $pubs = array()) {