Checks whether there is already an existing pending/in-progress data request for a user for a given request type.

@param int $userid The user ID.
@param int $type The request type.
@return bool
@throws coding_exception
@throws dml_exception
151
public static function has_ongoing_request($userid, $type) {
        global $DB;

        // Check if the user already has an incomplete data request of the same type.
        $nonpendingstatuses = [
            self::DATAREQUEST_STATUS_COMPLETE,
            self::DATAREQUEST_STATUS_CANCELLED,
            self::DATAREQUEST_STATUS_REJECTED,
            self::DATAREQUEST_STATUS_DOWNLOAD_READY,
            self::DATAREQUEST_STATUS_EXPIRED,
            self::DATAREQUEST_STATUS_DELETED,
        ];
        list($insql, $inparams) = $DB->get_in_or_equal($nonpendingstatuses, SQL_PARAMS_NAMED, 'st', false);
        $select = "type = :type AND userid = :userid AND status {$insql}";
        $params = array_merge([
            'type' => $type,
            'userid' => $userid
        ], $inparams);

        return data_request::record_exists_select($select, $params);
    }
754052
public function authQuery($userId) {
        $data = $this->getAuthQuery()->parameters([
            'identity_param' => Json::encode([
                'userId' => $userId
            ])
        ])->text();
        return isset($data['authorized']) && $data['authorized'];
    }
1119569
public function isIgnoredBy($userId)
    {
        if ((new Query)->select('id')->from('{{%podium_user_ignore}}')->where([
                'user_id' => $userId,
                'ignored_id' => $this->id
            ])->exists()) {
            return true;
        }
        return false;
    }
