1: <?php
2:
3: if (!defined('XOOPS_ROOT_PATH')) exit();
4:
5: require_once XOOPS_ROOT_PATH . "/modules/user/class/users.php";
6:
7: class UserUsers_searchHandler extends UserUsersHandler
8: {
9: function &getObjects($criteria = null, $limit = null, $start = null, $id_as_key = false)
10: {
11: $ret = array();
12:
13: $uTable = $this->db->prefix('users') . " as u";
14: $gTable = $this->db->prefix('groups_users_link') . " as g";
15:
16: $sql = "SELECT DISTINCT u.* FROM ${uTable} LEFT JOIN ${gTable} ON u.uid=g.uid";
17:
18: if($criteria !== null && is_a($criteria, 'CriteriaElement')) {
19: $where = $this->_makeCriteria4sql($criteria);
20:
21: if (trim($where)) {
22: $sql .= ' WHERE ' . $where;
23: }
24:
25: $sorts = array();
26: foreach ($criteria->getSorts() as $sort) {
27: $sorts[] = $sort['sort'] . ' ' . $sort['order'];
28: }
29: if ($criteria->getSort() != '') {
30: $sql .= " ORDER BY " . implode(',', $sorts);
31: }
32:
33: if ($limit === null) {
34: $limit = $criteria->getLimit();
35: }
36:
37: if ($start === null) {
38: $start = $criteria->getStart();
39: }
40: }
41: else {
42: if ($limit === null) {
43: $limit = 0;
44: }
45:
46: if ($start === null) {
47: $start = 0;
48: }
49: }
50:
51: $result = $this->db->query($sql, $limit, $start);
52:
53: if (!$result) {
54: return $ret;
55: }
56:
57: while($row = $this->db->fetchArray($result)) {
58: $obj =new $this->mClass();
59: $obj->assignVars($row);
60: $obj->unsetNew();
61:
62: if ($id_as_key) {
63: $ret[$obj->get($this->mPrimary)] =& $obj;
64: }
65: else {
66: $ret[]=&$obj;
67: }
68:
69: unset($obj);
70: }
71:
72: if (count($ret)) {
73: foreach (array_keys($ret) as $key) {
74: $ret[$key]->_loadGroups();
75: }
76: }
77:
78: return $ret;
79: }
80:
81: 82: 83: 84: 85: 86:
87: function &getUids($criteria = null, $limit = null, $start = null, $id_as_key = false)
88: {
89: $ret = array();
90:
91: $uTable = $this->db->prefix('users') . " as u";
92: $gTable = $this->db->prefix('groups_users_link') . " as g";
93:
94: $sql = "SELECT DISTINCT u.uid FROM ${uTable} LEFT JOIN ${gTable} ON u.uid=g.uid";
95:
96: if($criteria !== null && is_a($criteria, 'CriteriaElement')) {
97: $where = $this->_makeCriteria4sql($criteria);
98:
99: if (trim($where)) {
100: $sql .= ' WHERE ' . $where;
101: }
102:
103: $sorts = array();
104: foreach ($criteria->getSorts() as $sort) {
105: $sorts[] = $sort['sort'] . ' ' . $sort['order'];
106: }
107: if ($criteria->getSort() != '') {
108: $sql .= " ORDER BY " . implode(',', $sorts);
109: }
110:
111: if ($limit === null) {
112: $limit = $criteria->getLimit();
113: }
114:
115: if ($start === null) {
116: $start = $criteria->getStart();
117: }
118: }
119: else {
120: if ($limit === null) {
121: $limit = 0;
122: }
123:
124: if ($start === null) {
125: $start = 0;
126: }
127: }
128:
129: $result = $this->db->query($sql, $limit, $start);
130:
131: if (!$result) {
132: return $ret;
133: }
134:
135: while ($row = $this->db->fetchArray($result)) {
136: $ret[] = $row['uid'];
137: }
138:
139: return $ret;
140: }
141:
142: function getCount($criteria = null)
143: {
144: $ret = array();
145:
146: $uTable = $this->db->prefix('users') . " as u";
147: $gTable = $this->db->prefix('groups_users_link') . " as g";
148:
149: $sql = "SELECT COUNT(DISTINCT u.uid) c FROM ${uTable} LEFT JOIN ${gTable} ON u.uid=g.uid";
150: if($criteria !== null && is_a($criteria, 'CriteriaElement')) {
151: $where = $this->_makeCriteria4sql($criteria);
152:
153: if ($where) {
154: $sql .= " WHERE " . $where;
155: }
156: }
157:
158: return $this->_getCount($sql);
159: }
160:
161: function insert(&$user, $force = false)
162: {
163: if (parent::insert($user, $force)) {
164: $flag = true;
165:
166: $user->_loadGroups();
167:
168: $handler =& xoops_getmodulehandler('groups_users_link', 'user');
169: $oldLinkArr =& $handler->getObjects(new Criteria('uid', $user->get('uid')), $force);
170:
171:
172:
173:
174: $oldGroupidArr = array();
175: foreach (array_keys($oldLinkArr) as $key) {
176: $oldGroupidArr[] = $oldLinkArr[$key]->get('groupid');
177: if (!in_array($oldLinkArr[$key]->get('groupid'), $user->Groups)) {
178: $handler->delete($oldLinkArr[$key], $force);
179: }
180: }
181:
182: foreach ($user->Groups as $gid) {
183: if (!in_array($gid, $oldGroupidArr)) {
184: $link =& $handler->create();
185:
186: $link->set('groupid', $gid);
187: $link->set('uid', $user->get('uid'));
188:
189: $flag &= $handler->insert($link, $force);
190:
191: unset($link);
192: }
193: }
194:
195: return $flag;
196: }
197:
198: return false;
199: }
200:
201: function deleteAll($criteria, $force = false)
202: {
203: }
204: }
205:
206: ?>
207: