Returns nearby submissions (by runtime) for a particular user submission to a problem.

@param int $problem
@param int $user
@param int $above
@param int $below

@return array
336161
public function userProblemRanklist($problem, $user, $above = 10, $below = 10)
    {
        $rawSubmissions = $this->load('p/ranklist', array($problem, $user, $above, $below));
        $submissions = array();

        foreach ($rawSubmissions as $submission) {
            $submissions[] = Helper\formatSubmission($submission);
        }

        return $submissions;
    }
20388
protected function getVosForRegistration($user)
    {
        $vos = array();
        $members = array();
        $vosIdForRegistration = array();
        $vosForRegistration = array();

        $vos = $this->getVosByFacilityVoShortNames();
        foreach ($vos as $vo) {
            Logger::debug("Vo:" . print_r($vo, true));
            try {
                $member = $this->rpcAdapter->getMemberByUser($user, $vo);
                Logger::debug("Member:" . print_r($member, true));
                array_push($members, $member);
            } catch (\Exception $exception) {
                array_push($vosForRegistration, $vo);
                Logger::warning("perun:PerunIdentity: " . $exception);
            }
        }

        foreach ($members as $member) {
            if ($member->getStatus() === Member::VALID ||
                $member->getStatus() === Member::EXPIRED) {
                array_push($vosIdForRegistration, $member->getVoId());
            }
        }

        foreach ($vos as $vo) {
            if (in_array($vo->getId(), $vosIdForRegistration)) {
                array_push($vosForRegistration, $vo);
            }
        }
        Logger::debug("VOs for registration:  " . print_r($vosForRegistration, true));
        return $vosForRegistration;
    }
161986
public function getPermissions(User $user, array $resourceIds) {

        $results = array();
        $allRights = $this->getSupportedRights();

        foreach ($this->getInner() as $impl) {
            //Get rights not supported by implementation
            $notSupported = array_diff($allRights, $impl->getSupportedRights());
            $resourceRights = $impl->getPermissions($user, $resourceIds);
            $resourcesRights = [];
            foreach ($resourceRights as $uri => $resourceRight){
                $resourcesRights[$uri] = array_merge($notSupported, $resourceRight);
            }
            $results[] = $resourcesRights;
        }

        $rights = array();
        foreach ($resourceIds as $id) {
            $intersect = null;
            foreach ($results as $modelResult) {
                $intersect = is_null($intersect)
                    ? $modelResult[$id]
                    : array_intersect($intersect, $modelResult[$id]);
            }
            $rights[$id] = array_values($intersect);
        }
        
        return $rights;
    }
1287648
public function getRequestUser()
    {
        if ($this->requestUser === null) {
            $token = $this->getRequestApiToken();
            if ($token === '') {
                $this->requestUser = 'no-token';
            } else {
                $ip = $this->app->make('ip');
                if ($ip->isBanned()) {
                    $this->requestUser = 'banned';
                } else {
                    $requestUser = null;
                    $list = new UserList();
                    $list->disableAutomaticSorting();
                    $list->filterByAttribute('api_token', $token);
                    $ids = $list->getResultIDs();
                    if (!empty($ids)) {
                        $u = \User::getByUserID($ids[0]);
                        if ($u->isRegistered()) {
                            $requestUser = $u;
                        }
                    }
                    if ($requestUser === null) {
                        $this->requestUser == 'invalid-token';
                        $ip->logSignupRequest();
                        if ($ip->signupRequestThreshholdReached()) {
                            $ip->createIPBan();
                        }
                    } else {
                        $this->requestUser = $requestUser;
                    }
                }
            }
        }
        if ($this->requestUser === 'no-token') {
            throw AccessDeniedException::create(t('API Access Token required'));
        }
        if ($this->requestUser === 'banned') {
            throw AccessDeniedException::create($this->app->make('ip')->getErrorMessage());
        }
        if ($this->requestUser === 'invalid-token') {
            throw AccessDeniedException::create(t('Bad API Access Token'));
        }

        return $this->requestUser;
    }
