Show only 'public' groups on the profile.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 29 Sep 2010 12:47:02 +0000 (14:47 +0200)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Wed, 29 Sep 2010 12:47:02 +0000 (14:47 +0200)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
classes/user.php
templates/profile/profile.tpl

index 49f7931..fcd4fb5 100644 (file)
@@ -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());
     }
 
     /**
index 863cbdc..d02d153 100644 (file)
@@ -44,7 +44,7 @@ function chgMainWinLoc(strPage)
     {assign var=photo value=$profile->getPhoto(false)}
     {if $photo}<img alt="Photo de {$profile->fullName()}" src="photo/{$profile->hrid()}{if $with_pending_pic}/req{/if}" width="{$photo->width()}"/>{/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))}
       <h2>À l'X&hellip;</h2>
       {if $profile->section}<div><em class="intitule">Section&nbsp;: </em><span>{$profile->section}</span></div>{/if}
 
@@ -53,10 +53,10 @@ function chgMainWinLoc(strPage)
       <span>{', '|implode:$profile->getBinetsNames()}</span></div>{/if}
 
       {if $owner && $view eq 'private'}
-        {assign var=groups value=$owner->groupNames(true)}
+        {assign var=groups value=$owner->groups(true,true)}
         {if $groups|@count}<div><em class="intitule">Groupe{if count($groups) > 1}s{/if} et institution{if count($groups) > 1}s{/if} X&nbsp;: </em>
         <span><br/>
-        {foreach from=$groups item=group key=gk}{if $gk != 0}, {/if}<span title="{$group.nom}"><a href="{$group.site}">{$group.nom}</a></span>{/foreach}
+        {foreach from=$groups item=group name=groups}{if !$smarty.foreach.groups.first}, {/if}<span title="{$group.nom}"><a href="{$group.site}">{$group.nom}</a></span>{/foreach}
         </span></div>{/if}
       {/if}