From 34ade5a639500e0a43dfb5ccff4ecbac5fbda919 Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sun, 1 Feb 2009 20:10:48 +0100 Subject: [PATCH] Add a class Group to handler xnet groups. Signed-off-by: Florent Bruneau --- classes/group.php | 122 ++++++++++++++++++++++++++++++++++ classes/platalglobals.php.in | 21 ++---- classes/profile.php | 2 +- classes/user.php | 2 +- classes/xnetpage.php | 9 ++- core | 2 +- modules/xnetgrp.php | 30 +++------ templates/payment/xnet.tpl | 4 +- templates/profile/groupesx.tpl | 26 ++++---- templates/xnet/skin.tpl | 8 +-- templates/xnetevents/admin.tpl | 2 +- templates/xnetevents/calendar.tpl | 4 +- templates/xnetevents/edit.tpl | 4 +- templates/xnetevents/index.tpl | 4 +- templates/xnetevents/subscribe.tpl | 2 +- templates/xnetgrp/announce-admin.tpl | 2 +- templates/xnetgrp/announce-edit.tpl | 2 +- templates/xnetgrp/annuaire.tpl | 18 ++--- templates/xnetgrp/asso.tpl | 32 ++++----- templates/xnetgrp/edit.tpl | 46 ++++++------- templates/xnetgrp/forum.tpl | 2 +- templates/xnetgrp/inscrire.tpl | 10 +-- templates/xnetgrp/mail.tpl | 6 +- templates/xnetgrp/membres-add.tpl | 2 +- templates/xnetgrp/membres-del.tpl | 4 +- templates/xnetgrp/membres-edit.tpl | 2 +- templates/xnetgrp/subscribe-valid.tpl | 2 +- templates/xnetlists/alias-create.tpl | 2 +- templates/xnetlists/create.tpl | 4 +- templates/xnetlists/index.tpl | 8 +-- templates/xnetlists/sync.tpl | 2 +- 31 files changed, 243 insertions(+), 143 deletions(-) create mode 100644 classes/group.php diff --git a/classes/group.php b/classes/group.php new file mode 100644 index 0000000..62236db --- /dev/null +++ b/classes/group.php @@ -0,0 +1,122 @@ +$value) { + $this->data[$key] = $value; + } + $this->id = intval($this->data['id']); + $this->shortname = $this->data['diminutif']; + } + + public function __get($name) + { + if (property_exists($this, $name)) { + return $this->$name; + } + + if (isset($this->data[$name])) { + return $this->data[$name]; + } + + return null; + } + + public function __isset($name) + { + return property_exists($this, $name) || isset($this->data[$name]); + } + + public function getMemberUIDs() + { + if (is_null($this->members)) { + $this->members = XDB::fetchColumn('SELECT uid + FROM groupex.membres + WHERE asso_id = {?}', $this->id); + } + return $this->members; + } + + public function getMembers($sortby = null, $count = null, $offset = null) + { + return User::getBuildUsersWithUIDs($this->getMemberUIDs(), $sortby, $count, $offset); + } + + public function getMemberCount() + { + return count($this->getMemberUIDs()); + } + + public function getAdminUIDs() + { + if (is_null($this->admins)) { + $this->admins = XDB::fetchColumn('SELECT uid + FROM groupex.membres + WHERE asso_id = {?} AND perms = \'admin\'', $this->id); + } + return $this->admins; + } + + public function getAdmins($sortby = null, $count = null, $offset = null) + { + return User::getBuildUsersWithUIDs($this->getAdminUIDs(), $sortby, $count, $offset); + } + + public function getAdminCount() + { + return count($this->getAdminUIDs()); + } + + static public function get($id) + { + if (!$id) { + return null; + } + if (ctype_digit($id)) { + $where = XDB::format('id = {?}', $id); + } else { + $where = XDB::format('diminutif = {?}', $id); + } + $res = XDB::query('SELECT a.*, d.nom AS domnom, + FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc, + FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub + FROM groupex.asso AS a + LEFT JOIN groupex.dom AS d ON d.id = a.dom + WHERE ' . $where); + if ($res->numRows() != 1) { + return null; + } + return new Group($res->fetchOneAssoc()); + } +} + +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +?> diff --git a/classes/platalglobals.php.in b/classes/platalglobals.php.in index 00353f7..697c297 100644 --- a/classes/platalglobals.php.in +++ b/classes/platalglobals.php.in @@ -49,7 +49,7 @@ class PlatalGlobals extends PlGlobals $this->bootstrap(array('NbValid'), array($this, 'updateNbValid')); } - public function asso($key=null) + public function asso($key = null) { static $aid = null; @@ -59,30 +59,17 @@ class PlatalGlobals extends PlGlobals $gp = substr($gp, 0, $p); } - if ($gp) { - $res = XDB::query('SELECT a.*, d.nom AS domnom, - FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc, - FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub - FROM groupex.asso AS a - LEFT JOIN groupex.dom AS d ON d.id = a.dom - WHERE diminutif = {?}', $gp); - if (!($aid = $res->fetchOneAssoc())) { - $aid = array(); - } - } else { - $aid = array(); - } + $aid = Group::get($gp); } if (empty($key)) { return $aid; - } elseif ( isset($aid[$key]) ) { - return $aid[$key]; + } elseif (isset($aid->$key) ) { + return $aid->$key; } else { return null; } } - public function updateNbIns() { $res = XDB::query("SELECT COUNT(*) diff --git a/classes/profile.php b/classes/profile.php index d224585..6151a1a 100644 --- a/classes/profile.php +++ b/classes/profile.php @@ -1,6 +1,6 @@ déconnexion'; $html = '
Mes groupes (' . $links . ') :
'; while (list($nom, $mini) = $res->next()) { diff --git a/core b/core index a794b0b..b5e56a7 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a794b0bd619df7b333018eb8435f755032ea4e8b +Subproject commit b5e56a710b4bf25ed7b186c2cb9ea6e822db8fa3 diff --git a/modules/xnetgrp.php b/modules/xnetgrp.php index 27df50b..52e6092 100644 --- a/modules/xnetgrp.php +++ b/modules/xnetgrp.php @@ -328,20 +328,18 @@ class XnetGrpModule extends PLModule $sort = Env::s('order', 'directory_name'); $ofs = Env::i('offset'); + if ($ofs < 0) { + $ofs = 0; + } if (Env::b('admin')) { - $uids = XDB::fetchColumn('SELECT uid - FROM groupex.membres - WHERE asso_id = {?} AND perms = \'admin\'', - $globals->asso('id')); + $users = $globals->asso()->getAdmins($sort, NB_PER_PAGE, $ofs * NB_PER_PAGE); + $count = $globals->asso()->getAdminCount(); } else { - $uids = XDB::fetchColumn('SELECT uid - FROM groupex.membres - WHERE asso_id = {?}', $globals->asso('id')); + $users = $globals->asso()->getMembers($sort, NB_PER_PAGE, $ofs * NB_PER_PAGE); + $count = $globals->asso()->getMemberCount(); } - $users = User::getBuildUsersWithUIDs($uids, $sort, - NB_PER_PAGE, $ofs * NB_PER_PAGE); - $page->assign('pages', (count($uids) + NB_PER_PAGE - 1) / NB_PER_PAGE); + $page->assign('pages', ($count + NB_PER_PAGE - 1) / NB_PER_PAGE); $page->assign('current', $ofs); $page->assign('order', $sort); $page->assign('users', $users); @@ -361,11 +359,8 @@ class XnetGrpModule extends PLModule function handler_vcard(&$page, $photos = null) { global $globals; - $res = XDB::query('SELECT uid - FROM groupex.membres - WHERE asso_id = {?}', $globals->asso('id')); $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); - $vcard->addUsers($res->fetchColumn()); + $vcard->addUsers($globals->asso()->getMemberUIDs()); $vcard->show(); } @@ -375,11 +370,7 @@ class XnetGrpModule extends PLModule if (is_null($filename)) { $filename = $globals->asso('diminutif') . '.csv'; } - $id = XDB::fetchColumn("SELECT uid - FROM groupex.membres - WHERE asso_id = {?}", - $globals->asso('id')); - $users = User::getBuildUsersWithUIDs($id, 'full_name'); + $users = $globals->asso()->getMembers('directory_name'); header('Content-Type: text/x-csv; charset=utf-8;'); header('Pragma: '); header('Cache-Control: '); @@ -593,7 +584,6 @@ class XnetGrpModule extends PLModule break; } } -// var_dump($_SESSION); http_redirect($_SERVER['HTTP_REFERER']); } diff --git a/templates/payment/xnet.tpl b/templates/payment/xnet.tpl index 599a551..4f25b69 100644 --- a/templates/payment/xnet.tpl +++ b/templates/payment/xnet.tpl @@ -20,10 +20,10 @@ {* *} {**************************************************************************} -