314562
protected function fetch_posts_for_user($user) {
        // We maintain a mapping of user groups for each forum.
        $usergroups = [];
        $digeststructure = [];

        $poststructure = $this->adhocdata;
        $poststosend = [];
        foreach ($poststructure as $courseid => $forumids) {
            $course = $this->courses[$courseid];
            foreach ($forumids as $forumid => $discussionids) {
                $forum = $this->forums[$forumid];
                $maildigest = forum_get_user_maildigest_bulk($this->digestusers, $user, $forumid);

                if (!isset($this->subscribedusers[$forumid][$user->id])) {
                    // This user has no subscription of any kind to this forum.
                    // Do not send them any posts at all.
                    unset($poststructure[$courseid][$forumid]);
                    continue;
                }

                $subscriptiontime = \mod_forum\subscriptions::fetch_discussion_subscription($forum->id, $user->id);

                $cm = get_fast_modinfo($course)->instances['forum'][$forumid];
                foreach ($discussionids as $discussionid => $postids) {
                    $discussion = $this->discussions[$discussionid];
                    if (!\mod_forum\subscriptions::is_subscribed($user->id, $forum, $discussionid, $cm)) {
                        // The user does not subscribe to this forum as a whole, or to this specific discussion.
                        unset($poststructure[$courseid][$forumid][$discussionid]);
                        continue;
                    }

                    if ($discussion->groupid > 0 and $groupmode = groups_get_activity_groupmode($cm, $course)) {
                        // This discussion has a groupmode set (SEPARATEGROUPS or VISIBLEGROUPS).
                        // Check whether the user can view it based on their groups.
                        if (!isset($usergroups[$forum->id])) {
                            $usergroups[$forum->id] = groups_get_all_groups($courseid, $user->id, $cm->groupingid);
                        }

                        if (!isset($usergroups[$forum->id][$discussion->groupid])) {
                            // This user is not a member of this group, or the group no longer exists.

                            $modcontext = \context_module::instance($cm->id);
                            if (!has_capability('moodle/site:accessallgroups', $modcontext, $user)) {
                                // This user does not have the accessallgroups and is not a member of the group.
                                // Do not send posts from other groups when in SEPARATEGROUPS or VISIBLEGROUPS.
                                unset($poststructure[$courseid][$forumid][$discussionid]);
                                continue;
                            }
                        }
                    }

                    foreach ($postids as $postid) {
                        $post = $this->posts[$postid];
                        if ($subscriptiontime) {
                            // Skip posts if the user subscribed to the discussion after it was created.
                            $subscribedafter = isset($subscriptiontime[$post->discussion]);
                            $subscribedafter = $subscribedafter && ($subscriptiontime[$post->discussion] > $post->created);
                            if ($subscribedafter) {
                                // The user subscribed to the discussion/forum after this post was created.
                                unset($poststructure[$courseid][$forumid][$discussionid][$postid]);
                                continue;
                            }
                        }

                        if ($maildigest > 0) {
                            // This user wants the mails to be in digest form.
                            $digeststructure[] = (object) [
                                'userid' => $user->id,
                                'discussionid' => $discussion->id,
                                'postid' => $post->id,
                                'timemodified' => $post->created,
                            ];
                            unset($poststructure[$courseid][$forumid][$discussionid][$postid]);
                            continue;
                        } else {
                            // Add this post to the list of postids to be sent.
                            $poststosend[] = $postid;
                        }
                    }
                }

                if (empty($poststructure[$courseid][$forumid])) {
                    // This user is not subscribed to any discussions in this forum at all.
                    unset($poststructure[$courseid][$forumid]);
                    continue;
                }
            }
            if (empty($poststructure[$courseid])) {
                // This user is not subscribed to any forums in this course.
                unset($poststructure[$courseid]);
            }
        }

        return [$poststosend, $digeststructure];
    }
