2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
26 private $data = array();
28 private $members = null
;
29 private $admins = null
;
31 private function __construct(array $data)
33 foreach ($data as $key=>$value) {
34 $this->data
[$key] = $value;
36 $this->id
= intval($this->data
['id']);
37 $this->shortname
= $this->data
['diminutif'];
40 public function __get($name)
42 if (property_exists($this, $name)) {
46 if (isset($this->data
[$name])) {
47 return $this->data
[$name];
53 public function __isset($name)
55 return property_exists($this, $name) ||
isset($this->data
[$name]);
58 public function getMemberUIDs()
60 if (is_null($this->members
)) {
61 $this->members
= XDB
::fetchColumn('SELECT uid
63 WHERE asso_id = {?}', $this->id
);
65 return $this->members
;
68 public function getMembers($sortby = null
, $count = null
, $offset = null
)
70 return User
::getBuildUsersWithUIDs($this->getMemberUIDs(), $sortby, $count, $offset);
73 public function getMemberCount()
75 return count($this->getMemberUIDs());
78 public function getAdminUIDs()
80 if (is_null($this->admins
)) {
81 $this->admins
= XDB
::fetchColumn('SELECT uid
83 WHERE asso_id = {?} AND perms = \'admin\'', $this->id
);
88 public function getAdmins($sortby = null
, $count = null
, $offset = null
)
90 return User
::getBuildUsersWithUIDs($this->getAdminUIDs(), $sortby, $count, $offset);
93 public function getAdminCount()
95 return count($this->getAdminUIDs());
98 static public function get($id)
103 if (ctype_digit($id)) {
104 $where = XDB
::format('id = {?}', $id);
106 $where = XDB
::format('diminutif = {?}', $id);
108 $res = XDB
::query('SELECT a.*, d.nom AS domnom,
109 FIND_IN_SET(\'wiki_desc\', a.flags) AS wiki_desc,
110 FIND_IN_SET(\'notif_unsub\', a.flags) AS notif_unsub
111 FROM groupex.asso AS a
112 LEFT JOIN groupex.dom AS d ON d.id = a.dom
114 if ($res->numRows() != 1) {
117 return new Group($res->fetchOneAssoc());
121 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: