Update counter grant

@see http://api.yandex.ru/metrika/doc/beta/management/grants/editgrantold.xml

@param int $counterId
@param string $userLogin
@param Models\Grant $grant
@return Models\Grant
11597
public function updateGrant($counterId, $userLogin, Models\Grant $grant)
    {
        $resource = 'counter/' . $counterId . '/grant/' . $userLogin;
        $response = $this->sendPutRequest($resource, ["grant" => $grant->toArray()]);
        $grantResponse = new Models\UpdateGrantResponse($response);
        return $grantResponse->getGrant();
    }
1237856
public function setUserId( $userId )
    {
        $this->_user    = null;
        $this->userId   = ( (int) $userId ) ?: null;
        return $this;
    }
209084
public function revert_to_draft($userid) {
        global $DB, $USER;

        // Need grade permission.
        require_capability('mod/assign:grade', $this->context);

        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;
        }
        $submission->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
        $this->update_submission($submission, $userid, false, $this->get_instance()->teamsubmission);

        // Give each submission plugin a chance to process the reverting to draft.
        $plugins = $this->get_submission_plugins();
        foreach ($plugins as $plugin) {
            if ($plugin->is_enabled() && $plugin->is_visible()) {
                $plugin->revert_to_draft($submission);
            }
        }
        // Update the modified time on the grade (grader modified).
        $grade = $this->get_user_grade($userid, true);
        $grade->grader = $USER->id;
        $this->update_grade($grade);

        $completion = new completion_info($this->get_course());
        if ($completion->is_enabled($this->get_course_module()) &&
                $this->get_instance()->completionsubmit) {
            $completion->update_state($this->get_course_module(), COMPLETION_INCOMPLETE, $userid);
        }
        \mod_assign\event\submission_status_updated::create_from_submission($this, $submission)->trigger();
        return true;
    }
1154982
public function getGrants($counterId, $params = [])
    {
        $resource = 'counter/' . $counterId . '/grants';
        $response = $this->sendGetRequest($resource, $params);
        $grantResponse = new Models\GetGrantsResponse($response);
        return $grantResponse->getGrants();
    }
459320
public function handleLinkRequest(LoginRequest $request, $userId)
    {
        $socialLogin = $this->socialLoginMapper->findByProviderUserId(
            $request->getProvider(),
            $request->getProviderUserId()
        );

        if ($socialLogin) {
            throw new LinkedAccountExistsException;
        }

        $user = $this->userService->findById($userId);

        if (! $user) {
            throw new OutOfBoundsException('Account not found', self::EXCEPTION_ACCOUNT_NOT_FOUND);
        }

        $socialLoginEntity = new SocialLoginEntity;
        $socialLoginEntity->setUserId($user->getId())
            ->setProvider($request->getProvider())
            ->setProviderUserId($request->getProviderUserId())
            ->setAccessToken($request->getAccessToken())
            ->setAccessTokenExpires($request->getAccessTokenExpires())
            ->setRefreshToken($request->getRefreshToken());

        $socialLogin = $this->socialLoginMapper->persist($socialLoginEntity);

        return $this->handleLogin($user, $request);
    }
397277
public static function unblock_user(int $userid, int $usertounblockid) {
        global $DB;

        if ($blockeduser = $DB->get_record('message_users_blocked',
                ['userid' => $userid, 'blockeduserid' => $usertounblockid])) {
            $DB->delete_records('message_users_blocked', ['id' => $blockeduser->id]);

            // Trigger event for unblocking a contact.
            $event = \core\event\message_user_unblocked::create(array(
                'objectid' => $blockeduser->id,
                'userid' => $userid,
                'relateduserid' => $usertounblockid,
                'context' => \context_user::instance($userid)
            ));
            $event->add_record_snapshot('message_users_blocked', $blockeduser);
            $event->trigger();
        }
    }
768909
public function updateLoginStats($userId, $columns = array()) {
        if (isset($_SERVER['REMOTE_ADDR'])) {
            $columns['ip_address'] = $_SERVER['REMOTE_ADDR'];
        }
        $columns['last_login'] = new Zend_Db_Expr('NOW()');
        return $this->_model->update(
            $columns,
            $this->_model->getAdapter()->quoteInto('user_id = ?', $userId)
        );
    }
395545
public function store(CreateUserRequest $request, User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_CREATE);

        $user->fill($request->getValidatedData());
        $user->is_active = true;
        $user->save();
        $user->roles()->sync($request->get('roles'));

        $this->transNotification('created', ['name' => $user->full_name], $user->toArray());

        return redirect()->route('admin::auth.users.index');
    }
