From 4b8668886619b89c4c66b7b24deefaa1c28ef696 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Sat, 7 May 2011 00:44:05 +0200 Subject: [PATCH] Use PlSet for xnet group directories (Closes #1179). MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Create a new UserView similar to ProfileView for User objects * Create a new XnetUserView for displaying X.net group members * Update the directory handler to use PlSet instead Signed-off-by: Raphaël Barrois --- include/userset.inc.php | 62 +++++++++++++++++++ modules/xnetgrp.php | 55 ++++------------- templates/include/plview.xnetuser.entry.tpl | 45 ++++++++++++++ templates/include/plview.xnetuser.tpl | 40 ++++++++++++ templates/xnetgrp/annuaire.tpl | 96 ++--------------------------- 5 files changed, 163 insertions(+), 135 deletions(-) create mode 100644 templates/include/plview.xnetuser.entry.tpl create mode 100644 templates/include/plview.xnetuser.tpl diff --git a/include/userset.inc.php b/include/userset.inc.php index 2c58419..be7564d 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -302,6 +302,68 @@ class TrombiView extends ProfileView } } +/** A multipage view for users + * Allows the display of bounds when sorting by name or promo. + */ +abstract class UserView extends MultipageView +{ + protected function getBoundValue($user) + { + if ($user instanceof User) { + switch ($this->bound_field) { + case 'name': + $name = $user->lastName(); + return strtoupper($name); + case 'promo': + if ($user->hasProfile()) { + return $user->profile()->promo(); + } else { + return null; + } + default: + return null; + } + } + return null; + } + + public function bounds() + { + $order = Env::v('order', $this->defaultkey); + $show_bounds = 0; + if (($order == "name") || ($order == "-name")) { + $this->bound_field = "name"; + $show_bounds = 1; + } elseif (($order == "promo") || ($order == "-promo")) { + $this->bound_field = "promo"; + $show_bounds = -1; + } + if ($order{0} == '-') { + $show_bounds = -$show_bounds; + } + return $show_bounds; + } +} + +class XnetFicheView extends UserView +{ + public function __construct(PlSet $set, array $params) + { + $this->entriesPerPage = 20; + $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(Profile::DN_SORT), + ), 'promotion')); + parent::__construct($set, $params); + } + + public function templateName() + { + return 'include/plview.xnetuser.tpl'; + } +} + class GadgetView implements PlView { public function __construct(PlSet $set, array $params) diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index dd225ac..9193a60 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -324,53 +324,22 @@ class XnetGrpModule extends PLModule { global $globals; + __autoload('userset'); + $admins = false; if ($action == 'trombi') { - __autoload('userset'); - if ($action == 'trombi') { - $view = new ProfileSet(new UFC_Group($globals->asso('id'))); - } else { - $view = new UserSet(new UFC_Group($globals->asso('id'))); + $view = new ProfileSet(new UFC_Group($globals->asso('id'))); + } else { + if ($action == 'admins') { + $admins = true; + $action = $subaction; } - $view->addMod('trombi', 'Trombinoscope'); - $view->apply('annuaire', $page, $action, $subaction); - $page->changeTpl('xnetgrp/annuaire.tpl'); - $count = XDB::fetchOneCell('SELECT COUNT(*) - FROM group_members - WHERE asso_id = {?}', - $globals->asso('id')); - $page->assign('nb_tot', $count); - return; + $view = new UserSet(new UFC_Group($globals->asso('id'), $admins)); } - + $view->addMod('xnetfiche', 'Annuaire'); + $view->addMod('trombi', 'Trombinoscope'); + $view->apply('annuaire', $page, $action); + $page->assign('only_admin', $admins); $page->changeTpl('xnetgrp/annuaire.tpl'); - $sort = Env::s('order', 'directory_name'); - $ofs = Env::i('offset'); - if ($ofs < 0) { - $ofs = 0; - } - - $sdesc = $sort{0} == '-'; - $sf = $sdesc ? substr($sort, 1) : $sort; - if ($sf == 'promo') { - $se = new UFO_Promo(null, $sdesc); - } else { - $se = new UFO_Name($sf, null, null, $sdesc); - } - - if (Env::b('admin')) { - $uf = $globals->asso()->getAdminsFilter(null, $se); - } else { - $uf = $globals->asso()->getMembersFilter(null, $se); - } - $users = $uf->getUsers(new PlLimit(NB_PER_PAGE, $ofs * NB_PER_PAGE)); - $count = $uf->getTotalCount(); - - $page->assign('nb_tot', $count); - $page->assign('pages', floor(($count + NB_PER_PAGE - 1) / NB_PER_PAGE)); - $page->assign('current', $ofs); - $page->assign('order', $sort); - $page->assign('users', $users); - $page->assign('only_admin', Env::b('admin')); } function handler_trombi($page) diff --git a/templates/include/plview.xnetuser.entry.tpl b/templates/include/plview.xnetuser.entry.tpl new file mode 100644 index 0000000..07c7033 --- /dev/null +++ b/templates/include/plview.xnetuser.entry.tpl @@ -0,0 +1,45 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + + + + {profile user=$user promo=false} + + + {if $user->group_perms eq 'admin' && $user->category()}{/if} + {$user->category()|default:"Extérieur"} + {if $user->group_perms eq 'admin' && $user->category()}{/if} + + {if $user->group_comm}{$user->group_comm}{else} {/if} + + {if $user->hasProfile()} + {icon name=vcard title="[vcard]"} + {/if} + {icon name=email title="email"} + + {if $is_admin} + + {icon name=user_edit title="Édition du profil"} + {icon name=delete title="Supprimer de l'annuaire"} + + {/if} + diff --git a/templates/include/plview.xnetuser.tpl b/templates/include/plview.xnetuser.tpl new file mode 100644 index 0000000..8a0342b --- /dev/null +++ b/templates/include/plview.xnetuser.tpl @@ -0,0 +1,40 @@ +{**************************************************************************} +{* *} +{* Copyright (C) 2003-2011 Polytechnique.org *} +{* http://opensource.polytechnique.org/ *} +{* *} +{* This program is free software; you can redistribute it and/or modify *} +{* it under the terms of the GNU General Public License as published by *} +{* the Free Software Foundation; either version 2 of the License, or *} +{* (at your option) any later version. *} +{* *} +{* This program is distributed in the hope that it will be useful, *} +{* but WITHOUT ANY WARRANTY; without even the implied warranty of *} +{* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *} +{* GNU General Public License for more details. *} +{* *} +{* You should have received a copy of the GNU General Public License *} +{* along with this program; if not, write to the Free Software *} +{* Foundation, Inc., *} +{* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *} +{* *} +{**************************************************************************} + + + + + + + + {if $is_admin} + + {/if} + + {assign var=lostUsers value=false} + {foreach from=$set item=user} + {if $user->lost}{assign var=lostUsers value=true}{/if} + {include file="include/plview.xnetuser.entry.tpl" user=$user} + {/foreach} +
NomPromoInfosActions
+ +{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/xnetgrp/annuaire.tpl b/templates/xnetgrp/annuaire.tpl index f86c54c..70b1c26 100644 --- a/templates/xnetgrp/annuaire.tpl +++ b/templates/xnetgrp/annuaire.tpl @@ -23,7 +23,7 @@

{$asso->nom} : Annuaire du groupe

-Le groupe {$asso->nom} compte {$nb_tot} membres : +Le groupe {$asso->nom} compte {$plset_count} membres :

-{if $plset_base} -{include core=plset.tpl} -{else} -

-[tous les membres] -[animateurs]
-{* - XXX: This code has been temporary dropped, waiting for a cleaner way to do that stuff -{foreach from=$alphabet item=c} -{if $c} -[{$c}] -{/if} -{/foreach} -*} +[tous les membres] +[animateurs]

- - - - - - {if $is_admin} - - {/if} - - {assign var=lostUsers value=false} - {foreach from=$users item=user} - - - - {if $user->group_comm} - - {/if} - - {if $is_admin} - - {/if} - - {/foreach} -
- - {if $order eq 'directory_name'} - - {elseif $order eq '-directory_name'} - - {/if} - NOM Prénom - - - - {if $order eq '-promo'} - - {elseif $order eq 'promo'} - - {/if} - Promo - - InfosActions
- {if $user->lost}{assign var=lostUsers value=true}{/if} - {profile user=$user promo=false} - - {if $user->group_perms eq 'admin' && $user->category()}{/if} - {$user->category()|default:"Extérieur"} - {if $user->group_perms eq 'admin' && $user->category()}{/if} - {$user->group_comm}group_comm} colspan="2"{/if}> - {if $user->hasProfile()} - {icon name=vcard title="[vcard]"} - {/if} - {icon name=email title="email"} - - {icon name=user_edit title="Édition du profil"} - {icon name=delete title="Supprimer de l'annuaire"} -
- -{if $pages gt 1} -

-{section name="links" loop=$pages} -{if $smarty.section.links.index eq $current} -{$smarty.section.links.iteration} -{else} -{if $smarty.section.links.first} -précédente -{/if} -{$smarty.section.links.iteration} -{if $smarty.section.links.last} -suivante -{/if} -{/if} -{/section} -

-{/if} +{include core=plset.tpl} {if $lostUsers}

@@ -171,6 +85,4 @@ Le groupe {$asso->nom} compte {$nb_tot} membres :

{/if} -{/if} - {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} -- 2.1.4