From 56cd7aeef7f34f7dec76564821330be5d587b72c Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Wed, 29 Sep 2010 14:47:02 +0200 Subject: [PATCH] Show only 'public' groups on the profile. Signed-off-by: Florent Bruneau --- classes/user.php | 39 +++++++++++++++++++++++---------------- templates/profile/profile.tpl | 6 +++--- 2 files changed, 26 insertions(+), 19 deletions(-) diff --git a/classes/user.php b/classes/user.php index 49f7931..fcd4fb5 100644 --- a/classes/user.php +++ b/classes/user.php @@ -584,29 +584,36 @@ class User extends PlUser // Groupes X private $groups = null; - public function groups() + public function groups($institutions = false, $onlyPublic = false) { if (is_null($this->groups)) { - $this->groups = XDB::fetchAllAssoc('asso_id', 'SELECT asso_id, perms, comm - FROM group_members + $this->groups = XDB::fetchAllAssoc('asso_id', 'SELECT gm.asso_id, gm.perms, gm.comm, + g.diminutif, g.nom, g.site, g.cat, + g.pub + FROM group_members AS gm + INNER JOIN groups AS g ON (g.id = gm.asso_id) WHERE uid = {?}', $this->id()); } - return $this->groups; - } - - public function groupNames($institutions = false) - { - if ($institutions) { - $where = ' AND (g.cat = \'GroupesX\' OR g.cat = \'Institutions\')'; + if (!$institutions && !$onlyPublic) { + return $this->groups; } else { - $where = ''; + $result = array(); + foreach ($this->groups as $id=>$data) { + if ($institutions) { + if ($data['cat'] != 'GroupesX' && $data['cat'] != 'Institutions') { + continue; + } + } + if ($onlyPublic) { + if ($data['pub'] != 'public') { + continue; + } + } + $result[$id] = $data; + } + return $result; } - return XDB::fetchAllAssoc('SELECT g.diminutif, g.nom, g.site - FROM group_members AS gm - LEFT JOIN groups AS g ON (g.id = gm.asso_id) - WHERE gm.uid = {?}' . $where, - $this->id()); } /** diff --git a/templates/profile/profile.tpl b/templates/profile/profile.tpl index 863cbdc..d02d153 100644 --- a/templates/profile/profile.tpl +++ b/templates/profile/profile.tpl @@ -44,7 +44,7 @@ function chgMainWinLoc(strPage) {assign var=photo value=$profile->getPhoto(false)} {if $photo}Photo de {$profile->fullName()}{/if} - {if $logged && $view eq 'private' && ( $profile->section|smarty:nodefaults || $profile->getBinets()|smarty:nodefaults || ($owner && $owner->groups()|smarty:nodefaults))} + {if $logged && $view eq 'private' && ( $profile->section|smarty:nodefaults || $profile->getBinets()|smarty:nodefaults || ($owner && $owner->groups(true,true)|smarty:nodefaults))}

À l'X…

{if $profile->section}
Section : {$profile->section}
{/if} @@ -53,10 +53,10 @@ function chgMainWinLoc(strPage) {', '|implode:$profile->getBinetsNames()}{/if} {if $owner && $view eq 'private'} - {assign var=groups value=$owner->groupNames(true)} + {assign var=groups value=$owner->groups(true,true)} {if $groups|@count}
Groupe{if count($groups) > 1}s{/if} et institution{if count($groups) > 1}s{/if} X :
- {foreach from=$groups item=group key=gk}{if $gk != 0}, {/if}{$group.nom}{/foreach} + {foreach from=$groups item=group name=groups}{if !$smarty.foreach.groups.first}, {/if}{$group.nom}{/foreach}
{/if} {/if} -- 2.1.4