+
+ /** Get marketing informations
+ */
+ private function fetchMarketingData()
+ {
+ if (isset($this->last_known_email)) {
+ return;
+ }
+ $infos = XDB::fetchOneAssoc('SELECT IF (MAX(m.last) > p.relance, MAX(m.last), p.relance) AS last_relance,
+ p.email AS last_known_email
+ FROM register_pending AS p
+ LEFT JOIN register_marketing AS m ON (p.uid = m.uid)
+ WHERE p.uid = {?}
+ GROUP BY p.uid', $this->id());
+ if (!$infos) {
+ $infos = array('last_relance' => null, 'last_known_email' => null);
+ }
+ $this->fillFromArray($infos);
+ }
+
+ public function lastMarketingRelance()
+ {
+ $this->fetchMarketingData();
+ return $this->last_relance;
+ }
+
+ public function lastKnownEmail()
+ {
+ $this->fetchMarketingData();
+ return $this->last_known_email;
+ }
+
+
+ /** Get watch informations
+ */
+ private function fetchWatchData()
+ {
+ if (isset($this->watch_actions)) {
+ return;
+ }
+ $watch = XDB::fetchOneAssoc('SELECT flags AS watch_flags, actions AS watch_actions,
+ UNIX_TIMESTAMP(last) AS watch_last
+ FROM watch
+ WHERE uid = {?}', $this->id());
+ $watch['watch_flags'] = new PlFlagSet($watch['watch_flags']);
+ $watch['watch_actions'] = new PlFlagSet($watch['watch_actions']);
+ $watch['watch_promos'] = XDB::fetchColumn('SELECT promo
+ FROM watch_promo
+ WHERE uid = {?}', $this->id());
+ $watch['watch_users'] = XDB::fetchColumn('SELECT ni_id
+ FROM watch_nonins
+ WHERE uid = {?}', $this->id());
+ $this->fillFromArray($watch);
+ }
+
+ public function watchType($type)
+ {
+ $this->fetchWatchData();
+ return $this->watch_actions->hasFlag($type);
+ }
+
+ public function watchContacts()
+ {
+ $this->fetchWatchData();
+ return $this->watch_flags->hasFlag('contacts');
+ }
+
+ public function watchEmail()
+ {
+ $this->fetchWatchData();
+ return $this->watch_flags->hasFlag('mail');
+ }
+
+ public function watchPromos()
+ {
+ $this->fetchWatchData();
+ return $this->watch_promos;
+ }
+
+ public function watchUsers()
+ {
+ $this->fetchWatchData();
+ return $this->watch_users;
+ }
+
+ public function watchLast()
+ {
+ $this->fetchWatchData();
+ return $this->watch_last;
+ }
+
+
+ // Contacts
+ private $contacts = null;
+ private function fetchContacts()
+ {
+ if (is_null($this->contacts)) {
+ $this->contacts = XDB::fetchAllAssoc('contact', 'SELECT *
+ FROM contacts
+ WHERE uid = {?}',
+ $this->id());
+ }
+ }
+
+ public function iterContacts()
+ {
+ $this->fetchContacts();
+ return self::iterOverUIDs(array_keys($this->contacts));
+ }
+
+ public function getContacts()
+ {
+ $this->fetchContacts();
+ return self::getBulkUsersWithUIDs(array_keys($this->contacts));
+ }
+
+ public function isContact(PlUser &$user)
+ {
+ $this->fetchContacts();
+ return isset($this->contacts[$user->id()]);
+ }
+
+ // Groupes X
+ private $groups = null;
+ public function groups()
+ {
+ if (is_null($this->groups)) {
+ $this->groups = XDB::fetchAllAssoc('asso_id', 'SELECT asso_id, perms, comm
+ FROM group_members
+ WHERE uid = {?}',
+ $this->id());
+ }
+ return $this->groups;
+ }
+