Exemplo n.º 1
0
 /**
  * Remove a emember of the group
  *
  * @param string $userid
  * @return Group object (this)
  */
 function removemember($userid)
 {
     global $DB, $CFG, $USER, $HUB_SQL;
     //check user can add to the group
     if (!$this->isgroupadmin($USER->userid)) {
         return access_denied_error();
     }
     // check user exists
     $user = new User($userid);
     if ($user->load() instanceof Error) {
         global $ERROR;
         $ERROR = new error();
         return $ERROR->createUserNotFoundError($userid);
     }
     // remove them as admin (if they are already)
     if ($this->isgroupadmin($userid) && $this->removeadmin($userid) instanceof Error) {
         global $ERROR;
         $ERROR = new error();
         return $ERROR->createGroupLastAdmin($userid);
     }
     // remove the user from the group
     $params = array();
     $params[0] = $this->groupid;
     $params[1] = $userid;
     $res = $DB->delete($HUB_SQL->DATAMODEL_GROUP_MEMBER_DELETE, $params);
     if (!$res) {
         return database_error();
     } else {
         $this->reportpendingmember($userid);
     }
     $this->load();
     $this->loadmembers();
     return $this;
 }