X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fphone.php;h=29449e73ba90cad394c5dc6c48e17803c121018c;hb=2a1cd4ab034c1c4dccd132a76253cf4a7f84bf7d;hp=9a9f1b05598858f445c21889c203599d6441c973;hpb=5e1513f67936a6c6866113d260746711af4ea2ee;p=platal.git diff --git a/classes/phone.php b/classes/phone.php index 9a9f1b0..29449e7 100644 --- a/classes/phone.php +++ b/classes/phone.php @@ -55,21 +55,22 @@ class Phone const LINK_ADDRESS = 'address'; const LINK_PROFILE = 'user'; const LINK_COMPANY = 'hq'; + const LINK_GROUP = 'group'; /** The following fields, but $error, all correspond to the fields of the * database table profile_phones. */ - private $id = 0; - private $pid = 0; - private $search = ''; - private $link_type = 'user'; - private $link_id = 0; + public $id = 0; + public $pid = 0; + public $search = ''; + public $link_type = 'user'; + public $link_id = 0; // The following fields are the fields of the form in the profile edition. - private $type = 'fixed'; + public $type = 'fixed'; public $display = ''; public $pub = 'ax'; public $comment = ''; - private $error = false; + public $error = false; public function __construct(array $data = array()) { @@ -80,31 +81,6 @@ class Phone } } - public function linkType() - { - return $this->link_type; - } - - public function linkId() - { - return $this->link_id; - } - - public function id() - { - return $this->id; - } - - public function pid() - { - return $this->pid; - } - - public function search() - { - return $this->search; - } - public function setId($id) { $this->id = $id; @@ -301,9 +277,9 @@ class Phone { $this->format(); if (!$this->isEmpty()) { - XDB::execute('INSERT INTO profile_phones (pid, link_type, link_id, tel_id, tel_type, - search_tel, display_tel, pub, comment) - VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', + XDB::execute('INSERT IGNORE INTO profile_phones (pid, link_type, link_id, tel_id, tel_type, + search_tel, display_tel, pub, comment) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', $this->pid, $this->link_type, $this->link_id, $this->id, $this->type, $this->search, $this->display, $this->pub, $this->comment); } @@ -375,7 +351,9 @@ class Phone // Formats an array of form phones into an array of form formatted phones. static public function formatFormArray(array $data, &$success = true, $maxPublicity = null) { - return self::formArrayWalk($data, 'toFormArray', $success, true, $maxPublicity); + $phones = self::formArrayWalk($data, 'toFormArray', $success, true, $maxPublicity); + usort($phones, 'ProfileVisibility::comparePublicity'); + return $phones; } static public function formArrayToString(array $data) @@ -383,6 +361,16 @@ class Phone return implode(', ', self::formArrayWalk($data, 'toString')); } + static public function hasPrivate(array $phones) + { + foreach ($phones as $phone) { + if ($phone['pub'] == 'private') { + return true; + } + } + return false; + } + static public function iterate(array $pids = array(), array $link_types = array(), array $link_ids = array(), array $pubs = array()) {