Gets Team drops or create one.

@param Dropzone $dropzone
@param User     $user

@return array
480551
public function getTeamDrops(Dropzone $dropzone, User $user)
    {
        $drops = $this->dropRepo->findTeamDrops($dropzone, $user);

        return $drops;
    }
1203644
private function unlockOrLockUsers(Dropzone $dropzone, $unlock = true)
    {
        $this->get('icap.manager.dropzone_voter')->isAllowToOpen($dropzone);
        $this->get('icap.manager.dropzone_voter')->isAllowToEdit($dropzone);

        $dropRepo = $this->getDoctrine()->getManager()->getRepository('IcapDropzoneBundle:Drop');
        $drops = $dropRepo->findBy(['dropzone' => $dropzone->getId(), 'unlockedUser' => !$unlock]);

        foreach ($drops as $drop) {
            $drop->setUnlockedUser($unlock);
        }
        $em = $this->getDoctrine()->getManager();
        $em->flush();

        return $this->redirect(
            $this->generateUrl(
                'icap_dropzone_examiners',
                [
                    'resourceId' => $dropzone->getId(),
                ]
            )
        );
    }
715573
public function isUnlockedDrop($dropzoneId, $userId)
    {
        $qb = $this->createQueryBuilder('drop')
            ->select('drop.unlockedUser')
            ->andWhere('drop.dropzone = :dropzone')
            ->andWhere('drop.user = :user')
            ->setParameter('dropzone', $dropzoneId)
            ->setParameter('user', $userId);
        $isUnlockedDrop = $qb->getQuery()->getOneOrNullResult();

        return $isUnlockedDrop;
    }
412807
public function getFinishedPeerDrops(Dropzone $dropzone, User $user = null, $teamId = null)
    {
        $drops = [];

        switch ($dropzone->getDropType()) {
            case Dropzone::DROP_TYPE_USER:
                if (!empty($user)) {
                    $drops = $this->dropRepo->findUserFinishedPeerDrops($dropzone, $user);
                }
                break;
            case Dropzone::DROP_TYPE_TEAM:
                if ($teamId) {
                    $drops = $this->dropRepo->findTeamFinishedPeerDrops($dropzone, $teamId);
                }
                break;
        }

        return $drops;
    }
1319775
public function getRegistrationsSummaryForUser(User $user)
    {
        $data = [];
        $rsm = $this->createResultSetMappingBuilder('d');
        $rsm->addScalarResult('sbas_id','sbas_id');
        $rsm->addScalarResult('base_id','base_id');
        $rsm->addScalarResult('dbname','dbname');
        $rsm->addScalarResult('time_limited', 'time_limited');
        $rsm->addScalarResult('limited_from', 'limited_from');
        $rsm->addScalarResult('limited_to', 'limited_to');
        $rsm->addScalarResult('actif', 'actif');

        $sql = "
        SELECT dbname, sbas.sbas_id, time_limited,
               UNIX_TIMESTAMP( limited_from ) AS limited_from,
               UNIX_TIMESTAMP( limited_to ) AS limited_to,
               bas.server_coll_id, Users.id, basusr.actif,
               bas.base_id, " . $rsm->generateSelectClause(['d' => 'd',]) . "
        FROM (Users, bas, sbas)
          LEFT JOIN basusr ON ( Users.id = basusr.usr_id AND bas.base_id = basusr.base_id )
          LEFT JOIN Registrations d ON ( d.user_id = Users.id AND bas.base_id = d.base_id )
        WHERE basusr.actif = 1 AND bas.sbas_id = sbas.sbas_id
        AND Users.id = ?";

        $query = $this->_em->createNativeQuery($sql, $rsm);
        $query->setParameter(1, $user->getId());

        foreach ($query->getResult() as $row) {
            $registrationEntity = $row[0];
            $data[$row['sbas_id']][$row['base_id']] = [
                'base-id' => $row['base_id'],
                'db-name' => $row['dbname'],
                'active' => (Boolean) $row['actif'],
                'time-limited' => (Boolean) $row['time_limited'],
                'in-time' => $row['time_limited'] && ! ($row['limited_from'] >= time() && $row['limited_to'] <= time()),
                'registration' => $registrationEntity
            ];
        }

        return $data;
    }