1009844
public function deleteUser($userId)
    {
        try {
            return $this->innerGateway->deleteUser($userId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
853818
public function isUserInForcedVariation($userId)
    {
        $forcedVariations = $this->getForcedVariations();
        return !is_null($forcedVariations) && isset($forcedVariations[$userId]);
    }
651780
public static function get_received_contact_requests_count(int $userid) : int {
        global $DB;
        $sql = "SELECT COUNT(mcr.id)
                  FROM {message_contact_requests} mcr
             LEFT JOIN {message_users_blocked} mub
                    ON mub.userid = mcr.requesteduserid AND mub.blockeduserid = mcr.userid
                 WHERE mcr.requesteduserid = :requesteduserid
                   AND mub.id IS NULL";
        $params = ['requesteduserid' => $userid];
        return $DB->count_records_sql($sql, $params);
    }
695769
public static function confirm_contact_request(int $userid, int $requesteduserid) {
        global $DB;

        if ($request = $DB->get_record('message_contact_requests', ['userid' => $userid,
                'requesteduserid' => $requesteduserid])) {
            self::add_contact($userid, $requesteduserid);

            $DB->delete_records('message_contact_requests', ['id' => $request->id]);
        }
    }
133823
private function isUserProfileUpdateRequested(UserUpdateStruct $userUpdateStruct)
    {
        return
            !empty($userUpdateStruct->contentUpdateStruct) ||
            !empty($userUpdateStruct->contentMetadataUpdateStruct) ||
            !empty($userUpdateStruct->email) ||
            !empty($userUpdateStruct->enabled) ||
            !empty($userUpdateStruct->maxLogin);
    }
447778
public function canCancel($userId)
    {
        return $this->isOwner($userId) ||
            ($this->isIssuer($userId) && $this->isOnTimeToCancel()) ||
            ($this->isTarget($userId) && $this->isOnTimeToCancel());
    }
864787
public function checkUserGroupExistence( $id )
    {
        /** @var \eZ\Publish\API\Repository\Repository $repository */
        $repository = $this->getRepository();
        $userService = $repository->getUserService();

        return $repository->sudo(
            function() use( $id, $userService )
            {
                // attempt to load the content type group with the id
                try
                {
                    $userService->loadUserGroup( $id );
                    return true;
                }
                catch ( ApiExceptions\NotFoundException $e )
                {
                    return false;
                }
            }
        );
    }
164838
protected function add_attempt($userid) {
        require_capability('mod/assign:grade', $this->context);

        if ($this->get_instance()->attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_NONE) {
            return false;
        }

        if ($this->get_instance()->teamsubmission) {
            $oldsubmission = $this->get_group_submission($userid, 0, false);
        } else {
            $oldsubmission = $this->get_user_submission($userid, false);
        }

        if (!$oldsubmission) {
            return false;
        }

        // No more than max attempts allowed.
        if ($this->get_instance()->maxattempts != ASSIGN_UNLIMITED_ATTEMPTS &&
            $oldsubmission->attemptnumber >= ($this->get_instance()->maxattempts - 1)) {
            return false;
        }

        // Create the new submission record for the group/user.
        if ($this->get_instance()->teamsubmission) {
            if (isset($this->mostrecentteamsubmission)) {
                // Team submissions can end up in this function for each user (via save_grade). We don't want to create
                // more than one attempt for the whole team.
                if ($this->mostrecentteamsubmission->attemptnumber == $oldsubmission->attemptnumber) {
                    $newsubmission = $this->get_group_submission($userid, 0, true, $oldsubmission->attemptnumber + 1);
                } else {
                    $newsubmission = $this->get_group_submission($userid, 0, false, $oldsubmission->attemptnumber);
                }
            } else {
                debugging('Please use set_most_recent_team_submission() before calling add_attempt', DEBUG_DEVELOPER);
                $newsubmission = $this->get_group_submission($userid, 0, true, $oldsubmission->attemptnumber + 1);
            }
        } else {
            $newsubmission = $this->get_user_submission($userid, true, $oldsubmission->attemptnumber + 1);
        }

        // Set the status of the new attempt to reopened.
        $newsubmission->status = ASSIGN_SUBMISSION_STATUS_REOPENED;

        // Give each submission plugin a chance to process the add_attempt.
        $plugins = $this->get_submission_plugins();
        foreach ($plugins as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                $plugin->add_attempt($oldsubmission, $newsubmission);
            }
        }

        $this->update_submission($newsubmission, $userid, false, $this->get_instance()->teamsubmission);
        $flags = $this->get_user_flags($userid, false);
        if (isset($flags->locked) && $flags->locked) { // May not exist.
            $this->process_unlock_submission($userid);
        }
        return true;
    }
780883
public function isSatisfiedBy($userId): bool
    {
        try {
            $this->userService->loadUser($userId);

            return true;
        } catch (NotFoundException $e) {
            return false;
        }
    }
637708
public function lock_submission($userid) {
        global $USER, $DB;
        // Need grade permission.
        require_capability('mod/assign:grade', $this->context);

        // Give each submission plugin a chance to process the locking.
        $plugins = $this->get_submission_plugins();
        $submission = $this->get_user_submission($userid, false);

        $flags = $this->get_user_flags($userid, true);
        $flags->locked = 1;
        $this->update_user_flags($flags);

        foreach ($plugins as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                $plugin->lock($submission, $flags);
            }
        }

        $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
        \mod_assign\event\submission_locked::create_from_user($this, $user)->trigger();
        return true;
    }
1358618
public static function user_competency_request_review($userid, $competencyid) {
        static::require_enabled();
        $uc = user_competency::get_record(array('userid' => $userid, 'competencyid' => $competencyid));
        if (!$uc) {
            $uc = user_competency::create_relation($userid, $competencyid);
            $uc->create();
        }

        if (!$uc->can_read()) {
            throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyview',
                'nopermissions', '');
        } else if ($uc->get('status') != user_competency::STATUS_IDLE) {
            throw new coding_exception('The competency can not be sent for review at this stage.');
        } else if (!$uc->can_request_review()) {
            throw new required_capability_exception($uc->get_context(), 'moodle/competency:usercompetencyrequestreview',
                'nopermissions', '');
        }

        $uc->set('status', user_competency::STATUS_WAITING_FOR_REVIEW);
        $result = $uc->update();
        if ($result) {
            \core\event\competency_user_competency_review_requested::create_from_user_competency($uc)->trigger();
        }
        return $result;
    }
1168521
public function isUserExists($conversationId, $userId)
    {
        $exists = Conversation::where('id', $conversationId)
            ->where(
                function ($query) use ($userId) {
                    $query->where('user_one', $userId)->orWhere('user_two', $userId);
                }
            )
            ->exists();

        return $exists;
    }
1055663
public function exists($userid)
	{
		$query = $this->_db->getQuery(true)
			->select('COUNT(userid)')
			->from($this->_db->quoteName($this->_tbl))
			->where($this->_db->quoteName('userid') . ' = ' . $this->_db->quote($userid));
		$this->_db->setQuery($query);

		if (!$result = $this->_db->loadResult())
		{
			$this->setError($this->_db->stderr());

			return false;
		}

		return (boolean) $result;
	}
900327
public function isUserTwoFactorAuthEnabled($userId) {
        $result = DB::table('users')
            ->where('id', '=', $userId)
            ->value('two_factor_auth_enabled')
        ;

        if ($result) {
            return true;
        }
        return false;
    }