public function add_members($userids) { global $USER; if (empty($userids)) { return; } if (!$USER->can_edit_institution($this->name)) { throw new AccessDeniedException("Institution::add_members: access denied"); } $values = array_map('intval', $userids); array_unshift($values, $this->name); $users = get_records_sql_array(' SELECT u.*, r.confirmedusr FROM {usr} u LEFT JOIN {usr_institution_request} r ON u.id = r.usr AND r.institution = ? WHERE u.id IN (' . join(',', array_fill(0, count($values) - 1, '?')) . ') AND u.deleted = 0', $values); if (empty($users)) { return; } db_begin(); foreach ($users as $user) { // If the user hasn't requested membership, allow them to be added to // the institution anyway so long as the logged-in user is a site admin // or institutional admin for the user (in some other institution). if (!$user->confirmedusr) { $userobj = new User(); $userobj->from_stdclass($user); if (!$USER->is_admin_for_user($userobj)) { continue; } } $this->addUserAsMember($user); } db_commit(); foreach ($users as $user) { remove_user_sessions($user->id); } }