Uses ProfileVisibility to check publicity.
authorStéphane Jacob <sj@m4x.org>
Wed, 8 Dec 2010 20:04:07 +0000 (21:04 +0100)
committerStéphane Jacob <sj@m4x.org>
Wed, 8 Dec 2010 20:04:21 +0000 (21:04 +0100)
Signed-off-by: Stéphane Jacob <sj@m4x.org>
classes/address.php
classes/phone.php
modules/profile/jobs.inc.php

index 3d00c2b..067a505 100644 (file)
@@ -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();
         }
index 95a72ad..7dd4a4b 100644 (file)
@@ -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));
         }
index e054404..4726e94 100644 (file)
@@ -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);
             }