{$asso.nom} : Gestion des télépaiements

+

{$asso->nom} : Gestion des télépaiements

-Voici la liste des paiements en ligne possible pour le groupe {$asso.nom} : +Voici la liste des paiements en ligne possible pour le groupe {$asso->nom} :

{foreach from=$titres item=p} diff --git a/templates/profile/groupesx.tpl b/templates/profile/groupesx.tpl index b9c6b49..9f6566b 100644 --- a/templates/profile/groupesx.tpl +++ b/templates/profile/groupesx.tpl @@ -29,26 +29,26 @@ {foreach from=$assos item="asso"}
- {$asso.nom} - {if $asso.has_logo} - - [ LOGO ] + {$asso->nom} + {if $asso->has_logo} + + [ LOGO ] {/if} diff --git a/templates/xnet/skin.tpl b/templates/xnet/skin.tpl index 2899130..9326e03 100644 --- a/templates/xnet/skin.tpl +++ b/templates/xnet/skin.tpl @@ -82,8 +82,8 @@ {if $asso} - {if $asso.site} - LOGO + {if $asso->site} + LOGO {else} LOGO {/if} @@ -116,9 +116,9 @@ {/if} {/foreach} {/foreach} - {if $asso && ($is_admin || + {if $asso && $is_admin} {* WARN: this breaks "see the site as" || ($smarty.session.suid && ($smarty.session.suid.perms->hasFlag('admin') || - $smarty.session.suid.may_update[$asso.id])))} + $smarty.session.suid.may_update[$asso->id])))} *}

