<?php
/***************************************************************************
- * Copyright (C) 2003-2010 Polytechnique.org *
+ * Copyright (C) 2003-2014 Polytechnique.org *
* http://opensource.polytechnique.org/ *
* *
* This program is free software; you can redistribute it and/or modify *
case 'promo':
return new UFO_Promo($export->v('grade'), $desc);
- case 'lastname':
case 'name':
- case 'firstname':
- case 'nickname':
- case 'pseudonym':
- return new UFO_Name($type, $export->v('variant'),
- $export->b('particle'), $desc);
+ return new UFO_Name($desc);
case 'score':
case 'registration':
case 'hruid':
case 'pid':
case 'hrpid':
+ case 'is_admin':
$class = 'UFO_' . str_replace('_', '', $type);
return new $class($desc);
protected function getSortTokens(PlFilter $uf)
{
if (UserFilter::isGrade($this->grade)) {
- $sub = $uf->addEducationFilter($this->grade);
+ $sub = $uf->addEducationFilter(true, $this->grade);
return 'pe' . $sub . '.' . UserFilter::promoYear($this->grade);
} else {
$sub = $uf->addDisplayFilter();
}
}
+ public function getCondition($promo)
+ {
+ return new UFC_Promo(UserFilterCondition::OP_EQUALS, $this->grade, $promo);
+ }
+
public function export()
{
$export = $this->buildExport('promo');
// }}}
// {{{ class UFO_Name
/** Sorts users by name
- * @param $type Type of name on which to sort (firstname...)
- * @param $variant Variant of that name to use (marital, ordinary...)
- * @param $particle Set to true if particles should be included in the sorting order
* @param $desc If sort order should be descending
*/
-class UFO_Name extends PlFilterOrder
+class UFO_Name extends PlFilterGroupableOrder
{
- private $type;
- private $variant;
- private $particle;
+ protected function getSortTokens(PlFilter $uf)
+ {
+ $sub = $uf->addDisplayFilter();
+ $token = 'pd.sort_name';
+ if ($uf->accountsRequired()) {
+ $account_token = Profile::getAccountEquivalentName('sort_name');
+ return 'IFNULL(' . $token . ', a.' . $account_token . ')';
+ } else {
+ return $token;
+ }
+ }
- public function __construct($type, $variant = null, $particle = false, $desc = false)
+ public function getGroupToken(PlFilter $pf)
{
- parent::__construct($desc);
- $this->type = $type;
- $this->variant = $variant;
- $this->particle = $particle;
+ return 'SUBSTRING(' . $this->_tokens . ', 1, 1)';
}
- protected function getSortTokens(PlFilter $uf)
+ public function getCondition($initial)
{
- if (Profile::isDisplayName($this->type)) {
- $sub = $uf->addDisplayFilter();
- $token = 'pd' . $sub . '.' . $this->type;
- if ($uf->accountsRequired()) {
- $account_token = Profile::getAccountEquivalentName($this->type);
- return 'IFNULL(' . $token . ', a.' . $account_token . ')';
- } else {
- return $token;
- }
- } else {
- $sub = $uf->addNameFilter($this->type, $this->variant);
- if ($this->particle) {
- return 'CONCAT(pn' . $sub . '.particle, \' \', pn' . $sub . '.name)';
- } else {
- return 'pn' . $sub . '.name';
- }
- }
+ return new UFC_NameInitial($initial);
}
public function export()
{
- $export = $this->buildExport($this->type);
- if (!is_null($this->variant)) {
- $export['variant'] = $this->variant;
- }
- if ($this->particle) {
- $export['particle'] = true;
- }
+ $export = $this->buildExport();
return $export;
}
}
}
}
// }}}
+// {{{ class UFO_IsAdmin
+/** Sorts users, putting admins first
+ */
+class UFO_IsAdmin extends PlFilterOrder
+{
+ protected function getSortTokens(PlFilter $uf)
+ {
+ $uf->requireAccounts();
+ return 'a.is_admin';
+ }
+
+ public function export()
+ {
+ return $this->buildExport('is_admin');
+ }
+}
+// }}}
// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
?>