Merge remote branch 'origin/xorg/maint' into xorg/master
[platal.git] / classes / group.php
index b5f4500..db1a7ef 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -37,6 +37,9 @@ class Group
         }
         $this->id = intval($this->data['id']);
         $this->shortname = $this->data['diminutif'];
+        if (!is_null($this->axDate)) {
+            $this->axDate = format_datetime($this->axDate, '%d/%m/%Y');
+        }
     }
 
     public function __get($name)
@@ -113,9 +116,11 @@ 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
+                                   FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub,
+                                   (nls.id IS NOT NULL) AS has_nl
                              FROM  groups AS a
                         LEFT JOIN  group_dom  AS d ON d.id = a.dom
+                        LEFT JOIN  newsletters AS nls ON (nls.group_id = a.id)
                             WHERE  ' . $where);
         if ($res->numRows() != 1) {
             if ($can_be_shortname && (is_int($id) || ctype_digit($id))) {
@@ -123,7 +128,13 @@ class Group
             }
             return null;
         }
-        return new Group($res->fetchOneAssoc());
+        $data = $res->fetchOneAssoc();
+        $positions = XDB::fetchAllAssoc('SELECT  position, uid
+                                           FROM  group_members
+                                          WHERE  asso_id = {?} AND position IS NOT NULL
+                                       ORDER BY  position',
+                                        $data['id']);
+        return new Group(array_merge($data, array('positions' => $positions)));
     }
 }