Voir le site comme...

diff --git a/templates/xnetevents/admin.tpl b/templates/xnetevents/admin.tpl index ab83d43..80c3fa7 100644 --- a/templates/xnetevents/admin.tpl +++ b/templates/xnetevents/admin.tpl @@ -20,7 +20,7 @@ {* *} {**************************************************************************} -

{$asso.nom} : Événements

+

{$asso->nom} : Événements

{if $evt.titre || count($moments) eq 1} diff --git a/templates/xnetevents/calendar.tpl b/templates/xnetevents/calendar.tpl index 4798a0d..9b50789 100644 --- a/templates/xnetevents/calendar.tpl +++ b/templates/xnetevents/calendar.tpl @@ -25,13 +25,13 @@ VERSION:2.0 CALSCALE:GREGORIAN X-WR-TIMEZONE:Europe/Paris METHOD:PUBLISH -{display_ical name="x-wr-calname" value=$asso.nom} +{display_ical name="x-wr-calname" value=$asso->nom} BEGIN:VEVENT DSTAMP:{$timestamp|date_format:"%Y%m%dT%H%M%SZ"} DTSTART;VALUE=DATE;TZID=Europe/Paris:{$e.debut} DTEND;VALUE=DATE;TZID=Europe/Paris:{$e.fin} ORGANIZER;CN="{$e.prenom} {$e.nom}":MAILTO:{$e.alias}@polytechnique.org -UID:event-{$e.short_name}-{$e.eid}@{$asso.diminutif}.polytechnique.org +UID:event-{$e.short_name}-{$e.eid}@{$asso->diminutif}.polytechnique.org {if $admin} {foreach from=$participants item=m} {if $m.x} diff --git a/templates/xnetevents/edit.tpl b/templates/xnetevents/edit.tpl index 31ab564..661826a 100644 --- a/templates/xnetevents/edit.tpl +++ b/templates/xnetevents/edit.tpl @@ -35,7 +35,7 @@ function deadlineChange(box) {/literal} -

{$asso.nom} : {$evt.intitule|default:"Nouvel événement"}

+

{$asso->nom} : {$evt.intitule|default:"Nouvel événement"}

