Fixes bugs in name edition.
[platal.git] / classes / group.php
index c75191b..ce93e92 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2009 Polytechnique.org                              *
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -56,27 +56,49 @@ class Group
     {
         $cond = new UFC_Group($this->id, $admin);
         if (!is_null($extra_cond)) {
-            $cond = new UFC_And($cond, $extra_cond);
+            $cond = new PFC_And($cond, $extra_cond);
         }
         return new UserFilter($cond, $sort);
     }
 
-    public function getMembers($extra_cond = null, $sort = null)
+    public function getMembersFilter($extra_cond = null, $sort = null)
     {
         return $this->getUF(false, $extra_cond, $sort);
     }
 
-    public function getAdmins($extra_cond = null, $sort = null)
+    public function getAdminsFilter($extra_cond = null, $sort = null)
     {
         return $this->getUF(true, $extra_cond, $sort);
     }
 
+    public function iterMembers($extra_cond = null, $sort = null, $limit = null)
+    {
+        $uf = getMembersFilter($extra_cond, $sort);
+        return $uf->iterUsers($limit);
+    }
+
+    public function iterAdmins($extra_cond = null, $sort = null, $limit = null)
+    {
+        $uf = getAdminsFilter($extra_cond, $sort);
+        return $uf->iterUsers($limit);
+    }
+
+    public function getLogo($fallback = true)
+    {
+        if (!empty($this->logo)) {
+            return PlImage::fromData($this->logo, $this->logo_mime);
+        } else if ($fallback) {
+            return PlImage::fromFile(dirname(__FILE__).'/../htdocs/images/dflt_carre.jpg', 'image/jpeg');
+        }
+        return null;
+    }
+
     static public function get($id)
     {
         if (!$id) {
             return null;
         }
-        if (ctype_digit($id)) {
+        if (is_int($id) || ctype_digit($id)) {
             $where = XDB::format('id = {?}', $id);
         } else {
             $where = XDB::format('diminutif = {?}', $id);
@@ -84,8 +106,8 @@ class Group
         $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
+                             FROM  groups AS a
+                        LEFT JOIN  group_dom  AS d ON d.id = a.dom
                             WHERE  ' . $where);
         if ($res->numRows() != 1) {
             return null;