Delete all the data for a user.

@param int $userid The user ID.
@return void
339265
protected static function delete_user_data($userid) {
        global $DB;

        // Delete the stuff.
        $DB->delete_records('badge_manual_award', ['recipientid' => $userid]);
        $DB->delete_records('badge_criteria_met', ['userid' => $userid]);
        $DB->delete_records('badge_issued', ['userid' => $userid]);

        // Delete the backpacks and related stuff.
        $backpackids = $DB->get_fieldset_select('badge_backpack', 'id', 'userid = :userid', ['userid' => $userid]);
        if (!empty($backpackids)) {
            list($insql, $inparams) = $DB->get_in_or_equal($backpackids, SQL_PARAMS_NAMED);
            $DB->delete_records_select('badge_external', "backpackid $insql", $inparams);
            $DB->delete_records_select('badge_backpack', "id $insql", $inparams);
        }
    }
916824
public function removeUser($userId)
    {
        if (true === is_numeric($userId) && true === in_array($userId, $this->users)) {
            foreach (array_keys($this->users, (int)$userId, true) as $key) {
                unset($this->users[$key]);
            }
        }
        return $this;
    }
1135400
protected static function delete_data(\context $context, int $userid = null) {
        global $DB;

        $cohortids = $DB->get_fieldset_select('cohort', 'id', 'contextid = :contextid', ['contextid' => $context->id]);
        foreach ($cohortids as $cohortid) {
            $params = ['cohortid' => $cohortid];
            if (!empty($userid)) {
                $params['userid'] = $userid;
            }
            $DB->delete_records('cohort_members', $params);
        }
    }
872650
public function batchDelete(array $UserID)
    {
        $params = array(
                   'useridlist' => $UserID,
                  );
        return $this->http->jsonPost(self::API_BATCH_DELETE, $params);

    }
283979
public void clearUserMeta(final long userId) throws SQLException {
      Connection conn = null;
      PreparedStatement stmt = null;
      Timer.Context ctx = metrics.clearUserMetaTimer.time();
      try {
         conn = connectionSupplier.getConnection();
         stmt = conn.prepareStatement(deleteUserMetaSQL);
         stmt.setLong(1, userId);
         stmt.executeUpdate();
      } finally {
         ctx.stop();
         SQLUtil.closeQuietly(conn, stmt);
      }
   }
954967
protected static function delete_user_competencies($userid) {
        global $DB;
        $usercontext = context_user::instance($userid);

        // Remove all the comments made on user competencies.
        \core_comment\privacy\provider::delete_comments_for_all_users($usercontext, 'competency', 'user_competency');

        // Find the user competency IDs.
        $ucids = $DB->get_fieldset_select(user_competency::TABLE, 'id', 'userid = :userid', ['userid' => $userid]);
        if (empty($ucids)) {
            return;
        }
        list($insql, $inparams) = $DB->get_in_or_equal($ucids, SQL_PARAMS_NAMED);

        // Delete all the evidence associated with competencies.
        $DB->delete_records_select(evidence::TABLE, "usercompetencyid $insql", $inparams);

        // Delete all the record of competency.
        $DB->delete_records_select(user_competency::TABLE, "id $insql", $inparams);
    }
1079251
public static function can_create_data_deletion_request_for_self(int $userid = null): bool {
        global $USER;
        $userid = $userid ?: $USER->id;
        return has_capability('tool/dataprivacy:requestdelete', \context_user::instance($userid), $userid);
    }
20484
public function leaveAllTeams($userId)
    {
        $user = $this->model->find($userId);
        $user->teams()->detach();
    }
206164
public function deleteUser($userId)
    {
        $query = $this->handler->createDeleteQuery();
        $query
            ->deleteFrom($this->handler->quoteTable('ezuser_setting'))
            ->where(
                $query->expr->eq(
                    $this->handler->quoteColumn('user_id'),
                    $query->bindValue($userId, null, \PDO::PARAM_INT)
                )
            );
        $query->prepare()->execute();

        $query = $this->handler->createDeleteQuery();
        $query
            ->deleteFrom($this->handler->quoteTable('ezuser'))
            ->where(
                $query->expr->eq(
                    $this->handler->quoteColumn('contentobject_id'),
                    $query->bindValue($userId, null, \PDO::PARAM_INT)
                )
            );
        $query->prepare()->execute();
    }
690010
public function delete($id)
    {
        $user = $this->findById($id);
        $eventData = $user;
        $user->delete();
        $this->event->fire('users.delete', array($eventData));
    }
8573
public function handleDelete(int $id): void
	{
		if ($this->isAjax()) {
			$user = $this->orm->users->getById($id);
			$this->orm->users->removeAndFlush($user);
			$this['userList']->reload();
		} else {
			$this->terminate();
		}
	}
336109
public function deleteUserImage(UserInterface $user)
    {
        $file = $this->getUserImage($user);
        if (is_readable($file)) {
            unlink($file);
        }
    }
623991
public static function destroyByUser($user_id)
	{
		$user_id = (is_array($user_id) ? $user_id : array($user_id));

		$blank = self::blank();

		$query = $blank->getQuery()
			->delete($blank->getTableName())
			->whereIn('user_id', $user_id);

		if (!$query->execute())
		{
			return false;
		}

		return true;
	}
47695
public function delete($userId)
    {
        if (is_array($userId)) {
            return $this->batchDelete($userId);
        }

        return $this->httpGet('cgi-bin/user/delete', ['userid' => $userId]);
    }
267862
public function removeMember($id, $userId)
    {
        try {
            $result = $this->service->remove(Auth::user(), $id, $userId);

            if ($result) {
                return back()->with('message', 'Successfully removed member');
            }

            return back()->with('message', 'Failed to remove member');
        } catch (Exception $e) {
            return back()->withErrors($e->getMessage());
        }
    }
44522
public static function remove_contact(int $userid, int $contactid) {
        global $DB;

        if ($contact = self::get_contact($userid, $contactid)) {
            $DB->delete_records('message_contacts', ['id' => $contact->id]);

            $event = \core\event\message_contact_removed::create(array(
                'objectid' => $contact->id,
                'userid' => $userid,
                'relateduserid' => $contactid,
                'context' => \context_user::instance($userid)
            ));
            $event->add_record_snapshot('message_contacts', $contact);
            $event->trigger();
        }
    }
1237856
public function setUserId( $userId )
    {
        $this->_user    = null;
        $this->userId   = ( (int) $userId ) ?: null;
        return $this;
    }