345921
public function getResourcesPermissions(User $user, $resources)
    {
        $permissions = [];
        if(!is_null($user)){
            try {
                $permissionManager = $this->getServiceManager()->get(PermissionInterface::SERVICE_ID);
                $supportedRights   = $permissionManager->getSupportedRights();
                $permissions['supportedRights'] = $supportedRights;

                if(count($supportedRights) > 0){
                    $uris = $this->getUris($resources);

                    $permissions['data'] = $permissionManager->getPermissions($user, $uris);
                }
            } catch(\Exception $e){
                \common_Logger::w('Unable to retrieve permssions ' . $e->getMessage());
            }
        }
        return $permissions;

    }
1001935
public function countUserFinishedPapers(Exercise $exercise, User $user)
    {
        return (int) $this->getEntityManager()
            ->createQuery('
                SELECT COUNT(p)
                FROM UJM\ExoBundle\Entity\Attempt\Paper AS p
                WHERE p.user = :user
                  AND p.exercise = :exercise
                  AND p.end IS NOT NULL
            ')
            ->setParameters([
                'user' => $user,
                'exercise' => $exercise,
            ])
            ->getSingleScalarResult();
    }
585232
private function byRequestRememberPasswordSpecification($user)
    {
        (new RequestRememberPasswordCommandBuilder($this->container, $this->persistence))->build($user);

        return [
            'command' => ByRequestRememberPasswordChangeUserPasswordCommand::class,
            'handler' => ByRequestRememberPasswordChangeUserPasswordHandler::class,
        ];
    }
1359623
public function scopeForUserWithNewMessages(Builder $query, $userId)
    {
        $participantTable = Models::table('participants');
        $threadsTable = Models::table('threads');

        return $query->join($participantTable, $this->getQualifiedKeyName(), '=', $participantTable . '.thread_id')
            ->where($participantTable . '.user_id', $userId)
            ->whereNull($participantTable . '.deleted_at')
            ->where(function (Builder $query) use ($participantTable, $threadsTable) {
                $query->where($threadsTable . '.updated_at', '>', $this->getConnection()->raw($this->getConnection()->getTablePrefix() . $participantTable . '.last_read'))
                    ->orWhereNull($participantTable . '.last_read');
            })
            ->select($threadsTable . '.*');
    }
907177
private function listUserAuthorizedSubdefs(User $user)
    {
        $acl = $this->getAclForUser($user);
        $ret = [];

        foreach ($acl->get_granted_sbas() as $databox) {
            $databoxId = $databox->get_sbas_id();
            $subdefs = $databox->get_subdef_structure();
            foreach ($subdefs as $subGroup) {
                foreach ($subGroup->getIterator() as $sub) {
                    $opt = [];
                    $data = [
                      'name'             => $sub->get_name(),
                      'databox_id'       => $databoxId,
                      'class'            => $sub->get_class(),
                      'preset'           => $sub->get_preset(),
                      'downloadable'     => $sub->isDownloadable(),
                      'devices'          => $sub->getDevices(),
                      'labels'           => [
                        'fr' => $sub->get_label('fr'),
                        'en' => $sub->get_label('en'),
                        'de' => $sub->get_label('de'),
                        'nl' => $sub->get_label('nl'),
                      ],
                    ];
                    $options = $sub->getOptions();
                    foreach ($options as $option) {
                        $opt[$option->getName()] = $option->getValue();
                    }
                    $data['options'] = $opt;
                    $ret[$subGroup->getName()][$sub->get_name()] = $data;
                }
            }
        }

        return $ret;
    }
396850
private function isRelativeTo($threshold, $above = true)
	{
		$threshold = ip2long($threshold);

		if (!$threshold)
		{
			throw new \RuntimeException('Invalid input, not an IP address');
		}

		return $above ? ($this->ipLong >= $threshold) : ($this->ipLong <= $threshold);
	}
590724
public function findByUser(User $user, $asArray = true)
    {
        $groupQb = $this->_em->createQueryBuilder()
            ->select('g')
            ->from('Claroline\CoreBundle\Entity\Group', 'g')
            ->join('g.users', 'gu')
            ->where('gu = :user');

        $select = $asArray ? 'o.id, o.name, op.percentage AS progress, COUNT(oc) AS competencyCount' : 'o';

        $query = $this->createQueryBuilder('o')
            ->select($select)
            ->leftJoin('o.objectiveCompetencies', 'oc')
            ->leftJoin('o.users', 'ou')
            ->leftJoin('o.groups', 'og')
            ->leftJoin(
                'HeVinci\CompetencyBundle\Entity\Progress\ObjectiveProgress',
                'op',
                'WITH',
                'op.user = :user AND op.objective = o'
            )
            ->andWhere($groupQb->expr()->orX(
                'ou = :user',
                $groupQb->expr()->in('og', $groupQb->getQuery()->getDQL())
            ))
            ->groupBy('o.id')
            ->setParameter(':user', $user)
            ->getQuery();

        return $query->{$asArray ? 'getArrayResult' : 'getResult'}();
    }
603902
public function getPageAction(ServerRequestInterface $request, Tree $tree, UserInterface $user): ResponseInterface
    {
        Auth::checkComponentAccess($this, 'list', $tree, $user);
      
        $listController = new BranchesController(app(ModuleService::class));
        return $listController->page($request);
    }
1105301
public function getResourceUserPermission(ResourceInterface $resource, UserInterface $user)
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId AND r.user=:user')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->setParameter('user', $user)
            ->getQuery();

        return $query->getOneOrNullResult();
    }
