<?php
/***************************************************************************
- * Copyright (C) 2003-2010 Polytechnique.org *
+ * Copyright (C) 2003-2011 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
return $groups;
}
- private function getUIDList($uids = null, PlLimit &$limit)
+ private function getUIDList($uids = null, PlLimit $limit)
{
$this->requireAccounts();
$this->buildQuery();
return $fetched;
}
- private function getPIDList($pids = null, PlLimit &$limit)
+ private function getPIDList($pids = null, PlLimit $limit)
{
$this->requireProfiles();
$this->buildQuery();
/** Check that the user match the given rule.
*/
- public function checkUser(PlUser &$user)
+ public function checkUser(PlUser $user)
{
$this->requireAccounts();
$this->buildQuery();
/** Check that the profile match the given rule.
*/
- public function checkProfile(Profile &$profile)
+ public function checkProfile(Profile $profile)
{
$this->requireProfiles();
$this->buildQuery();
public function export()
{
- $export = array('condition' => $this->root->export());
+ $export = array('conditions' => $this->root->export());
if (!empty($this->sort)) {
- $export['sort'] = array();
+ $export['sorts'] = array();
foreach ($this->sort as $sort) {
- $export['sort'][] = $sort->export();
+ $export['sorts'][] = $sort->export();
}
}
return $export;
}
+ public function exportConditions()
+ {
+ return $this->root->export();
+ }
+
+ public static function fromExport(array $export)
+ {
+ $export = new PlDict($export);
+ if (!$export->has('conditions')) {
+ throw new Exception("Cannot build a user filter without conditions");
+ }
+ $cond = UserFilterCondition::fromExport($export->v('conditions'));
+ $sorts = null;
+ if ($export->has('sorts')) {
+ $sorts = array();
+ foreach ($export->v('sorts') as $sort) {
+ $sorts[] = UserFilterOrder::fromExport($sort);
+ }
+ }
+ return new UserFilter($cond, $sorts);
+ }
+
+ public static function fromJSon($json)
+ {
+ $export = json_decode($json, true);
+ if (is_null($export)) {
+ throw new Exception("Invalid json: $json");
+ }
+ return self::fromExport($json);
+ }
+
+ public static function fromExportedConditions(array $export)
+ {
+ $cond = UserFilterCondition::fromExport($export);
+ return new UserFilter($cond);
+ }
+
+ public static function fromJSonConditions($json)
+ {
+ $export = json_decode($json, true);
+ if (is_null($export)) {
+ throw new Exception("Invalid json: $json");
+ }
+ return self::fromExportedConditions($json);
+ }
+
static public function getLegacy($promo_min, $promo_max)
{
if ($promo_min != 0) {
return $joins;
}
+ /** NLS
+ */
+ private $nls = array();
+ public function addNewsLetterFilter($nlid)
+ {
+ $this->requireAccounts();
+ $sub = 'nl_' . $nlid;
+ $this->nls[$nlid] = $sub;
+ return $sub;
+ }
+
+ protected function newsLetterJoins()
+ {
+ $joins = array();
+ foreach ($this->nls as $key => $sub) {
+ $joins[$sub] = PlSqlJoin::left('newsletter_ins', '$ME.nlid = {?} AND $ME.uid = $UID', $key);
+ }
+ return $joins;
+ }
+
/** BINETS
*/
/** EMAILS
*/
- private $e = array();
+ private $ra = array();
+ /** Allows filtering by redirection.
+ * @param $email If null, enable a left join on the email redirection table
+ * (email_redirect_account); otherwise, perform a left join on users having
+ * that email as a redirection.
+ * @return Suffix to use to access the adequate table.
+ */
public function addEmailRedirectFilter($email = null)
{
$this->requireAccounts();
- return $this->register_optional($this->e, $email);
- }
-
- private $ve = array();
- public function addVirtualEmailFilter($email = null)
+ return $this->register_optional($this->ra, $email);
+ }
+
+ const ALIAS_BEST = 'bestalias';
+ const ALIAS_FORLIFE = 'forlife';
+ const ALIAS_AUXILIARY = 'alias_aux';
+ private $sa = array();
+ /** Allows filtering by source email.
+ * @param $email If null, enable a left join on the email source table
+ * (email_source_account); otherwise, perform a left join on users having
+ * that email as a source email.
+ * @return Suffix to use to access the adequate table.
+ */
+ public function addAliasFilter($email = null)
{
- $this->addAliasFilter(self::ALIAS_FORLIFE);
- return $this->register_optional($this->ve, $email);
+ $this->requireAccounts();
+ return $this->register_optional($this->sa, $email);
}
- const ALIAS_BEST = 'bestalias';
- const ALIAS_FORLIFE = 'forlife';
- private $al = array();
- public function addAliasFilter($alias = null)
+ private $with_rf = false;
+ /** Allows filtering by active redirection.
+ * @return Suffix to use to access the adequate table.
+ */
+ public function addActiveEmailRedirectFilter($email = null)
{
$this->requireAccounts();
- return $this->register_optional($this->al, $alias);
+ $this->with_rf = true;
}
protected function emailJoins()
{
global $globals;
$joins = array();
- foreach ($this->e as $sub=>$key) {
- if (is_null($key)) {
- $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\'');
+ foreach ($this->ra as $sub => $redirections) {
+ if (is_null($redirections)) {
+ $joins['ra' . $sub] = PlSqlJoin::left('email_redirect_account', '$ME.uid = $UID AND $ME.type != \'imap\'');
} else {
- if (!is_array($key)) {
- $key = array($key);
+ if (!is_array($redirections)) {
+ $key = array($redirections);
}
- $joins['e' . $sub] = PlSqlJoin::left('emails', '$ME.uid = $UID AND $ME.flags != \'filter\'
- AND $ME.email IN {?}', $key);
+ $joins['ra' . $sub] = PlSqlJoin::left('email_redirect_account', '$ME.uid = $UID AND $ME.type != \'imap\'
+ AND $ME.redirect IN {?}', $redirections);
}
}
- foreach ($this->al as $sub=>$key) {
- if (is_null($key)) {
- $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\')');
+ foreach ($this->sa as $sub => $emails) {
+ if (is_null($emails)) {
+ $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID');
} else if ($key == self::ALIAS_BEST) {
- $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\') AND FIND_IN_SET(\'bestalias\', $ME.flags)');
+ $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND FIND_IN_SET(\'bestalias\', $ME.flags)');
} else if ($key == self::ALIAS_FORLIFE) {
- $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type = \'a_vie\'');
+ $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND $ME.type = \'forlife\'');
+ } else if ($key == self::ALIAS_AUXILIARY) {
+ $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND $ME.type = \'alias_aux\'');
} else {
- if (!is_array($key)) {
- $key = array($key);
+ if (!is_array($emails)) {
+ $key = array($emails);
}
- $joins['al' . $sub] = PlSqlJoin::left('aliases', '$ME.uid = $UID AND $ME.type IN (\'alias\', \'a_vie\')
- AND $ME.alias IN {?}', $key);
+ $joins['sa' . $sub] = PlSqlJoin::left('email_source_account', '$ME.uid = $UID AND $ME.email IN {?}', $emails);
}
}
- foreach ($this->ve as $sub=>$key) {
- if (is_null($key)) {
- $joins['v' . $sub] = PlSqlJoin::left('virtual', '$ME.type = \'user\'');
- } else {
- if (!is_array($key)) {
- $key = array($key);
- }
- $joins['v' . $sub] = PlSqlJoin::left('virtual', '$ME.type = \'user\' AND $ME.alias IN {?}', $key);
- }
- $joins['vr' . $sub] = PlSqlJoin::left('virtual_redirect',
- '$ME.vid = v' . $sub . '.vid
- AND ($ME.redirect IN (CONCAT(al_forlife.alias, \'@\', {?}),
- CONCAT(al_forlife.alias, \'@\', {?}),
- a.email))',
- $globals->mail->domain, $globals->mail->domain2);
+ if ($this->with_rf) {
+ $joins['rf'] = PlSqlJoin::left('email_redirect_account', '$ME.uid = $UID AND $ME.type != \'imap\' AND $ME.flags = \'active\'');;
}
return $joins;
}
$this->requireProfiles();
$this->pc = true;
if ($type == UFC_Corps::CURRENT) {
- $pce['pcec'] = 'current_corpsid';
+ $this->pce['pcec'] = 'current_corpsid';
return 'pcec';
} else if ($type == UFC_Corps::ORIGIN) {
- $pce['pceo'] = 'original_corpsid';
+ $this->pce['pceo'] = 'original_corpsid';
return 'pceo';
}
}
}
}
// }}}
-
// {{{ class ProfileFilter
class ProfileFilter extends UserFilter
{