Un événement peut être une réunion, un séminaire, une conférence, un voyage promo, @@ -184,7 +184,7 @@ Ton inscription à [METS LE NOM DE L'EVENEMENT ICI] a bien été enregistrée et -- {$smarty.session.prenom} {$smarty.session.nom}{/if}
- Page internet de l'événement :
+ Page internet de l'événement :
Le nouveau paiement sera activé automatiquement après validation par le trésorier de Polytechnique.org, ce qui sera fait sous peu. -

{$asso.nom} : Édition d'une annonce

+

{$asso->nom} : Édition d'une annonce

{if $art.texte}
diff --git a/templates/xnetgrp/annuaire.tpl b/templates/xnetgrp/annuaire.tpl index 7ed7eb6..ee05e60 100644 --- a/templates/xnetgrp/annuaire.tpl +++ b/templates/xnetgrp/annuaire.tpl @@ -20,10 +20,10 @@ {* *} {**************************************************************************} -

{$asso.nom} : Annuaire du groupe

+

{$asso->nom} : Annuaire du groupe

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

@@ -112,9 +112,11 @@ Le groupe {$asso.nom} compte {$nb_tot} membres : {if $user->group_comm} {$user->group_comm} {/if} - group_comm}colspan="2"{/if}> - {icon name=vcard title="[vcard]"} - {icon name=email title="email"} + group_comm}colspan="2"{/if}> + {if $user->hasProfile()} + {icon name=vcard title="[vcard]"} + {/if} + {icon name=email title="email"} {if $is_admin} diff --git a/templates/xnetgrp/asso.tpl b/templates/xnetgrp/asso.tpl index 5714102..41b468f 100644 --- a/templates/xnetgrp/asso.tpl +++ b/templates/xnetgrp/asso.tpl @@ -20,52 +20,52 @@ {* *} {**************************************************************************} -

{$asso.nom} : Accueil

+

{$asso->nom} : Accueil

- {if $asso.site} + {if $asso->site} - + {/if} - {if $asso.resp || $asso.mail} + {if $asso->resp || $asso->mail} {/if} - {if $asso.forum} + {if $asso->forum} {/if} - {if !$is_member && $is_logged && $asso.inscriptible && $xnet_type != 'promotions'} + {if !$is_member && $is_logged && $asso->inscriptible && $xnet_type != 'promotions'} {elseif $is_member} @@ -74,12 +74,12 @@ Me désinscrire : {/if} - {if $asso.ax} + {if $asso->ax} @@ -39,7 +39,7 @@ Diminutif : @@ -47,7 +47,7 @@ Domaine DNS : @@ -56,10 +56,10 @@ @@ -71,7 +71,7 @@ @@ -94,7 +94,7 @@ Site web : @@ -103,7 +103,7 @@ Contact : @@ -112,7 +112,7 @@ Adresse email : @@ -121,7 +121,7 @@ Forum : @@ -131,11 +131,11 @@ @@ -147,7 +147,7 @@ laisser vide par défaut @@ -157,13 +157,13 @@ laisser vide par défaut @@ -172,15 +172,15 @@ @@ -198,7 +198,7 @@ {icon name=information title="Syntaxe wiki"} Voir la syntaxe wiki autorisée pour la description. + {if !$asso->wiki_desc && $asso->descr}class="error"{/if}>{$asso->descr}
diff --git a/templates/xnetgrp/forum.tpl b/templates/xnetgrp/forum.tpl index b56abee..80604c7 100644 --- a/templates/xnetgrp/forum.tpl +++ b/templates/xnetgrp/forum.tpl @@ -20,7 +20,7 @@ {* *} {**************************************************************************} -

{$asso.nom} : Forum

+

{$asso->nom} : Forum

{$banana|smarty:nodefaults} diff --git a/templates/xnetgrp/inscrire.tpl b/templates/xnetgrp/inscrire.tpl index 0eac944..28a4d5d 100644 --- a/templates/xnetgrp/inscrire.tpl +++ b/templates/xnetgrp/inscrire.tpl @@ -20,7 +20,7 @@ {* *} {**************************************************************************} -

Demande d'inscription à {$asso.nom}

+

Demande d'inscription à {$asso->nom}

{if $user && $is_admin && $show_form} @@ -62,26 +62,26 @@

Ta demande d'inscription a bien été envoyée ! Tu seras averti par email de la suite qui lui sera donnée.

-

