public function exitGroup($g) { // takes a group object, and, if the user is in the group, they exit the group if (is_object($g)) { $app = Application::getFacadeApplication(); $db = $app['database']->connection(); $gID = $g->getGroupID(); $ue = new \Concrete\Core\User\Event\UserGroup($this); $ue->setGroupObject($g); $app['director']->dispatch('on_user_exit_group', $ue); $q = 'delete from UserGroups where uID = ? and gID = ?'; $r = $db->executeQuery($q, array($this->uID, $gID)); } }
public function exitGroup($g) { // takes a group object, and, if the user is in the group, they exit the group if (is_object($g)) { $gID = $g->getGroupID(); $db = Loader::db(); $ue = new \Concrete\Core\User\Event\UserGroup($this); $ue->setGroupObject($g); Events::dispatch('on_user_exit_group', $ue); $q = "delete from UserGroups where uID = '{$this->uID}' and gID = '{$gID}'"; $r = $db->query($q); } }
public function updateGroups($groupArray) { $db = Loader::db(); $q = "select gID from UserGroups where uID = '{$this->uID}'"; $r = $db->query($q); if ($r) { $existingGIDArray = array(); while ($row = $r->fetchRow()) { $existingGIDArray[] = $row['gID']; } } $dh = Loader::helper('date'); $datetime = $dh->getOverridableNow(); if (is_array($groupArray)) { foreach ($groupArray as $gID) { $key = array_search($gID, $existingGIDArray); if ($key !== false) { // we remove this item from the existing GID array unset($existingGIDArray[$key]); } else { // this item is new, so we add it. $_ux = $this->getUserObject(); $g = Group::getByID($gID); $_ux->enterGroup($g); } } } // now we go through the existing GID Array, and remove everything, since whatever is left is not wanted. // Fire on_user_exit_group event for each group exited foreach ($existingGIDArray as $gID) { $group = Group::getByID($gID); if ($group) { $ue = new \Concrete\Core\User\Event\UserGroup($this->getUserObject()); $ue->setGroupObject($group); Events::dispatch('on_user_exit_group', $ue); } } // Remove from db if (count($existingGIDArray) > 0) { $inStr = implode(',', $existingGIDArray); $q2 = "delete from UserGroups where uID = '{$this->uID}' and gID in ({$inStr})"; $r2 = $db->query($q2); // fire the user group removal event for each of the groups we've deleted foreach ($existingGIDArray as $gID) { $ue = new \Concrete\Core\User\Event\UserGroup($this->getUserObject()); $ue->setGroupObject(Group::getByID($gID)); Events::dispatch('on_user_exit_group', $ue); } } }