Performs unenrolment of users that are no longer enrolled in the consumer side.

@param stdClass $tool The tool record object.
@return int The number of users that have been unenrolled.
349550
protected function sync_unenrol(stdClass $tool) {
        global $DB;

        $ltiplugin = enrol_get_plugin('lti');

        if (!$this->should_sync_unenrol($tool->membersyncmode)) {
            return 0;
        }

        if (empty($this->currentusers)) {
            return 0;
        }

        $unenrolcount = 0;

        $ltiusersrs = $DB->get_recordset('enrol_lti_users', array('toolid' => $tool->id), 'lastaccess DESC', 'userid');
        // Go through the users and check if any were never listed, if so, remove them.
        foreach ($ltiusersrs as $ltiuser) {
            if (!in_array($ltiuser->userid, $this->currentusers)) {
                $instance = new stdClass();
                $instance->id = $tool->enrolid;
                $instance->courseid = $tool->courseid;
                $instance->enrol = 'lti';
                $ltiplugin->unenrol_user($instance, $ltiuser->userid);
                // Increment unenrol count.
                $unenrolcount++;
            }
        }
        $ltiusersrs->close();

        return $unenrolcount;
    }
419971
public static function course_reset_ended($event) {
        if (!empty(self::$resetinprogress)) {
            if (!empty($event->other['reset_options']['reset_groups_remove'])) {
                lesson_process_group_deleted_in_course($event->courseid);
            }
        }

        self::$resetinprogress = null;
    }
577143
public function unregister($identifier)
    {
        $this->load();

        parent::unregister($identifier);
        $this->getDrupalCommonConnector()->variable_set($this->section, $this->registry[$this->section]);
    }
1103831
public function createDefaultToolMaskDecoders(Tool $tool)
    {
        foreach (ToolMaskDecoder::$defaultActions as $action) {
            $maskDecoder = $this->maskRepo
                ->findMaskDecoderByToolAndName($tool, $action);

            if (is_null($maskDecoder)) {
                $maskDecoder = new ToolMaskDecoder();
                $maskDecoder->setTool($tool);
                $maskDecoder->setName($action);
                $maskDecoder->setValue(ToolMaskDecoder::$defaultValues[$action]);
                $maskDecoder->setGrantedIconClass(
                    ToolMaskDecoder::$defaultGrantedIconClass[$action]
                );
                $maskDecoder->setDeniedIconClass(
                    ToolMaskDecoder::$defaultDeniedIconClass[$action]
                );
                $this->om->persist($maskDecoder);
            }
        }
        $this->om->flush();
    }
1344457
public function process(course_enrolment_manager $manager, array $users, stdClass $properties) {
        if (!has_capability("enrol/self:unenrol", $manager->get_context())) {
            return false;
        }

        foreach ($users as $user) {
            foreach ($user->enrolments as $enrolment) {
                $plugin = $enrolment->enrolmentplugin;
                $instance = $enrolment->enrolmentinstance;
                if ($plugin->allow_unenrol_user($instance, $enrolment)) {
                    $plugin->unenrol_user($instance, $user->id);
                }
            }
        }

        return true;
    }
871815
public function updateUnreadCount() {
    $unread = 0;

    // Get the user.
    $uid = $this->currentUser->id();
    // Get all the thread id's for this user.
    $threads = $this->getAllThreadIdsForUser($uid);

    if (empty($threads)) {
      return $unread;
    }

    // Check the last time someone other than the current user added
    // something to the threads.
    $thread_last_messages = $this->getLastMessagesFromOtherUsers($uid, $threads);
    if (empty($thread_last_messages)) {
      return $unread;
    }

    foreach ($thread_last_messages as $thread_id => $last_message) {
      // Check if the user has a timestamp on the thread.
      $thread_last_check = $this->userData->get('private_message', $uid, 'private_message_thread:' . $thread_id);
      if ($thread_last_check === NULL) {
        $thread_last_check = 0;
      }

      // Check if someone send a message after your last check.
      if ($last_message > $thread_last_check) {
        $unread++;
      }
    }
    return $unread;
  }
1041233
public function unbind()
	{
		if ($this->isBound && $this->resource && \is_resource($this->resource))
		{
			return ldap_unbind($this->resource);
		}

		return true;
	}
1327392
public function isUnreadByUser($member = null) {
		if (!$member) {
			$member = $this->securityContext->getMember();
		}

		if ($member && $member->ID) {
			return strtotime($this->Created) > strtotime($member->LastPostView);
		}
	}
112404
public function undismiss() {
		// Validate nonce.
		if ( isset( $_POST['set_key_auth'] ) && ! empty( $_POST['notice'] ) && check_ajax_referer( 'boldgrid_set_key', 'set_key_auth', false ) ) {
			$id = sanitize_key( $_POST['notice'] );

			// Get all of the notices this user has dismissed.
			$dismissals = get_user_meta( get_current_user_id(), 'boldgrid_dismissed_admin_notices' );

			// Loop through all of the dismissed notices. If we find the dismissal, then remove it.
			foreach ( $dismissals as $dismissal ) {
				if ( $id === $dismissal['id'] ) {
					delete_user_meta( get_current_user_id(), 'boldgrid_dismissed_admin_notices', $dismissal );
					break;
				}
			}
		}
	}