[Retour à la page d'accueil de {$asso.nom}]

+

[Retour à la page d'accueil de {$asso->nom}]

{else}

-Pour t'inscrire à {$asso.nom}, il te faut en demander l'autorisation aux animateurs du groupe via le +Pour t'inscrire à {$asso->nom}, il te faut en demander l'autorisation aux animateurs du groupe via le formulaire ci-dessous. Vérifie et corrige au besoin les différents champs, puis clique sur [ M'inscrire ! ].

{xsrf_token_field}

- OUI, je souhaite être inscrit au groupe {$asso.nom}. + OUI, je souhaite être inscrit au groupe {$asso->nom}.

Indique ci-après tes motivations qui seront communiquées aux animateurs du groupe :

diff --git a/templates/xnetgrp/membres-add.tpl b/templates/xnetgrp/membres-add.tpl index cff436b..01ddadf 100644 --- a/templates/xnetgrp/membres-add.tpl +++ b/templates/xnetgrp/membres-add.tpl @@ -52,7 +52,7 @@ function searchX() {/literal} //]]> -

{$asso.nom} : Ajout d'un membre

+

{$asso->nom} : Ajout d'un membre

{xsrf_token_field} diff --git a/templates/xnetgrp/membres-del.tpl b/templates/xnetgrp/membres-del.tpl index 7bbd86e..9a46b52 100644 --- a/templates/xnetgrp/membres-del.tpl +++ b/templates/xnetgrp/membres-del.tpl @@ -32,7 +32,7 @@ {else} -

{$asso.nom} : gestion des membres

+

{$asso->nom} : gestion des membres

Suppression du membre : {$user.prenom} {$user.nom} @@ -44,7 +44,7 @@

{if $self} - Êtes-vous sûr de vouloir vous désinscrire du groupe {$asso.nom} et de toutes + Êtes-vous sûr de vouloir vous désinscrire du groupe {$asso->nom} et de toutes les listes de diffusion associées ? {else} Êtes-vous sûr de vouloir supprimer {$user.prenom} {$user.nom} du groupe, diff --git a/templates/xnetgrp/membres-edit.tpl b/templates/xnetgrp/membres-edit.tpl index d36e235..044f821 100644 --- a/templates/xnetgrp/membres-edit.tpl +++ b/templates/xnetgrp/membres-edit.tpl @@ -40,7 +40,7 @@ {/literal} -

{$asso.nom} : gestion des membres

+

{$asso->nom} : gestion des membres

[Retour à l'annuaire] diff --git a/templates/xnetgrp/subscribe-valid.tpl b/templates/xnetgrp/subscribe-valid.tpl index 51348c9..8d4cfac 100644 --- a/templates/xnetgrp/subscribe-valid.tpl +++ b/templates/xnetgrp/subscribe-valid.tpl @@ -20,7 +20,7 @@ {* *} {**************************************************************************} -

{$asso.nom} : Validation des inscriptions

+

{$asso->nom} : Validation des inscriptions

Site Web : {$asso.site}{$asso->site}
Contact : - {if $asso.mail} - {mailto address=$asso.mail text=$asso.resp|utf8_decode|default:"par email" encode=javascript} + {if $asso->mail} + {mailto address=$asso->mail text=$asso->resp|utf8_decode|default:"par email" encode=javascript} {else} - {$asso.resp} + {$asso->resp} {/if}
Forum : par le web - ou par nntp + ou par nntp
M'inscrire : - m'inscrire + m'inscrire
- me désinscrire + me désinscrire
groupe agréé par l'AX @@ -99,10 +99,10 @@
- {if $asso.wiki_desc} - {$asso.descr|miniwiki:title|smarty:nodefaults} + {if $asso->wiki_desc} + {$asso->descr|miniwiki:title|smarty:nodefaults} {else} - {$asso.descr|smarty:nodefaults} + {$asso->descr|smarty:nodefaults} {/if}
diff --git a/templates/xnetgrp/edit.tpl b/templates/xnetgrp/edit.tpl index ce76dbf..5f0277b 100644 --- a/templates/xnetgrp/edit.tpl +++ b/templates/xnetgrp/edit.tpl @@ -20,7 +20,7 @@ {* *} {**************************************************************************} -

{if $asso.nom}{$asso.nom} : {/if}Éditer l'accueil

+

{if $asso->nom}{$asso->nom} : {/if}Éditer l'accueil

{xsrf_token_field} @@ -31,7 +31,7 @@ Nom :
- +
- +
- +
- +
- +
- +
- +
inscriptible eq 1}checked="checked"{/if} name="inscriptible" /> inscriptible neq 1}checked="checked"{/if} name="inscriptible" /> - +
- +
-
Diffusion de la liste des membres :
-