* @param $data: an array of form formatted addresses.
* @param $pid, $type, $linkid: pid, type and id concerned by the update.
*/
- static public function saveFromArray(array $data, $pid, $type = self::LINK_PROFILE, $linkid = null)
+ static public function saveFromArray(array $data, $pid, $type = self::LINK_PROFILE, $linkid = null, $savePrivate = true)
{
foreach ($data as $id => $value) {
- if (!is_null($linkid)) {
- $value['id'] = $linkid;
- } else {
- $value['id'] = $id;
- }
- if (!is_null($pid)) {
- $value['pid'] = $pid;
- }
- if (!is_null($type)) {
- $value['type'] = $type;
+ if ($value['pub'] != 'private' || $savePrivate) {
+ if (!is_null($linkid)) {
+ $value['id'] = $linkid;
+ } else {
+ $value['id'] = $id;
+ }
+ if (!is_null($pid)) {
+ $value['pid'] = $pid;
+ }
+ if (!is_null($type)) {
+ $value['type'] = $type;
+ }
+ $address = new Address($value);
+ $address->save();
}
- $address = new Address($value);
- $address->save();
}
}
public function save(ProfilePage &$page, $field, $value)
{
- Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS, null, S::user()->isMe($page->owner) || S::admin());
- Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, S::user()->isMe($page->owner) || S::admin());
- Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE);
+ $deletePrivate = S::user()->isMe($page->owner) || S::admin();
+
+ Phone::deletePhones($page->pid(), Phone::LINK_ADDRESS, null, $deletePrivate);
+ Address::deleteAddresses($page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
+ Address::saveFromArray($value, $page->pid(), Address::LINK_PROFILE, null, $deletePrivate);
if (S::user()->isMe($page->owner) && count($value) > 1) {
Platal::page()->trigWarning('Attention, tu as plusieurs adresses sur ton profil. Pense à supprimer celles qui sont obsolètes.');
}
Phone::deletePhones($page->pid(), Phone::LINK_JOB, null, $deletePrivate);
$terms_values = array();
foreach ($value as $id => &$job) {
- if (isset($job['name']) && $job['name']) {
+ if (($job['pub'] != 'private' || $deletePrivate) && (isset($job['name']) && $job['name'])) {
if (isset($job['jobid']) && $job['jobid']) {
XDB::execute('INSERT INTO profile_job (pid, id, description, email,
url, pub, email_pub, jobid)