Add options to profile->getPhones to allow filtering
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 21 Jun 2010 19:03:34 +0000 (21:03 +0200)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 21 Jun 2010 19:22:26 +0000 (21:22 +0200)
Filter by phone type or by link (job/address/...)

Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/profile.php
include/profilefields.inc.php
templates/profile/profile.tpl

index 740eeb3..9352029 100644 (file)
@@ -111,27 +111,40 @@ class Profile
             self::FIRSTNAME => array(self::VN_ORDINARY, self::VN_INI, self::VN_OTHER)
         );
 
-    const ADDRESS_MAIN       = 0x000001;
-    const ADDRESS_PERSO      = 0x000002;
-    const ADDRESS_PRO        = 0x000004;
-    const ADDRESS_ALL        = 0x000006;
-    const ADDRESS_POSTAL     = 0x000008;
-
-    const EDUCATION_MAIN     = 0x000010;
-    const EDUCATION_EXTRA    = 0x000020;
-    const EDUCATION_ALL      = 0x000040;
-    const EDUCATION_FINISHED = 0x000080;
-    const EDUCATION_CURRENT  = 0x000100;
-
-    const JOBS_MAIN          = 0x001000;
-    const JOBS_ALL           = 0x002000;
-    const JOBS_FINISHED      = 0x004000;
-    const JOBS_CURRENT       = 0x008000;
-
-    const NETWORKING_ALL     = 0x000000;
-    const NETWORKING_WEB     = 0x010000;
-    const NETWORKING_IM      = 0x020000;
-    const NETWORKING_SOCIAL  = 0x040000;
+    const ADDRESS_MAIN       = 0x00000001;
+    const ADDRESS_PERSO      = 0x00000002;
+    const ADDRESS_PRO        = 0x00000004;
+    const ADDRESS_ALL        = 0x00000006;
+    const ADDRESS_POSTAL     = 0x00000008;
+
+    const EDUCATION_MAIN     = 0x00000010;
+    const EDUCATION_EXTRA    = 0x00000020;
+    const EDUCATION_ALL      = 0x00000040;
+    const EDUCATION_FINISHED = 0x00000080;
+    const EDUCATION_CURRENT  = 0x00000100;
+
+    const JOBS_MAIN          = 0x00001000;
+    const JOBS_ALL           = 0x00002000;
+    const JOBS_FINISHED      = 0x00004000;
+    const JOBS_CURRENT       = 0x00008000;
+
+    const NETWORKING_ALL     = 0x00000000;
+    const NETWORKING_WEB     = 0x00010000;
+    const NETWORKING_IM      = 0x00020000;
+    const NETWORKING_SOCIAL  = 0x00040000;
+
+    const PHONE_LINK_JOB     = 0x00100000;
+    const PHONE_LINK_ADDRESS = 0x00200000;
+    const PHONE_LINK_PROFILE = 0x00400000;
+    const PHONE_LINK_COMPANY = 0x00800000;
+    const PHONE_LINK_ANY     = 0x00F00000;
+
+    const PHONE_TYPE_FAX     = 0x01000000;
+    const PHONE_TYPE_FIXED   = 0x02000000;
+    const PHONE_TYPE_MOBILE  = 0x04000000;
+    const PHONE_TYPE_ANY     = 0x07000000;
+
+    const PHONE_ANY          = 0x07F00000;
 
     const FETCH_ADDRESSES      = 0x000001;
     const FETCH_CORPS          = 0x000002;
index ffff5ad..c456d04 100644 (file)
@@ -151,6 +151,42 @@ class Phone
             $this->$key = $val;
         }
     }
+
+    public function hasFlags($flags) {
+        return $this->hasType($flags) && $this->hasLink($flags);
+    }
+
+    /** Returns true if this phone's type matches the flags
+     */
+    public function hasType($flags) {
+        $flags = $flags & Profile::PHONE_TYPE_ANY;
+        return (
+            ($flags == Profile::PHONE_TYPE_ANY)
+            ||
+            (($flags & Profile::PHONE_TYPE_FAX) && $this->type == self::TYPE_FAX)
+            ||
+            (($flags & Profile::PHONE_TYPE_FIXED) && $this->type == self::TYPE_FIXED)
+            ||
+            (($flags & Profile::PHONE_TYPE_MOBILE) && $this->type == self::TYPE_MOBILE)
+        );
+    }
+
+    /** Returns true if this phone's link matches the flags
+     */
+    public function hasLink($flags) {
+        $flags = $flags & Profile::PHONE_LINK_ANY;
+        return (
+            ($flags == Profile::PHONE_LINK_ANY)
+            ||
+            (($flags & Profile::PHONE_LINK_COMPANY) && $this->link_type == self::LINK_COMPANY)
+            ||
+            (($flags & Profile::PHONE_LINK_JOB) && $this->link_type == self::LINK_JOB)
+            ||
+            (($flags & Profile::PHONE_LINK_ADDRESS) && $this->link_type == self::LINK_ADDRESS)
+            ||
+            (($flags & Profile::PHONE_LINK_PROFILE) && $this->link_type == self::LINK_PROFILE)
+        );
+    }
 }
 // }}}
 // {{{ class Company
@@ -665,10 +701,12 @@ class ProfilePhones extends ProfileField
         $phones = array();
         $nb = 0;
         foreach ($this->phones as $id => $phone) {
-            $phones[$id] = $phone;
-            ++$nb;
-            if ($limit != null && $nb == $limit) {
-                break;
+            if ($phone->hasFlags($flags)) {
+                $phones[$id] = $phone;
+                ++$nb;
+                if ($limit != null && $nb == $limit) {
+                    break;
+                }
             }
         }
         return $phones;
index a1a2e58..411a59f 100644 (file)
@@ -124,7 +124,8 @@ function chgMainWinLoc(strPage)
     </div>
     {/if}
 
-    {assign var=phones value=$profile->getPhones(0)}
+    {* 121634816 is Profile::PHONE_LINK_PROFILE | Profile::PHONE_TYPE_ANY = 0x7400000 *}
+    {assign var=phones value=$profile->getPhones(121634816)}
     {if $logged || count($phones) > 0}
     <div class="contact">
       {if $logged}