Add a new attempt for a user.

@param int $userid int The user to add the attempt for
@return bool - true if successful.
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;
    }
1082199
public function getUser(string $userid)
    {
        $cl = $this->getUserClass();
        $user = new $cl;
        return $user->obtainByUserID($userid);
    }
601656
public function update($userId)
    {
        try
        {
            $permissions = Input::get('permissions', array());
            $this->users->updatePermissions($userId,$permissions);

            return Redirect::route('cpanel.users.index')
                ->with('success', Lang::get('cpanel::users.permissions_update_success'));
        }
        catch ( UserNotFoundException $e)
        {
            return Redirect::route('cpanel.users.permissions')
                ->with('error', $e->getMessage());
        }

    }
390539
public function activeForUser($userId)
    {
        return $this->forUser($userId)->reject(function ($client) {
            return $client->revoked;
        })->values();
    }
212113
public function delete($userid)
	{
		$event = new Event('onPlatformUserDelete');
		$event->addArgument('userid', $userid);
		$event->addArgument('activePlugin', $this->activePlugin);

		Factory::getDispatcher()->triggerEvent($event);

		$debug = $event->getArgument('debug', null);
		if ($debug) {
			$this->debug[] = $debug;
		}

		$error = $event->getArgument('error', null);
		if ($error) {
			$this->error[] = $error;
		}
	}
874572
public function isUserInRoleById(int $userId): bool
    {
        if (isset($this->users[$userId])) {
            return true;
        }

        return false;
    }
288199
protected function process_revert_to_draft($userid = 0) {
        require_sesskey();

        if (!$userid) {
            $userid = required_param('userid', PARAM_INT);
        }

        return $this->revert_to_draft($userid);
    }
1132043
public function likeToggle($userId = null)
    {
        app(LikeableServiceContract::class)->toggleLikeOf($this, LikeType::LIKE, $userId);
    }
329641
public function remove_submission($userid) {
        global $USER;

        if (!$this->can_edit_submission($userid, $USER->id)) {
            print_error('nopermission');
        }

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

        if (!$submission) {
            return false;
        }

        // Tell each submission plugin we were saved with no data.
        $plugins = $this->get_submission_plugins();
        foreach ($plugins as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                $plugin->remove($submission);
            }
        }

        if ($submission->userid != 0) {
            \mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
        }
        return true;
    }
152356
public function assignUser($userGroupId, $userId = [])
    {
        $this->groupId = $userGroupId;

        $this->getLogger()->info('Assigning User IDs ' . json_encode($userId) . ' To User Group ID ' . $this->groupId);
        $response = $this->doPost('/group/members/assign/' . $userGroupId, [
            'userId' => $userId
        ]);

        /** @var XiboUserGroup $userGroup */
        $userGroup = $this->hydrate($response);

        return $userGroup;
    }
1343281
public static function can_create_data_deletion_request_for_other(int $userid = null): bool {
        global $USER;
        $userid = $userid ?: $USER->id;
        return has_capability('tool/dataprivacy:requestdeleteforotheruser', context_system::instance(), $userid);
    }
219223
public function createPushPackageForUser($userId)
    {
        $packageDir = sprintf('/%s/pushPackage%s.%s', sys_get_temp_dir(), time(), $userId);
        $package = $this->createPackage($packageDir, $userId);

        $this->generatePackage($package);

        return $package;
    }
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;
	}
334144
public function addInvolvedUserId($involvedUserId)
    {
        if (!in_array($involvedUserId, $this->involvedUserIds)) {
            $this->involvedUserIds[] = $involvedUserId;
        }

        return $this;
    }
789301
private function setUserToBeImpersonated($userId)
	{
		if (!empty($userId)) {
			if (version_compare($this->laravel->version(), '5.2.0', '<')) {
				$userModel = config('auth.model');
				$user = $userModel::find($userId);
				$this->laravel['auth']->setUser($user);
			} else {
				if (!config('openapischemas.auth_provider')) {
					$this->error('You need to specify a "auth_provider" value in your openapischemas.php configuration file first.');
					exit();
				}
				$provider = config('openapischemas.auth_provider');
				$userModel = config("auth.providers.$provider.model");
				if (!config('auth.providers.' . $provider . '.model')) {
					$this->error('No model in your config/auth.php matching auth provider "' . $provider . '" from your openapischemas.php configuration file.');
					exit();
				}
				$user = $userModel::find($userId);
				$auth_guard = config('openapischemas.auth_guard');
				$this->laravel['auth']->guard($auth_guard)->setUser($user);
			}
		}
	}
506857
public function create($data, $userId = null)
    {
        if (isset($userId)) {
            return $this->client()->put($data, 'users/{userId}', ['userId' => $userId]);
        }

        return $this->client()->post($data, 'users');
    }
1275672
public function liked($userId=null)
	{
		if(is_null($userId)) {
			$userId = $this->loggedInUserId();
		}
		
		return (bool) $this->likes()
			->where('user_id', '=', $userId)
			->count();
	}