-// {{{ class Phone
-class Phone
-{
- const TYPE_FAX = 'fax';
- const TYPE_FIXED = 'fixed';
- const TYPE_MOBILE = 'mobile';
- public $type;
-
- public $search;
- public $display;
- public $comment = '';
-
- const LINK_JOB = 'pro';
- const LINK_ADDRESS = 'address';
- const LINK_PROFILE = 'user';
- const LINK_COMPANY = 'hq';
- public $link_type;
- public $link_id;
-
- public $id;
-
- /** Fields are :
- * $type, $search, $display, $link_type, $link_id, $comment, $pid, $id
- */
- public function __construct($data)
- {
- foreach ($data as $key => $val) {
- $this->$key = $val;
- }
- }
-
- /** Returns the unique ID of a phone
- * This ID will allow to link it to an address, a user or a job
- * The format is address_addressId_phoneId (where phoneId is the id
- * of the phone in the list of those associated with the address)
- */
- public function uid() {
- return $this->link_type . '_' . $this->link_id . '_' . $this->id;
- }
-
- 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)
- );
- }
-
- /** User accessible version of the type
- */
- public function displayType($short = false)
- {
- switch ($this->type) {
- case Phone::TYPE_FIXED:
- return $short ? 'Tél' : 'Fixe';
- case Phone::TYPE_FAX:
- return 'Fax';
- case Phone::TYPE_MOBILE:
- return $short ? 'Mob' : 'Mobile';
- default:
- return $this->type;
- }
- }
-
- /** 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)
- );
- }
-}
-// }}}