2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
27 interface UserFilterCondition
29 const COND_TRUE
= 'TRUE';
30 const COND_FALSE
= 'FALSE';
32 /** Check that the given user matches the rule.
34 public function buildCondition(UserFilter
&$uf);
37 abstract class UFC_OneChild
implements UserFilterCondition
41 public function __construct($child = null
)
43 if (!is_null($child) && ($child instanceof UserFilterCondition
)) {
44 $this->setChild($child);
48 public function setChild(UserFilterCondition
&$cond)
50 $this->child
=& $cond;
54 abstract class UFC_NChildren
implements UserFilterCondition
56 protected $children = array();
58 public function __construct()
60 $children = func_get_args();
61 foreach ($children as &$child) {
62 if (!is_null($child) && ($child instanceof UserFilterCondition
)) {
63 $this->addChild($child);
68 public function addChild(UserFilterCondition
&$cond)
70 $this->children
[] =& $cond;
73 protected function catConds(array $cond, $op, $fallback)
75 if (count($cond) == 0) {
77 } else if (count($cond) == 1) {
80 return '(' . implode(') ' . $op . ' (', $cond) . ')';
85 class UFC_True
implements UserFilterCondition
87 public function buildCondition(UserFilter
&$uf)
89 return self
::COND_TRUE
;
93 class UFC_False
implements UserFilterCondition
95 public function buildCondition(UserFilter
&$uf)
97 return self
::COND_FALSE
;
101 class UFC_Not
extends UFC_OneChild
103 public function buildCondition(UserFilter
&$uf)
105 $val = $this->child
->buildCondition($uf);
106 if ($val == self
::COND_TRUE
) {
107 return self
::COND_FALSE
;
108 } else if ($val == self
::COND_FALSE
) {
109 return self
::COND_TRUE
;
111 return 'NOT (' . $val . ')';
116 class UFC_And
extends UFC_NChildren
118 public function buildCondition(UserFilter
&$uf)
120 if (empty($this->children
)) {
121 return self
::COND_FALSE
;
123 $true = self
::COND_FALSE
;
125 foreach ($this->children
as &$child) {
126 $val = $child->buildCondition($uf);
127 if ($val == self
::COND_TRUE
) {
128 $true = self
::COND_TRUE
;
129 } else if ($val == self
::COND_FALSE
) {
130 return self
::COND_FALSE
;
135 return $this->catConds($conds, 'AND', $true);
140 class UFC_Or
extends UFC_NChildren
142 public function buildCondition(UserFilter
&$uf)
144 if (empty($this->children
)) {
145 return self
::COND_TRUE
;
147 $true = self
::COND_TRUE
;
149 foreach ($this->children
as &$child) {
150 $val = $child->buildCondition($uf);
151 if ($val == self
::COND_TRUE
) {
152 return self
::COND_TRUE
;
153 } else if ($val == self
::COND_FALSE
) {
154 $true = self
::COND_FALSE
;
159 return $this->catConds($conds, 'OR', $true);
164 class UFC_Profile
implements UserFilterCondition
166 public function buildCondition(UserFilter
&$uf)
168 return '$PID IS NOT NULL';
172 class UFC_Promo
implements UserFilterCondition
179 public function __construct($comparison, $grade, $promo)
181 $this->grade
= $grade;
182 $this->comparison
= $comparison;
183 $this->promo
= $promo;
184 if ($this->grade
!= UserFilter
::DISPLAY
) {
185 UserFilter
::assertGrade($this->grade
);
189 public function buildCondition(UserFilter
&$uf)
191 if ($this->grade
== UserFilter
::DISPLAY
) {
192 $sub = $uf->addDisplayFilter();
193 return XDB
::format('pd' . $sub . '.promo = {?}', $this->promo
);
195 $sub = $uf->addEducationFilter(true
, $this->grade
);
196 $field = 'pe' . $sub . '.' . UserFilter
::promoYear($this->grade
);
197 return $field . ' IS NOT NULL AND ' . $field . ' ' . $this->comparison
. ' ' . XDB
::format('{?}', $this->promo
);
202 class UFC_Name
implements UserFilterCondition
214 public function __construct($type, $text, $mode)
221 private function buildNameQuery($type, $variant, $where, UserFilter
&$uf)
223 $sub = $uf->addNameFilter($type, $variant);
224 return str_replace('$ME', 'pn' . $sub, $where);
227 public function buildCondition(UserFilter
&$uf)
231 if (($this->mode
& self
::PARTICLE
) == self
::PARTICLE
) {
232 $left = 'CONCAT($ME.particle, \' \', $ME.name)';
234 if (($this->mode
& self
::CONTAINS
) == 0) {
235 $right = XDB
::format('{?}', $this->text
);
237 } else if (($this->mode
& self
::CONTAINS
) == self
::PREFIX
) {
238 $right = XDB
::format('CONCAT({?}, \'%\')', $this->text
);
239 } else if (($this->mode
& self
::CONTAINS
) == self
::SUFFIX
) {
240 $right = XDB
::format('CONCAT(\'%\', {?})', $this->text
);
242 $right = XDB
::format('CONCAT(\'%\', {?}, \'%\')', $this->text
);
244 $cond = $left . $op . $right;
245 $conds = array($this->buildNameQuery($this->type
, null
, $cond, $uf));
246 if (($this->mode
& self
::VARIANTS
) != 0 && isset(UserFilter
::$name_variants[$this->type
])) {
247 foreach (UserFilter
::$name_variants[$this->type
] as $var) {
248 $conds[] = $this->buildNameQuery($this->type
, $var, $cond, $uf);
251 return implode(' OR ', $conds);
255 class UFC_Dead
implements UserFilterCondition
260 public function __construct($comparison = null
, $date = null
)
262 $this->comparison
= $comparison;
266 public function buildCondition(UserFilter
&$uf)
268 $str = 'p.deathdate IS NOT NULL';
269 if (!is_null($this->comparison
)) {
270 $str .= ' AND p.deathdate ' . $this->comparison
. ' ' . XDB
::format('{?}', date('Y-m-d', $this->date
));
276 class UFC_Registered
implements UserFilterCondition
282 public function __construct($active = false
, $comparison = null
, $date = null
)
284 $this->only_active
= $active;
285 $this->comparison
= $comparison;
289 public function buildCondition(UserFilter
&$uf)
292 $date = 'a.uid IS NOT NULL AND a.state = \'active\'';
294 $date = 'a.uid IS NOT NULL AND a.state != \'pending\'';
296 if (!is_null($this->comparison
)) {
297 $date .= ' AND a.registration_date ' . $this->comparison
. ' ' . XDB
::format('{?}', date('Y-m-d', $this->date
));
303 class UFC_ProfileUpdated
implements UserFilterCondition
308 public function __construct($comparison = null
, $date = null
)
310 $this->comparison
= $comparison;
314 public function buildCondition(UserFilter
&$uf)
316 return 'p.last_change ' . $this->comparison
. XDB
::format(' {?}', date('Y-m-d H:i:s', $this->date
));
320 class UFC_Birthday
implements UserFilterCondition
325 public function __construct($comparison = null
, $date = null
)
327 $this->comparison
= $comparison;
331 public function buildCondition(UserFilter
&$uf)
333 return 'p.next_birthday ' . $this->comparison
. XDB
::format(' {?}', date('Y-m-d', $this->date
));
337 class UFC_Sex
implements UserFilterCondition
340 public function __construct($sex)
345 public function buildCondition(UserFilter
&$uf)
347 if ($this->sex
!= User
::GENDER_MALE
&& $this->sex
!= User
::GENDER_FEMALE
) {
348 return self
::COND_FALSE
;
350 return XDB
::format('p.sex = {?}', $this->sex
== User
::GENDER_FEMALE ?
'female' : 'male');
355 class UFC_Group
implements UserFilterCondition
359 public function __construct($group, $admin = false
)
361 $this->group
= $group;
362 $this->admin
= $admin;
365 public function buildCondition(UserFilter
&$uf)
367 $sub = $uf->addGroupFilter($this->group
);
368 $where = 'gpm' . $sub . '.perms IS NOT NULL';
370 $where .= ' AND gpm' . $sub . '.perms = \'admin\'';
376 class UFC_Email
implements UserFilterCondition
379 public function __construct($email)
381 $this->email
= $email;
384 public function buildCondition(UserFilter
&$uf)
386 if (User
::isForeignEmailAddress($this->email
)) {
387 $sub = $uf->addEmailRedirectFilter($this->email
);
388 return XDB
::format('e' . $sub . '.email IS NOT NULL OR a.email = {?}', $this->email
);
389 } else if (User
::isVirtualEmailAddress($this->email
)) {
390 $sub = $uf->addVirtualEmailFilter($this->email
);
391 return 'vr' . $sub . '.redirect IS NOT NULL';
393 @list
($user, $domain) = explode('@', $this->email
);
394 $sub = $uf->addAliasFilter($user);
395 return 'al' . $sub . '.alias IS NOT NULL';
400 class UFC_EmailList
implements UserFilterCondition
403 public function __construct($emails)
405 $this->emails
= $emails;
408 public function buildCondition(UserFilter
&$uf)
415 if (count($this->emails
) == 0) {
416 return UserFilterCondition
::COND_TRUE
;
419 foreach ($this->emails
as $entry) {
420 if (User
::isForeignEmailAddress($entry)) {
421 if (is_null($email)) {
422 $email = $uf->addEmailRedirectFilter();
424 $cond[] = XDB
::format('e' . $email . '.email = {?} OR a.email = {?}', $entry, $entry);
425 } else if (User
::isVirtualEmailAddress($entry)) {
426 if (is_null($virtual)) {
427 $virtual = $uf->addVirtualEmailFilter();
429 $cond[] = XDB
::format('vr' . $virtual . '.redirect IS NOT NULL AND v' . $virtual . '.alias = {?}', $entry);
431 if (is_null($alias)) {
432 $alias = $uf->addAliasFilter();
434 @list
($user, $domain) = explode('@', $entry);
435 $cond[] = XDB
::format('al' . $alias . '.alias = {?}', $user);
438 return '(' . implode(') OR (', $cond) . ')';
442 abstract class UFC_UserRelated
implements UserFilterCondition
445 public function __construct(PlUser
&$user)
447 $this->user
=& $user;
451 class UFC_Contact
extends UFC_UserRelated
453 public function buildCondition(UserFilter
&$uf)
455 $sub = $uf->addContactFilter($this->user
->id());
456 return 'c' . $sub . '.contact IS NOT NULL';
460 class UFC_WatchRegistration
extends UFC_UserRelated
462 public function buildCondition(UserFilter
&$uf)
464 if (!$this->user
->watch('registration')) {
465 return UserFilterCondition
::COND_FALSE
;
467 $uids = $this->user
->watchUsers();
468 if (count($uids) == 0) {
469 return UserFilterCondition
::COND_FALSE
;
471 return '$UID IN ' . XDB
::formatArray($uids);
476 class UFC_WatchPromo
extends UFC_UserRelated
479 public function __construct(PlUser
&$user, $grade = UserFilter
::GRADE_ING
)
481 parent
::__construct($user);
482 $this->grade
= $grade;
485 public function buildCondition(UserFilter
&$uf)
487 $promos = $this->user
->watchPromos();
488 if (count($promos) == 0) {
489 return UserFilterCondition
::COND_FALSE
;
491 $sube = $uf->addEducationFilter(true
, $this->grade
);
492 $field = 'pe' . $sube . '.' . UserFilter
::promoYear($this->grade
);
493 return $field . ' IN ' . XDB
::formatArray($promos);
498 class UFC_WatchContact
extends UFC_Contact
500 public function buildCondition(UserFilter
&$uf)
502 if (!$this->user
->watchContacts()) {
503 return UserFilterCondition
::COND_FALSE
;
505 return parent
::buildCondition($uf);
514 abstract class UserFilterOrder
516 protected $desc = false
;
517 public function __construct($desc = false
)
522 public function buildSort(UserFilter
&$uf)
524 $sel = $this->getSortTokens($uf);
525 if (!is_array($sel)) {
529 foreach ($sel as $k=>$s) {
530 $sel[$k] = $s . ' DESC';
536 abstract protected function getSortTokens(UserFilter
&$uf);
539 class UFO_Promo
extends UserFilterOrder
543 public function __construct($grade = null
, $desc = false
)
545 parent
::__construct($desc);
546 $this->grade
= $grade;
549 protected function getSortTokens(UserFilter
&$uf)
551 if (UserFilter
::isGrade($this->grade
)) {
552 $sub = $uf->addEducationFilter($this->grade
);
553 return 'pe' . $sub . '.' . UserFilter
::promoYear($this->grade
);
555 $sub = $uf->addDisplayFilter();
556 return 'pd' . $sub . '.promo';
561 class UFO_Name
extends UserFilterOrder
567 public function __construct($type, $variant = null
, $particle = false
, $desc = false
)
569 parent
::__construct($desc);
571 $this->variant
= $variant;
572 $this->particle
= $particle;
575 protected function getSortTokens(UserFilter
&$uf)
577 if (UserFilter
::isDisplayName($this->type
)) {
578 $sub = $uf->addDisplayFilter();
579 return 'pd' . $sub . '.' . $this->type
;
581 $sub = $uf->addNameFilter($this->type
, $this->variant
);
582 if ($this->particle
) {
583 return 'CONCAT(pn' . $sub . '.particle, \' \', pn' . $sub . '.name)';
585 return 'pn' . $sub . '.name';
591 class UFO_Registration
extends UserFilterOrder
593 protected function getSortTokens(UserFilter
&$uf)
595 return 'a.registration_date';
599 class UFO_Birthday
extends UserFilterOrder
601 protected function getSortTokens(UserFilter
&$uf)
603 return 'p.next_birthday';
607 class UFO_ProfileUpdate
extends UserFilterOrder
609 protected function getSortTokens(UserFilter
&$uf)
611 return 'p.last_change';
615 class UFO_Death
extends UserFilterOrder
617 protected function getSortTokens(UserFilter
&$uf)
619 return 'p.deathdate';
624 /***********************************
625 *********************************
627 *********************************
628 ***********************************/
632 static private $joinMethods = array();
635 private $sort = array();
636 private $query = null
;
637 private $orderby = null
;
639 private $lastcount = null
;
641 public function __construct($cond = null
, $sort = null
)
643 if (empty(self
::$joinMethods)) {
644 $class = new ReflectionClass('UserFilter');
645 foreach ($class->getMethods() as $method) {
646 $name = $method->getName();
647 if (substr($name, -5) == 'Joins' && $name != 'buildJoins') {
648 self
::$joinMethods[] = $name;
652 if (!is_null($cond)) {
653 if ($cond instanceof UserFilterCondition
) {
654 $this->setCondition($cond);
657 if (!is_null($sort)) {
658 if ($sort instanceof UserFilterOrder
) {
659 $this->addSort($sort);
660 } else if (is_array($sort)) {
661 foreach ($sort as $s) {
668 private function buildQuery()
670 if (is_null($this->orderby
)) {
672 foreach ($this->sort
as $sort) {
673 $orders = array_merge($orders, $sort->buildSort($this));
675 if (count($orders) == 0) {
678 $this->orderby
= 'ORDER BY ' . implode(', ', $orders);
681 if (is_null($this->query
)) {
682 $where = $this->root
->buildCondition($this);
683 $joins = $this->buildJoins();
684 $this->query
= 'FROM accounts AS a
685 LEFT JOIN account_profiles AS ap ON (ap.uid = a.uid AND FIND_IN_SET(\'owner\', ap.perms))
686 LEFT JOIN profiles AS p ON (p.pid = ap.pid)
688 WHERE (' . $where . ')';
692 private function formatJoin(array $joins)
695 foreach ($joins as $key => $infos) {
698 if ($mode == 'inner') {
699 $str .= 'INNER JOIN ';
700 } else if ($mode == 'left') {
701 $str .= 'LEFT JOIN ';
703 Platal
::page()->kill("Join mode error");
705 $str .= $table . ' AS ' . $key;
706 if (isset($infos[2])) {
707 $str .= ' ON (' . str_replace(array('$ME', '$PID', '$UID'), array($key, 'p.pid', 'a.uid'), $infos[2]) . ')';
714 private function buildJoins()
717 foreach (self
::$joinMethods as $method) {
718 $joins = array_merge($joins, $this->$method());
720 return $this->formatJoin($joins);
723 private function getUIDList($uids = null
, $count = null
, $offset = null
)
727 if (!is_null($count)) {
728 if (!is_null($offset)) {
729 $limit = XDB
::format('LIMIT {?}, {?}', (int)$offset, (int)$count);
731 $limit = XDB
::format('LIMIT {?}', (int)$count);
735 if (!is_null($uids)) {
736 $cond = ' AND a.uid IN ' . XDB
::formatArray($uids);
738 $fetched = XDB
::fetchColumn('SELECT SQL_CALC_FOUND_ROWS a.uid
739 ' . $this->query
. $cond . '
741 ' . $this->orderby
. '
743 $this->lastcount
= (int)XDB
::fetchOneCell('SELECT FOUND_ROWS()');
747 /** Check that the user match the given rule.
749 public function checkUser(PlUser
&$user)
752 $count = (int)XDB
::fetchOneCell('SELECT COUNT(*)
753 ' . $this->query
. XDB
::format(' AND a.uid = {?}', $user->id()));
757 /** Filter a list of user to extract the users matching the rule.
759 public function filter(array $users, $count = null
, $offset = null
)
764 foreach ($users as $user) {
765 if ($user instanceof PlUser
) {
771 $table[$uid] = $user;
773 $fetched = $this->getUIDList($uids, $count, $offset);
775 foreach ($fetched as $uid) {
776 $output[] = $table[$uid];
781 public function getUIDs($count = null
, $offset = null
)
783 return $this->getUIDList(null
, $count, $offset);
786 public function getUsers($count = null
, $offset = null
)
788 return User
::getBulkUsersWithUIDs($this->getUIDs($count, $offset));
791 public function getTotalCount()
793 if (is_null($this->lastcount
)) {
795 return (int)XDB
::fetchOneCell('SELECT COUNT(DISTINCT a.uid)
798 return $this->lastcount
;
802 public function setCondition(UserFilterCondition
&$cond)
804 $this->root
=& $cond;
808 public function addSort(UserFilterOrder
&$sort)
810 $this->sort
[] = $sort;
811 $this->orderby
= null
;
814 static public function getLegacy($promo_min, $promo_max)
816 if ($promo_min != 0) {
817 $min = new UFC_Promo('>=', self
::GRADE_ING
, intval($promo_min));
819 $min = new UFC_True();
821 if ($promo_max != 0) {
822 $max = new UFC_Promo('<=', self
::GRADE_ING
, intval($promo_max));
824 $max = new UFC_True();
826 return new UserFilter(new UFC_And($min, $max));
829 static public function sortByName()
831 return array(new UFO_Name(self
::LASTNAME
), new UFO_Name(self
::FIRSTNAME
));
834 static public function sortByPromo()
836 return array(new UFO_Promo(), new UFO_Name(self
::LASTNAME
), new UFO_Name(self
::FIRSTNAME
));
839 static private function getDBSuffix($string)
841 return preg_replace('/[^a-z0-9]/i', '', $string);
846 private function register_optional(array &$table, $val)
849 $sub = $this->option++
;
852 $sub = self
::getDBSuffix($val);
856 $table[$sub] = $index;
862 const DISPLAY
= 'display';
864 public function addDisplayFilter()
870 private function displayJoins()
873 return array('pd' => array('left', 'profile_display', '$ME.pid = $PID'));
882 const LASTNAME
= 'lastname';
883 const FIRSTNAME
= 'firstname';
884 const NICKNAME
= 'nickname';
885 const PSEUDONYM
= 'pseudonym';
888 const VN_MARITAL
= 'marital';
889 const VN_ORDINARY
= 'ordinary';
890 const VN_OTHER
= 'other';
891 const VN_INI
= 'ini';
893 const DN_FULL
= 'directory_name';
894 const DN_DISPLAY
= 'yourself';
895 const DN_YOURSELF
= 'yourself';
896 const DN_DIRECTORY
= 'directory_name';
897 const DN_PRIVATE
= 'private_name';
898 const DN_PUBLIC
= 'public_name';
899 const DN_SHORT
= 'short_name';
900 const DN_SORT
= 'sort_name';
902 static public $name_variants = array(
903 self
::LASTNAME
=> array(self
::VN_MARITAL
, self
::VN_ORDINARY
),
904 self
::FIRSTNAME
=> array(self
::VN_ORDINARY
, self
::VN_INI
, self
::VN_OTHER
)
907 static public function assertName($name)
909 if (!Profile
::getNameTypeId($name)) {
910 Platal
::page()->kill('Invalid name type');
914 static public function isDisplayName($name)
916 return $name == self
::DN_FULL ||
$name == self
::DN_DISPLAY
917 ||
$name == self
::DN_YOURSELF ||
$name == self
::DN_DIRECTORY
918 ||
$name == self
::DN_PRIVATE ||
$name == self
::DN_PUBLIC
919 ||
$name == self
::DN_SHORT ||
$name == self
::DN_SORT
;
922 private $pn = array();
923 public function addNameFilter($type, $variant = null
)
925 if (!is_null($variant)) {
926 $ft = $type . '_' . $variant;
931 self
::assertName($ft);
933 if (!is_null($variant) && $variant == 'other') {
934 $sub .= $this->option++
;
936 $this->pn
[$sub] = Profile
::getNameTypeId($ft);
940 private function nameJoins()
943 foreach ($this->pn
as $sub => $type) {
944 $joins['pn' . $sub] = array('left', 'profile_name', '$ME.pid = $PID AND $ME.typeid = ' . $type);
952 const GRADE_ING
= 'Ing.';
953 const GRADE_PHD
= 'PhD';
954 const GRADE_MST
= 'M%';
955 static public function isGrade($grade)
957 return $grade == self
::GRADE_ING ||
$grade == self
::GRADE_PHD ||
$grade == self
::GRADE_MST
;
960 static public function assertGrade($grade)
962 if (!self
::isGrade($grade)) {
963 Platal
::page()->killError("Diplôme non valide");
967 static public function promoYear($grade)
969 // XXX: Definition of promotion for phds and masters might change in near future.
970 return ($grade == UserFilter
::GRADE_ING
) ?
'entry_year' : 'grad_year';
973 private $pepe = array();
974 private $with_pee = false
;
975 public function addEducationFilter($x = false
, $grade = null
)
978 $index = $this->option
;
979 $sub = $this->option++
;
981 self
::assertGrade($grade);
984 $this->with_pee
= true
;
987 $this->pepe
[$index] = $sub;
991 private function educationJoins()
994 if ($this->with_pee
) {
995 $joins['pee'] = array('inner', 'profile_education_enum', 'pee.abbreviation = \'X\'');
997 foreach ($this->pepe
as $grade => $sub) {
998 if ($this->isGrade($grade)) {
999 $joins['pe' . $sub] = array('left', 'profile_education', '$ME.eduid = pee.id AND $ME.uid = $PID');
1000 $joins['pede' . $sub] = array('inner', 'profile_education_degree_enum', '$ME.id = pe' . $sub . '.degreeid AND $ME.abbreviation LIKE ' .
1001 XDB
::format('{?}', $grade));
1003 $joins['pe' . $sub] = array('left', 'profile_education', '$ME.uid = $PID');
1004 $joins['pee' . $sub] = array('inner', 'profile_education_enum', '$ME.id = pe' . $sub . '.eduid');
1005 $joins['pede' . $sub] = array('inner', 'profile_education_degree_enum', '$ME.id = pe' . $sub . '.degreeid');
1014 private $gpm = array();
1015 public function addGroupFilter($group = null
)
1017 if (!is_null($group)) {
1018 if (ctype_digit($group)) {
1019 $index = $sub = $group;
1022 $sub = self
::getDBSuffix($group);
1025 $sub = 'group_' . $this->option++
;
1029 $this->gpm
[$sub] = $index;
1033 private function groupJoins()
1036 foreach ($this->gpm
as $sub => $key) {
1037 if (is_null($key)) {
1038 $joins['gpa' . $sub] = array('inner', 'groupex.asso');
1039 $joins['gpm' . $sub] = array('left', 'groupex.membres', '$ME.uid = $UID AND $ME.asso_id = gpa' . $sub . '.id');
1040 } else if (ctype_digit($key)) {
1041 $joins['gpm' . $sub] = array('left', 'groupex.membres', '$ME.uid = $UID AND $ME.asso_id = ' . $key);
1043 $joins['gpa' . $sub] = array('inner', 'groupex.asso', XDB
::format('$ME.diminutif = {?}', $key));
1044 $joins['gpm' . $sub] = array('left', 'groupex.membres', '$ME.uid = $UID AND $ME.asso_id = gpa' . $sub . '.id');
1052 private $e = array();
1053 public function addEmailRedirectFilter($email = null
)
1055 return $this->register_optional($this->e
, $email);
1058 private $ve = array();
1059 public function addVirtualEmailFilter($email = null
)
1061 $this->addAliasFilter(self
::ALIAS_FORLIFE
);
1062 return $this->register_optional($this->ve
, $email);
1065 const ALIAS_BEST
= 'bestalias';
1066 const ALIAS_FORLIFE
= 'forlife';
1067 private $al = array();
1068 public function addAliasFilter($alias = null
)
1070 return $this->register_optional($this->al
, $alias);
1073 private function emailJoins()
1077 foreach ($this->e
as $sub=>$key) {
1078 if (is_null($key)) {
1079 $joins['e' . $sub] = array('left', 'emails', '$ME.uid = $UID AND $ME.flags != \'filter\'');
1081 $joins['e' . $sub] = array('left', 'emails', XDB
::format('$ME.uid = $UID AND $ME.flags != \'filter\' AND $ME.email = {?}', $key));
1084 foreach ($this->al
as $sub=>$key) {
1085 if (is_null($key)) {
1086 $joins['al' . $sub] = array('left', 'aliases', '$ME.id = $UID AND $ME.type IN (\'alias\', \'a_vie\')');
1087 } else if ($key == self
::ALIAS_BEST
) {
1088 $joins['al' . $sub] = array('left', 'aliases', '$ME.id = $UID AND $ME.type IN (\'alias\', \'a_vie\') AND FIND_IN_SET(\'bestalias\', $ME.flags)');
1089 } else if ($key == self
::ALIAS_FORLIFE
) {
1090 $joins['al' . $sub] = array('left', 'aliases', '$ME.id = $UID AND $ME.type = \'a_vie\'');
1092 $joins['al' . $sub] = array('left', 'aliases', XDB
::format('$ME.id = $UID AND $ME.type IN (\'alias\', \'a_vie\') AND $ME.alias = {?}', $key));
1095 foreach ($this->ve
as $sub=>$key) {
1096 if (is_null($key)) {
1097 $joins['v' . $sub] = array('left', 'virtual', '$ME.type = \'user\'');
1099 $joins['v' . $sub] = array('left', 'virtual', XDB
::format('$ME.type = \'user\' AND $ME.alias = {?}', $key));
1101 $joins['vr' . $sub] = array('left', 'virtual_redirect', XDB
::format('$ME.vid = v' . $sub . '.vid
1102 AND ($ME.redirect IN (CONCAT(al_forlife.alias, \'@\', {?}),
1103 CONCAT(al_forlife.alias, \'@\', {?}),
1105 $globals->mail
->domain
, $globals->mail
->domain2
));
1113 private $cts = array();
1114 public function addContactFilter($uid = null
)
1116 return $this->register_optional($this->cts
, is_null($uid) ? null
: 'user_' . $uid);
1119 private function contactJoins()
1122 foreach ($this->cts
as $sub=>$key) {
1123 if (is_null($key)) {
1124 $joins['c' . $sub] = array('left', 'contacts', '$ME.contact = $UID');
1126 $joins['c' . $sub] = array('left', 'contacts', XDB
::format('$ME.uid = {?} AND $ME.contact = $UID', substr($key, 5)));
1135 private $wn = array();
1136 public function addWatchRegistrationFilter($uid = null
)
1138 return $this->register_optional($this->wn
, is_null($uid) ? null
: 'user_' . $uid);
1141 private $wp = array();
1142 public function addWatchPromoFilter($uid = null
)
1144 return $this->register_optional($this->wp
, is_null($uid) ? null
: 'user_' . $uid);
1147 private $w = array();
1148 public function addWatchFilter($uid = null
)
1150 return $this->register_optional($this->w
, is_null($uid) ? null
: 'user_' . $uid);
1153 private function watchJoins()
1156 foreach ($this->w
as $sub=>$key) {
1157 if (is_null($key)) {
1158 $joins['w' . $sub] = array('left', 'watch');
1160 $joins['w' . $sub] = array('left', 'watch', XDB
::format('$ME.uid = {?}', substr($key, 5)));
1163 foreach ($this->wn
as $sub=>$key) {
1164 if (is_null($key)) {
1165 $joins['wn' . $sub] = array('left', 'watch_nonins', '$ME.ni_id = $UID');
1167 $joins['wn' . $sub] = array('left', 'watch_nonins', XDB
::format('$ME.uid = {?} AND $ME.ni_id = $UID', substr($key, 5)));
1170 foreach ($this->wn
as $sub=>$key) {
1171 if (is_null($key)) {
1172 $joins['wn' . $sub] = array('left', 'watch_nonins', '$ME.ni_id = $UID');
1174 $joins['wn' . $sub] = array('left', 'watch_nonins', XDB
::format('$ME.uid = {?} AND $ME.ni_id = $UID', substr($key, 5)));
1177 foreach ($this->wp
as $sub=>$key) {
1178 if (is_null($key)) {
1179 $joins['wp' . $sub] = array('left', 'watch_promo');
1181 $joins['wp' . $sub] = array('left', 'watch_promo', XDB
::format('$ME.uid = {?}', substr($key, 5)));
1189 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: