19 defined(
'XOOPS_ROOT_PATH') or die('Restricted access');
21 require_once
$GLOBALS['xoops']->path('kernel/user.php');
22 require_once
$GLOBALS['xoops']->path('kernel/group.php');
57 var $_members = array();
64 function XoopsMemberHandler(&
$db)
76 function &createGroup()
78 $inst =& $this->_gHandler->create();
87 function &createUser()
89 $inst =& $this->_uHandler->create();
99 function getGroup($id)
101 return $this->_gHandler->get($id);
110 function &getUser($id)
112 if (!isset($this->_members[$id])) {
113 $this->_members[$id] = & $this->_uHandler->get($id);
115 return $this->_members[$id];
124 function deleteGroup(&$group)
126 $this->_gHandler->delete($group);
127 $this->_mHandler->deleteAll(
new Criteria(
'groupid', $group->getVar(
'groupid')));
139 $this->_uHandler->delete(
$user);
140 $this->_mHandler->deleteAll(
new Criteria(
'uid',
$user->getVar(
'uid')));
151 function insertGroup(&$group)
153 return $this->_gHandler->insert($group);
163 function insertUser(&
$user, $force =
false)
165 return $this->_uHandler->insert(
$user, $force);
175 function getGroups(
$criteria = null, $id_as_key =
false)
177 return $this->_gHandler->getObjects(
$criteria, $id_as_key);
189 return $this->_uHandler->getObjects(
$criteria, $id_as_key);
216 $users = $this->_uHandler->getObjects(
$criteria,
true);
218 foreach (array_keys($users) as
$i) {
219 $ret[
$i] = $users[
$i]->getVar(
'uname');
233 $mship =& $this->_mHandler->create();
234 $mship->setVar(
'groupid', $group_id);
236 return $this->_mHandler->insert($mship);
246 function removeUsersFromGroup($group_id, $user_ids = array())
251 foreach ($user_ids as
$uid) {
255 return $this->_mHandler->deleteAll(
$criteria);
268 function getUsersByGroup($group_id, $asobject =
false,
$limit = 0,
$start = 0)
270 $user_ids = $this->_mHandler->getUsersByGroup($group_id,
$limit,
$start);
275 foreach ($user_ids as $u_id) {
276 $user =& $this->getUser($u_id);
277 if (is_object(
$user)) {
293 function getGroupsByUser(
$user_id, $asobject =
false)
295 $group_ids = $this->_mHandler->getGroupsByUser(
$user_id);
299 foreach ($group_ids as $g_id) {
300 $ret[] = $this->getGroup($g_id);
352 return $this->_uHandler->getCount(
$criteria);
361 function getUserCountByGroup($group_id)
363 return $this->_mHandler->getCount(
new Criteria(
'groupid', $group_id));
374 function updateUserByField(&
$user, $fieldName, $fieldValue)
376 $user->setVar($fieldName, $fieldValue);
377 return $this->insertUser(
$user);
388 function updateUsersByField($fieldName, $fieldValue,
$criteria = null)
390 return $this->_uHandler->updateAll($fieldName, $fieldValue,
$criteria);
401 if (
$user->getVar(
'level') != 0) {
404 $user->setVar(
'level', 1);
405 return $this->_uHandler->insert(
$user,
true);
419 function getUsersByGroupLink(
$groups,
$criteria = null, $asobject =
false, $id_as_key =
false)
423 $select = $asobject ?
"u.*" :
"u.uid";
424 $sql =
"SELECT DISTINCT {$select} " .
" FROM " . $this->_uHandler->db->prefix(
"users")
425 .
" AS u" .
" LEFT JOIN " . $this->_mHandler->db->prefix(
"groups_users_link")
426 .
" AS m ON m.uid = u.uid WHERE ";
428 $criteriaCompo->add(
new Criteria(
'm.groupid',
"(" . implode(
", ",
$groups) .
")",
'IN'));
434 $sql_criteria = $criteriaCompo->render();
441 $sql_criteria = $criteriaCompo->render();
445 $sql .= $sql_criteria;
453 while ($myrow = $this->_uHandler->db->fetchArray(
$result)) {
456 $user->assignVars($myrow);
464 $ret[] = $myrow[
'uid'];
481 $sql =
"SELECT DISTINCT COUNT(u.uid) "
482 .
" FROM " . $this->_uHandler->db->prefix(
"users") .
" AS u"
483 .
" LEFT JOIN " . $this->_mHandler->db->prefix(
"groups_users_link")
484 .
" AS m ON m.uid = u.uid" .
" WHERE ";
486 $criteriaCompo->add(
new Criteria(
'm.groupid',
"(" . implode(
", ",
$groups) .
")",
'IN'));
491 $sql_criteria = $criteriaCompo->render();
494 $sql .= $sql_criteria;
499 if (!
$result = $this->_uHandler->db->query(
$sql)) {
502 list (
$ret) = $this->_uHandler->db->fetchRow(
$result);