894260
public function actionDeregister($user)
    {
        $user = $this->getUser($user);
        if ($user->deregister()) {
            echo "User (" . $user->getID() . ") Deregistered.\n";
            return static::EXIT_CODE_NORMAL;
        }
        return static::EXIT_CODE_ERROR;
    }
585163
function countDeletedLines()
    {
        $count = 0;
        foreach ($this->_edits as $edit) {
            if (is_a($edit, 'Text_Diff_Op_delete') ||
                is_a($edit, 'Text_Diff_Op_change')) {
                $count += $edit->norig();
            }
        }
        return $count;
    }
594159
protected function minimise_user_record(\stdClass $user) {
        // We store large amount of users in one huge array, make sure we do not store info there we do not actually
        // need in mail generation code or messaging.
        unset($user->institution);
        unset($user->department);
        unset($user->address);
        unset($user->city);
        unset($user->url);
        unset($user->currentlogin);
        unset($user->description);
        unset($user->descriptionformat);
    }
834956
private function _deletedCount()
    {
        if ($this->_deleted === null) {
            return 0;
        }

        if (extension_loaded('bitset')) {
            return count(bitset_to_array($this->_deleted));
        } else {
            return count($this->_deleted);
        }
    }
57022
public function undeleteAction()
    {
        $this->deleteParameters = $this->deleteParameters + $this->defaultTokenParameters;
        $this->deleteSnippets   = $this->getToken()->getDeleteSnippetNames();

        parent::deleteAction();
    }
898839
public function canProceed(Tool $tool)
    {
        if (false === $this->configuration->isDevMode() && true === $tool->isOnlyDev()) {
            return false;
        }

        return true;
    }
1311698
protected function reset_userdata_submissions(stdClass $data) {
        global $DB;

        $submissions = $this->get_submissions();
        foreach ($submissions as $submission) {
            $this->delete_submission($submission);
        }

        return true;
    }
1154569
public function delete($id)
    {
        if ($id === '1') {
            throw new ForbiddenException();
        }
        if (!$this->request->is(['post'])) {
            throw new MethodNotAllowedException();
        }

        /** @var Connection $connection */
        $connection = $this->Groups->connection();

        $connection->begin();
        $group = $this->Groups->get($id);

        $users = $this->Groups->UsersGroups->Users->find()
            ->matching('UsersGroups', function (Query $q) use ($id) {
                return $q->where(['UsersGroups.group_id' => $id]);
            });

        // Filter the resulting users to match only users assigned to more than one user group.
        $skipUserIds = $this->Groups->UsersGroups->findUserIdsWithOnlyOneGroup();
        if (!empty($skipUserIds)) {
            $users->where([
                $this->Groups->Users->aliasField('id') . ' IN' => $skipUserIds
            ]);
        }

        $userCount = $users->all()->count();
        $groupCanBeDeleted = ($userCount === 0);

        if (($alternativeGroupIds = $this->request->data('alternative_group_id')) !== null) {
            // check if a valid alternative group has been selected for every user
            $valid = true;
            $validAlternativeGroupIds = [];
            foreach ($users as $user) {
                if (!isset($alternativeGroupIds[$user->id]) ||
                    (int)$alternativeGroupIds[$user->id] === (int)$id ||
                    !$this->Groups->exists(['id' => $alternativeGroupIds[$user->id]])
                ) {
                    $valid = false;
                } else {
                    $validAlternativeGroupIds[$user->id] = (int)$alternativeGroupIds[$user->id];
                }
            }
            if ($valid) {
                // move existing users of the group to the submitted alternative group
                $groupCanBeDeleted = (bool)$this->Groups->moveUsersToAlternativeGroups($validAlternativeGroupIds);
            } else {
                $this->Flash->error(__d('wasabi_core', 'Please select an alternative user group for every listed user.'));
            }
        }

        if ($groupCanBeDeleted === true) {
            if ($this->Groups->delete($group)) {
                $connection->commit();
                if ($userCount > 0) {
                    $this->Flash->success(__d('wasabi_core', 'The group <strong>{0}</strong> has been deleted. Prior <strong>{1}</strong> group member(s) ha(s/ve) been moved to another group.', $group->name, $userCount));
                } else {
                    $this->Flash->success(__d('wasabi_core', 'The group <strong>{0}</strong> has been deleted.', $group->name));
                }
            } else {
                $connection->rollback();
                $this->Flash->error($this->dbErrorMessage);
            }
            $this->redirect($this->Filter->getBacklink(['action' => 'index'], $this->request));
            return;
        } else {
            $connection->rollback();
            $this->Flash->warning(__d('wasabi_core', 'The group <strong>{0}</strong> has <strong>{1}</strong> member(s) that need to be moved to another group.', $group->name, $userCount));
            $this->set([
                'users' => $users,
                'group' => $group,
                'groups' => $this->Groups->find('list')->where(['not' => ['id' => $id]])
            ]);
        }
    }