812523
protected function assignUserToUserGroups(User $user, array $userGroupObjects)
    {
        $ezUserGroups = [];
        foreach ($userGroupObjects as $userGroup) {
            $userGroup = $this->userGroupManager->createOrUpdate($userGroup);
            if ($userGroup instanceof UserGroupObject) {
                $ezUserGroup = $this->userGroupManager->find($userGroup);
                if ($ezUserGroup) {
                    $ezUserGroups[$ezUserGroup->id] = $ezUserGroup;
                    try {
                        $this->userService->assignUserToUserGroup($user, $ezUserGroup);
                    } catch (InvalidArgumentException $alreadyAssignedException) {
                        // Ignore error about: user already assigned to usergroup.
                    }
                }
            }
        }

        return $ezUserGroups;
    }
121126
public static function get($user, $id = false)
    {
        $params = array();

        if ($id) {
            $params['id'] = $id;
        }

        return $user->get('pylon/get', $params);
    }
1049369
public static function collectByUser($user_id)
    {
        $user = AclUser::find($user_id);
        if ($user === null) {
            return collect([]);
        }

        return (new static)->where('group_id', $user->acl_group_id)->get();
    }
1073499
protected function getEmailData(User $user, $email)
    {
        $token = $this->generateToken($user, $email);

        return [
            '{username}' => $user->display_name,
            '{url}' => $this->url->to('forum')->route('confirmEmail', ['token' => $token->token]),
            '{forum}' => $this->settings->get('forum_title')
        ];
    }
261128
public function getQbLastByUser(User $user)
    {
        $qb = $this->createQueryBuilder('d')
            ->where('d.createdBy = :user1 OR d.updatedBy = :user2')
            ->orderBy('d.updatedAt', 'desc')
            ->setParameters(
                [
                    'user1' => $user,
                    'user2' => $user,
                ]
            );

        return $qb;
    }
642605
public function getTeamDrop(Dropzone $dropzone, Team $team, User $user, $withCreation = false)
    {
        $drop = $this->dropRepo->findOneBy(['dropzone' => $dropzone, 'teamUuid' => $team->getUuid()]);

        if ($withCreation) {
            if (empty($drop)) {
                $this->om->startFlushSuite();
                $drop = new Drop();
                $drop->setUser($user);
                $drop->setDropzone($dropzone);
                $drop->setTeamId($team->getId());
                $drop->setTeamUuid($team->getUuid());
                $drop->setTeamName($team->getName());

                foreach ($team->getRole()->getUsers() as $teamUser) {
                    $drop->addUser($teamUser);
                    /* TODO: checks that a valid status is not overwritten */
                    $this->resourceEvalManager->createResourceEvaluation(
                        $dropzone->getResourceNode(),
                        $teamUser,
                        null,
                        ['status' => AbstractResourceEvaluation::STATUS_INCOMPLETE]
                    );
                }
                $this->om->persist($drop);
                $this->om->endFlushSuite();

                $this->eventDispatcher->dispatch('log', new LogDropStartEvent($dropzone, $drop));
            } elseif (!$drop->hasUser($user)) {
                $this->om->startFlushSuite();
                $drop->addUser($user);
                $this->resourceEvalManager->createResourceEvaluation(
                    $dropzone->getResourceNode(),
                    $user,
                    null,
                    ['status' => AbstractResourceEvaluation::STATUS_INCOMPLETE]
                );
                $this->om->persist($drop);
                $this->om->endFlushSuite();
            }
        }

        return $drop;
    }
798111
public function getAllCorrectionsData(Dropzone $dropzone)
    {
        $data = [];
        $corrections = $this->correctionRepo->findAllCorrectionsByDropzone($dropzone);

        foreach ($corrections as $correction) {
            $teamId = $correction->getTeamUuid();
            $key = empty($teamId) ? 'user_'.$correction->getUser()->getUuid() : 'team_'.$teamId;

            if (!isset($data[$key])) {
                $data[$key] = [];
            }
            $data[$key][] = $this->serializeCorrection($correction);
        }

        return $data;
    }