585335
public function resendAction(Request $request, User $user = null)
    {
        $currentUser = $this->getUser();

        if (null === $user) {
            $user = $currentUser;
            if (!is_object($user) || !$user instanceof UserInterface) {
                throw new AccessDeniedException(
                    'This user does not have access to this section.'
                );
            }
        } else if (!$this->isGranted('ROLE_SUPER_ADMIN')) {
            throw new AccessDeniedException(
                'You cannot resend the confirmation for another user.'
            );
        }

        $isCurrentUser = $user->getId() === $currentUser->getId();

        // get the referer, if none redirect to the login
        // which should go to the default page after login
        $redirect = $request->headers->get(
            'referer',
            $this->generateUrl('fos_user_security_login')
        );

        if ($user->isEnabled()) {
            if ($isCurrentUser) {
                $this->addFlash('warning', 'Your account is already enabled.');
            } else {
                $this->addFlash('warning', 'The user is already enabled.');
            }

            return $this->redirect($redirect);
        }

        if (null === $user->getConfirmationToken()) {
            $user->setConfirmationToken(
                $this->get('fos_user.util.token_generator')
                    ->generateToken()
            );
            $this->get('fos_user.user_manager')->updateUser($user);
        }

        $this->get('fos_user.mailer')->sendConfirmationEmailMessage($user);

        if ($isCurrentUser) {
            $this->addFlash(
                'success',
                'Your account activation email has been resent.'
            );
        } else {
            $this->addFlash(
                'success',
                'The account activation email has been resent.'
            );
        }

        return $this->redirect($redirect);
    }
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);
    }
847353
public function save_user_extension($userid, $extensionduedate) {
        global $DB;

        // Need submit permission to submit an assignment.
        require_capability('mod/assign:grantextension', $this->context);

        if (!is_enrolled($this->get_course_context(), $userid)) {
            return false;
        }
        if (!has_capability('mod/assign:submit', $this->context, $userid)) {
            return false;
        }

        if ($this->get_instance()->duedate && $extensionduedate) {
            if ($this->get_instance()->duedate > $extensionduedate) {
                return false;
            }
        }
        if ($this->get_instance()->allowsubmissionsfromdate && $extensionduedate) {
            if ($this->get_instance()->allowsubmissionsfromdate > $extensionduedate) {
                return false;
            }
        }

        $flags = $this->get_user_flags($userid, true);
        $flags->extensionduedate = $extensionduedate;

        $result = $this->update_user_flags($flags);

        if ($result) {
            \mod_assign\event\extension_granted::create_from_assign($this, $userid)->trigger();
        }
        return $result;
    }
265143
public function updateUserContext(UserContext $context): void
    {
        $context->addParameter(
            'userId',
            $this->repository->getPermissionResolver()->getCurrentUserReference()->getUserId()
        );
    }
1083121
public function getGrant($counterId, $userLogin, $params = [])
    {
        $resource = 'counter/' . $counterId . '/grant/' . $userLogin;
        $response = $this->sendGetRequest($resource, $params);
        $grantResponse = new Models\GetGrantResponse($response);
        return $grantResponse->getGrant();
    }
626689
public function updateUserRecordWithLastlogin($userId) {

        $now = Carbon::now();
        $ip  = $this->request->getClientIp();

        DB::table('users')
            ->where('id', $userId)
            ->update(['last_login' => $now, 'last_login_ip' => $ip] )
        ;
    }
1080486
public function update(User $user, UpdateUser $request)
    {
        $data = $request->except(['password', 'roles']);
        if ($request->wantsPasswordChange()) {
            $data['password'] = bcrypt($request->getNewPassword());
        }

        try {
            $user->update($data);
            $user->syncRoles($request->roles());

            $flashMessage = __(':name has been updated.', ['name' => $user->name]);
            if ($request->wantsPasswordChange()) {
                $flashMessage .= ' ' . __("The user's password has changed");
            }

            flash()->success($flashMessage);
        } catch (\Exception $e) {
            flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));

            return redirect()->back();
        }

        return redirect(route('appshell.user.show', $user));
    }
119121
public static function loginas($userid, \context $context, $generateevent = true) {
        global $USER;

        if (self::is_loggedinas()) {
            return;
        }

        // Switch to fresh new $_SESSION.
        $_SESSION = array();
        $_SESSION['REALSESSION'] = clone($GLOBALS['SESSION']);
        $GLOBALS['SESSION'] = new \stdClass();
        $_SESSION['SESSION'] =& $GLOBALS['SESSION'];

        // Create the new $USER object with all details and reload needed capabilities.
        $_SESSION['REALUSER'] = clone($GLOBALS['USER']);
        $user = get_complete_user_data('id', $userid);
        $user->realuser       = $_SESSION['REALUSER']->id;
        $user->loginascontext = $context;

        // Let enrol plugins deal with new enrolments if necessary.
        enrol_check_plugins($user);

        if ($generateevent) {
            // Create event before $USER is updated.
            $event = \core\event\user_loggedinas::create(
                array(
                    'objectid' => $USER->id,
                    'context' => $context,
                    'relateduserid' => $userid,
                    'other' => array(
                        'originalusername' => fullname($USER, true),
                        'loggedinasusername' => fullname($user, true)
                    )
                )
            );
        }

        // Set up global $USER.
        \core\session\manager::set_user($user);

        if ($generateevent) {
            $event->trigger();
        }
    }
740207
public function addGrant($counterId, Models\Grant $grant)
    {
        $resource = 'counter/' . $counterId . '/grants';
        $response = $this->sendPostRequest($resource, ["grant" => $grant->toArray()]);
        $grantResponse = new Models\AddGrantResponse($response);
        return $grantResponse->getGrant();
    }