12067
public function getUserNotificationsList(User $user, $page = 1, $maxResult = -1, $isRss = false, $notificationParameters = null, $category = null)
    {
        $query = $this->getUserNotifications($user, $page, $maxResult, $isRss, $notificationParameters, false, $category);
        $adapter = new DoctrineORMAdapter($query, false);
        $pager = new Pagerfanta($adapter);
        $pager->setMaxPerPage($maxResult);

        try {
            $pager->setCurrentPage($page);
        } catch (NotValidCurrentPageException $e) {
            throw new NotFoundHttpException();
        }
        $notifications = $this->renderNotifications($pager->getCurrentPageResults());

        return [
            'pager' => $pager,
            'notificationViews' => $notifications['views'],
            'colors' => $notifications['colors'],
        ];
    }
1124236
public function getUserRegistrations(User $user, array $collections)
    {
        $qb = $this->createQueryBuilder('d');
        $qb->where($qb->expr()->eq('d.user', ':user'));
        $qb->setParameter(':user', $user->getId());

        if (count($collections) > 0) {
            $qb->andWhere('d.baseId IN (:bases)');
            $qb->setParameter(':bases', array_map(function (\collection $collection) {
                return $collection->get_base_id();
            }, $collections));
        }

        $qb->orderBy('d.created', 'DESC');

        return $qb->getQuery()->getResult();
    }
756156
public function findWorkspacesWithSelfRegistrationBySearch(User $user, $search)
    {
        $dql = '
            SELECT w
            FROM Claroline\CoreBundle\Entity\Workspace\Workspace w
            WHERE w.displayable = true
            AND w.selfRegistration = true
            AND (
                UPPER(w.name) LIKE :search
                OR UPPER(w.code) LIKE :search
            )
            AND w.id NOT IN (
                SELECT w2.id FROM Claroline\CoreBundle\Entity\Workspace\Workspace w2
                JOIN w2.roles r
                JOIN r.users u
                WHERE u.id = :userId
            )
            ORDER BY w.name
        ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('userId', $user->getId());
        $search = strtoupper($search);
        $query->setParameter('search', "%{$search}%");

        return $query->getResult();
    }