132693
public function copyDropzone(Dropzone $dropzone, DropZone $newDropzone)
    {
        foreach ($dropzone->getCriteria() as $criterion) {
            $newCriterion = new Criterion();
            $newCriterion->setDropzone($newDropzone);
            $newCriterion->setInstruction($criterion->getInstruction());
            $this->om->persist($newCriterion);
        }

        return $newDropzone;
    }
408671
public function usersWorkflows(Member $user)
    {

        $groupIds = $user->Groups()->column('ID');

        $groupInstances = null;

        $filter = array('');

        if (is_array($groupIds)) {
            $groupInstances = DataList::create(WorkflowInstance::class)
                ->filter(array('Group.ID:ExactMatchMulti' => $groupIds))
                ->where('"WorkflowStatus" != \'Complete\'');
        }

        $userInstances = DataList::create(WorkflowInstance::class)
            ->filter(array('Users.ID:ExactMatch' => $user->ID))
            ->where('"WorkflowStatus" != \'Complete\'');

        if ($userInstances) {
            $userInstances = $userInstances->toArray();
        } else {
            $userInstances = array();
        }

        if ($groupInstances) {
            $groupInstances = $groupInstances->toArray();
        } else {
            $groupInstances = array();
        }

        $all = array_merge($groupInstances, $userInstances);

        return ArrayList::create($all);
    }
1370766
public function openDropZoneAction(DropZone $dropzone)
    {
        return $this->redirect(
            $this->generateUrl('claro_resource_open', [
                'node' => $dropzone->getResourceNode()->getId(),
                'resourceType' => $dropzone->getResourceNode()->getResourceType()->getName(),
            ])
        );
    }
819400
public function submitCorrection(Correction $correction, User $user)
    {
        $this->om->startFlushSuite();

        $correction->setFinished(true);
        $correction->setEndDate(new \DateTime());
        $correction->setUser($user);
        $this->om->persist($correction);
        $this->om->forceFlush();
        $drop = $this->computeDropScore($correction->getDrop());
        $dropzone = $drop->getDropzone();
        $userDrop = null;
        $users = [];

        switch ($dropzone->getDropType()) {
            case Dropzone::DROP_TYPE_USER:
                $users = [$user];
                $userDrop = $this->getUserDrop($dropzone, $user);
                break;
            case Dropzone::DROP_TYPE_TEAM:
                $teamDrops = $this->getTeamDrops($dropzone, $user);

                if (1 === count($teamDrops)) {
                    $users = $teamDrops[0]->getUsers();
                    $userDrop = $teamDrops[0];
                }
                break;
        }
        $this->eventDispatcher->dispatch('log', new LogCorrectionEndEvent($dropzone, $correction->getDrop(), $correction));
        $this->om->forceFlush();

        $this->checkSuccess($drop);
        $this->checkCompletion($dropzone, $users, $userDrop);

        $this->om->endFlushSuite();

        return $correction;
    }
849949
public function getAvailableRoutes($user = null): array
    {
        if ($user instanceof ModelDecoratorInterface) {
            $user = $user->getModel();
        }
        if (is_null($user)) {
            $user = $this->helper->getCurrentUser();
        }

        $routes = [];
        foreach ($this->router->getRouteCollection()->getIterator() as $routeName => $route) {
            if (!$this->checkRouteAccess($routeName, $user)) {
                continue;
            }

            if (!isset($routes['routes'])) {
                $routes['routes'] = [];
            }
            $routes['routes'][$route->getPath()] = $route->getPath();
        }

        $tree = $this->treeBuilder->getTree();
        if (!empty($tree['route_patterns'])) {
            foreach ($tree['route_patterns'] as $pattern => $permissions) {
                if (!$this->la->checkAccess($permissions, ['user' => $user])) {
                    continue;
                }

                if (!isset($routes['route_patterns'])) {
                    $routes['route_patterns'] = [];
                }
                $routes['route_patterns'][$pattern] = $pattern;
            }
        }

        return $routes;
    }