From: Raphaël Barrois Date: Mon, 21 Jun 2010 19:03:34 +0000 (+0200) Subject: Add options to profile->getPhones to allow filtering X-Git-Tag: xorg/1.0.0~109 X-Git-Url: http://git.polytechnique.org/?a=commitdiff_plain;h=3c985c085f0e966ce2a0198d957fbafa2269ac82;p=platal.git Add options to profile->getPhones to allow filtering Filter by phone type or by link (job/address/...) Signed-off-by: Raphaël Barrois --- diff --git a/classes/profile.php b/classes/profile.php index 740eeb3..9352029 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -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; diff --git a/include/profilefields.inc.php b/include/profilefields.inc.php index ffff5ad..c456d04 100644 --- a/include/profilefields.inc.php +++ b/include/profilefields.inc.php @@ -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; diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index a1a2e58..411a59f 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -124,7 +124,8 @@ function chgMainWinLoc(strPage) {/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}
{if $logged}