From: Stéphane Jacob Date: Wed, 8 Dec 2010 20:04:07 +0000 (+0100) Subject: Uses ProfileVisibility to check publicity. X-Git-Tag: xorg/1.0.2~90 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=e7027060f9c8209b3d5f2a82b94f5dc70fc91edc;p=platal.git Uses ProfileVisibility to check publicity. Signed-off-by: Stéphane Jacob --- diff --git a/classes/address.php b/classes/address.php index 3d00c2b..067a505 100644 --- a/classes/address.php +++ b/classes/address.php @@ -588,7 +588,7 @@ class Address $this->countryId = null; } $this->geocodeChosen = null; - $this->phones = Phone::formatFormArray($this->phones, $this->error, $this->pub); + $this->phones = Phone::formatFormArray($this->phones, $this->error, new ProfileVisibility($this->pub)); if ($format['postalText']) { $this->formatPostalAddress(); } diff --git a/classes/phone.php b/classes/phone.php index 95a72ad..7dd4a4b 100644 --- a/classes/phone.php +++ b/classes/phone.php @@ -351,27 +351,21 @@ class Phone static private function formArrayWalk(array $data, $function, &$success = true, $requiresEmptyPhone = false, $maxPublicity = null) { - static $publicity = array('private' => 0, 'ax' => 1, 'public' => 2); - $phones = array(); foreach ($data as $item) { $phone = new Phone($item); $success = (!$phone->error && ($phone->format() || $phone->isEmpty()) && $success); if (!$phone->isEmpty()) { - if (!is_null($maxPublicity) && array_key_exists($maxPublicity, $publicity)) { - if ($publicity[$phone->pub] > $publicity[$maxPublicity]) { - $phone->pub = $maxPublicity; - } + if (!is_null($maxPublicity) && $maxPublicity->isVisible($phone->pub)) { + $phone->pub = $maxPublicity->level(); } $phones[] = call_user_func(array($phone, $function)); } } if (count($phones) == 0 && $requiresEmptyPhone) { $phone = new Phone(); - if (!is_null($maxPublicity) && array_key_exists($maxPublicity, $publicity)) { - if ($publicity[$phone->pub] > $publicity[$maxPublicity]) { - $phone->pub = $maxPublicity; - } + if (!is_null($maxPublicity) && $maxPublicity->isVisible($phone->pub)) { + $phone->pub = $maxPublicity->level(); } $phones[] = call_user_func(array($phone, $function)); } diff --git a/modules/profile/jobs.inc.php b/modules/profile/jobs.inc.php index e054404..4726e94 100644 --- a/modules/profile/jobs.inc.php +++ b/modules/profile/jobs.inc.php @@ -131,10 +131,8 @@ class ProfileSettingJob implements ProfileSetting return $jobs; } - private function cleanJob(ProfilePage &$page, $jobid, array &$job, &$success) + private function cleanJob(ProfilePage &$page, $jobid, array &$job, &$success, $maxPublicity) { - static $publicity = array('private' => 0, 'ax' => 1, 'public' => 2); - if ($job['w_email'] == "new@example.org") { $job['w_email'] = $job['w_email_new']; } @@ -184,11 +182,10 @@ class ProfileSettingJob implements ProfileSetting } } - if ($publicity[$job['w_email_pub']] > $publicity[$job['pub']]) { - $job['w_email_pub'] = $job['pub']; + if ($maxPublicity->isVisible($job['w_email_pub'])) { + $job['w_email_pub'] = $maxPublicity->level(); } - - $job['w_phone'] = Phone::formatFormArray($job['w_phone'], $s, $job['pub']); + $job['w_phone'] = Phone::formatFormArray($job['w_phone'], $s, $maxPublicity); unset($job['removed']); unset($job['new']); @@ -198,8 +195,6 @@ class ProfileSettingJob implements ProfileSetting public function value(ProfilePage &$page, $field, $value, &$success) { - static $publicity = array('private' => 0, 'ax' => 1, 'public' => 2); - $entreprise = ProfileValidate::get_typed_requests($page->pid(), 'entreprise'); $entr_val = 0; @@ -243,11 +238,12 @@ class ProfileSettingJob implements ProfileSetting foreach ($value as $key => &$job) { $address = new Address($job['w_address']); $s = $address->format(); - if ($publicity[$address->pub] > $publicity[$job['pub']]) { - $address->pub = $job['pub']; + $maxPublicity = new ProfileVisibility($job['pub']); + if ($maxPublicity->isVisible($address->pub)) { + $address->pub = $maxPublicity->level(); } $job['w_address'] = $address->toFormArray(); - $this->cleanJob($page, $key, $job, $s); + $this->cleanJob($page, $key, $job, $s, $maxPublicity); if (!$init) { $success = ($success && $s); }