Add function for fetching more info about a user's groups
authorRaphaël Barrois <raphael.barrois@polytechnique.org>
Sat, 20 Mar 2010 00:39:40 +0000 (01:39 +0100)
committerRaphaël Barrois <raphael.barrois@polytechnique.org>
Mon, 22 Mar 2010 13:07:51 +0000 (14:07 +0100)
Signed-off-by: Raphaël Barrois <raphael.barrois@polytechnique.org>
classes/user.php

index 83d7b0a..1ce06bc 100644 (file)
@@ -506,6 +506,20 @@ class User extends PlUser
         return $this->groups;
     }
 
+    public function groupNames($institutions = false)
+    {
+        if ($institutions) {
+            $where = ' AND (g.cat = \'GroupesX\' OR g.cat = \'Institutions\')';
+        } else {
+            $where = '';
+        }
+        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());
+    }
+
     /**
      * Clears a user.
      *  *always deletes in: account_lost_passwords, register_marketing,