From 913a4e9004e7c0558dc79f3600b8f712b2f216fd Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sun, 14 Feb 2010 00:59:27 +0100 Subject: [PATCH] Move Name-related code from UserFilter to Profile MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Display names * Name variants * Available names Signed-off-by: Raphaël Barrois --- classes/profile.php | 35 +++++++++++++++++++++++++++++++++++ classes/userfilter.php | 45 ++++++--------------------------------------- include/userset.inc.php | 22 +++++++++++----------- modules/marketing.php | 2 +- modules/xnetgrp.php | 4 ++-- 5 files changed, 55 insertions(+), 53 deletions(-) diff --git a/classes/profile.php b/classes/profile.php index 1f05066..3dd0e14 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -24,10 +24,37 @@ class Profile static private $v_values = array('public' => array('public'), 'ax' => array('ax', 'public'), 'private' => array('private', 'ax', 'public')); + const VISIBILITY_PUBLIC = 'public'; const VISIBILITY_AX = 'ax'; const VISIBILITY_PRIVATE = 'private'; + /* name tokens */ + const LASTNAME = 'lastname'; + const FIRSTNAME = 'firstname'; + const NICKNAME = 'nickname'; + const PSEUDONYM = 'pseudonym'; + const NAME = 'name'; + /* name variants */ + const VN_MARITAL = 'marital'; + const VN_ORDINARY = 'ordinary'; + const VN_OTHER = 'other'; + const VN_INI = 'ini'; + /* display names */ + const DN_FULL = 'directory_name'; + const DN_DISPLAY = 'yourself'; + const DN_YOURSELF = 'yourself'; + const DN_DIRECTORY = 'directory_name'; + const DN_PRIVATE = 'private_name'; + const DN_PUBLIC = 'public_name'; + const DN_SHORT = 'short_name'; + const DN_SORT = 'sort_name'; + + static public $name_variants = array( + self::LASTNAME => array(self::VN_MARITAL, self::VN_ORDINARY), + self::FIRSTNAME => array(self::VN_ORDINARY, self::VN_INI, self::VN_OTHER) + ); + const ADDRESS_MAIN = 0x000001; const ADDRESS_PERSO = 0x000002; const ADDRESS_PRO = 0x000004; @@ -459,6 +486,14 @@ class Profile return self::getBulkProfilesWithPIDs($table); } + public static function isDisplayName($name) + { + return $name == self::DN_FULL || $name == self::DN_DISPLAY + || $name == self::DN_YOURSELF || $name == self::DN_DIRECTORY + || $name == self::DN_PRIVATE || $name == self::DN_PUBLIC + || $name == self::DN_SHORT || $name == self::DN_SORT; + } + public static function getNameTypeId($type, $for_sql = false) { if (!S::has('name_types')) { diff --git a/classes/userfilter.php b/classes/userfilter.php index 7b97136..e8aa2f2 100644 --- a/classes/userfilter.php +++ b/classes/userfilter.php @@ -247,8 +247,8 @@ class UFC_Name implements UserFilterCondition } $cond = $left . $op . $right; $conds = array($this->buildNameQuery($this->type, null, $cond, $uf)); - if (($this->mode & self::VARIANTS) != 0 && isset(UserFilter::$name_variants[$this->type])) { - foreach (UserFilter::$name_variants[$this->type] as $var) { + if (($this->mode & self::VARIANTS) != 0 && isset(Profile::$name_variants[$this->type])) { + foreach (Profile::$name_variants[$this->type] as $var) { $conds[] = $this->buildNameQuery($this->type, $var, $cond, $uf); } } @@ -1342,7 +1342,7 @@ class UFO_Name extends UserFilterOrder protected function getSortTokens(PlFilter &$uf) { - if (UserFilter::isDisplayName($this->type)) { + if (Profile::isDisplayName($this->type)) { $sub = $uf->addDisplayFilter(); return 'pd' . $sub . '.' . $this->type; } else { @@ -1447,7 +1447,7 @@ class UFO_Death extends UserFilterOrder * in the final query. * * In the join_criter text, $ME is replaced with 'join_tablealias', $PID with - * profile.pid, and $UID with auth_user_md5.user_id. + * profile.pid, and $UID with accounts.uid. * * For each kind of "JOIN" needed, a function named addXXXFilter() should be defined; * its parameter will be used to set various private vars of the UserFilter describing @@ -1735,12 +1735,12 @@ class UserFilter extends PlFilter static public function sortByName() { - return array(new UFO_Name(self::LASTNAME), new UFO_Name(self::FIRSTNAME)); + return array(new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); } static public function sortByPromo() { - return array(new UFO_Promo(), new UFO_Name(self::LASTNAME), new UFO_Name(self::FIRSTNAME)); + return array(new UFO_Promo(), new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME)); } static private function getDBSuffix($string) @@ -1829,31 +1829,6 @@ class UserFilter extends PlFilter /** NAMES */ - /* name tokens */ - const LASTNAME = 'lastname'; - const FIRSTNAME = 'firstname'; - const NICKNAME = 'nickname'; - const PSEUDONYM = 'pseudonym'; - const NAME = 'name'; - /* name variants */ - const VN_MARITAL = 'marital'; - const VN_ORDINARY = 'ordinary'; - const VN_OTHER = 'other'; - const VN_INI = 'ini'; - /* display names */ - const DN_FULL = 'directory_name'; - const DN_DISPLAY = 'yourself'; - const DN_YOURSELF = 'yourself'; - const DN_DIRECTORY = 'directory_name'; - const DN_PRIVATE = 'private_name'; - const DN_PUBLIC = 'public_name'; - const DN_SHORT = 'short_name'; - const DN_SORT = 'sort_name'; - - static public $name_variants = array( - self::LASTNAME => array(self::VN_MARITAL, self::VN_ORDINARY), - self::FIRSTNAME => array(self::VN_ORDINARY, self::VN_INI, self::VN_OTHER) - ); static public function assertName($name) { @@ -1862,14 +1837,6 @@ class UserFilter extends PlFilter } } - static public function isDisplayName($name) - { - return $name == self::DN_FULL || $name == self::DN_DISPLAY - || $name == self::DN_YOURSELF || $name == self::DN_DIRECTORY - || $name == self::DN_PRIVATE || $name == self::DN_PUBLIC - || $name == self::DN_SHORT || $name == self::DN_SORT; - } - private $pn = array(); public function addNameFilter($type, $variant = null) { diff --git a/include/userset.inc.php b/include/userset.inc.php index 9bf11c9..fb6c5e8 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -94,7 +94,7 @@ class SearchSet extends ProfileSet $orders = $ufb->getOrders(); $orders[] = new UFO_Promo(UserFilter::DISPLAY, true); - $orders[] = new UFO_Promo(UserFilter::DN_SORT); + $orders[] = new UFO_Name(Profile::DN_SORT); if (S::logged() && Env::has('nonins')) { $this->conds = new PFC_And($this->conds, @@ -159,21 +159,21 @@ class MinificheView extends MultipageView new UFO_Score(true), new UFO_ProfileUpdate(true), new UFO_Promo(UserFilter::DISPLAY, true), - new UFO_Name(UserFilter::DN_SORT), + new UFO_Name(Profile::DN_SORT), ), 'pertinence')); } $this->addSort(new PlViewOrder( 'name', - array(new UFO_Name(UserFilter::DN_SORT)), + array(new UFO_Name(Profile::DN_SORT)), 'nom')); $this->addSort(new PlViewOrder('promo', array( new UFO_Promo(UserFilter::DISPLAY, true), - new UFO_Name(UserFilter::DN_SORT), + new UFO_Name(Profile::DN_SORT), ), 'promotion')); $this->addSort(new PlViewOrder('date_mod', array( new UFO_ProfileUpdate(true), new UFO_Promo(UserFilter::DISPLAY, true), - new UFO_Name(UserFilter::DN_SORT), + new UFO_Name(Profile::DN_SORT), ), 'dernière modification')); parent::__construct($set, $data, $params); } @@ -223,15 +223,15 @@ class MentorView extends MultipageView { $this->entriesPerPage = 10; $this->addSort(new PlViewOrder('rand', array(new PFO_Random(S::i('uid'))), 'aléatoirement')); - $this->addSort(new PlViewOrder('name', array(new UFO_Name(UserFilter::DN_SORT)), 'nom')); + $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); $this->addSort(new PlViewOrder('promo', array( new UFO_Promo(UserFilter::DISPLAY, true), - new UFO_Name(UserFilter::DN_SORT), + new UFO_Name(Profile::DN_SORT), ), 'promotion')); $this->addSort(new PlViewOrder('date_mod', array( new UFO_ProfileUpdate(true), new UFO_Promo(UserFilter::DISPLAY, true), - new UFO_Name(UserFilter::DN_SORT), + new UFO_Name(Profile::DN_SORT), ), 'dernière modification')); parent::__construct($set, $data, $params); } @@ -285,13 +285,13 @@ class TrombiView extends MultipageView new UFO_Score(true), new UFO_ProfileUpdate(true), new UFO_Promo(UserFilter::DISPLAY, true), - new UFO_Name(UserFilter::DN_SORT), + new UFO_Name(Profile::DN_SORT), ), 'pertinence')); } - $this->addSort(new PlViewOrder('name', array(new UFO_Name(UserFilter::DN_SORT)), 'nom')); + $this->addSort(new PlViewOrder('name', array(new UFO_Name(Profile::DN_SORT)), 'nom')); $this->addSort(new PlViewOrder('promo', array( new UFO_Promo(UserFilter::DISPLAY, true), - new UFO_Name(UserFilter::DN_SORT), + new UFO_Name(Profile::DN_SORT), ), 'promotion')); parent::__construct($set, $data, $params); } diff --git a/modules/marketing.php b/modules/marketing.php index bda1484..eecab75 100644 --- a/modules/marketing.php +++ b/modules/marketing.php @@ -212,7 +212,7 @@ class MarketingModule extends PLModule $uf = new UserFilter(new UFC_And(new UFC_Promo('=', UserFilter::DISPLAY, $promo), new UFC_Not(new UFC_Registered())), - array(new UFO_Name(UserFilter::LASTNAME), new UFO_Name(UserFilter::FIRSTNAME))); + array(new UFO_Name(Profile::LASTNAME), new UFO_Name(Profile::FIRSTNAME))); $users = $uf->getUsers(); $page->assign('nonins', $users); } diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 254819b..3348d2c 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -677,10 +677,10 @@ class XnetGrpModule extends PLModule list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom'))); $cond = new UFC_And(new UFC_Not(new UFC_Registered())); if (!empty($nom)) { - $cond->addChild(new UFC_Name(UserFilter::LASTNAME, $nom, UFC_Name::CONTAINS)); + $cond->addChild(new UFC_Name(Profile::LASTNAME, $nom, UFC_Name::CONTAINS)); } if (!empty($prenom)) { - $cond->addChild(new UFC_Name(UserFilter::FIRSTNAME, $prenom, UFC_Name::CONTAINS)); + $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $prenom, UFC_Name::CONTAINS)); } if (Env::i('promo')) { $cond->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, Env::i('promo'))); -- 2.1.4