public function findSessionGroupsByGroup(Group $group, $executeQuery = true)
 {
     $dql = '
         SELECT csg
         FROM Claroline\\CursusBundle\\Entity\\CourseSessionGroup csg
         JOIN csg.group g
         WHERE g.name = :group
         ORDER BY csg.registrationDate DESC
     ';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('group', $group->getName());
     return $executeQuery ? $query->getResult() : $query;
 }
 public function findCursusByGroup(Group $group, $executeQuery = true)
 {
     $dql = '
         SELECT c
         FROM Claroline\\CursusBundle\\Entity\\Cursus c
         WHERE EXISTS (
             SELECT cg
             FROM Claroline\\CursusBundle\\Entity\\CursusGroup cg
             JOIN cg.group g
             WHERE g.name = :group
             AND cg.cursus = c
         )
     ';
     $query = $this->_em->createQuery($dql);
     $query->setParameter('group', $group->getName());
     return $executeQuery ? $query->getResult() : $query;
 }
    public function countUsersOfGroupByRole(Group $group, Role $role)
    {
        $dql = '
            SELECT count(u) FROM Claroline\\CoreBundle\\Entity\\User u
            JOIN u.groups g
            WHERE g.name = :groupName
            AND u.id in
                (
                    SELECT u2.id FROM Claroline\\CoreBundle\\Entity\\User u2
                    LEFT JOIN u2.roles r1
                    LEFT JOIN u2.groups g2
                    LEFT JOIN g2.roles r2
                    WHERE r1.name = :roleName
                    OR r2.name = :roleName
                )

        ';
        $query = $this->_em->createQuery($dql);
        $query->setParameter('roleName', $role->getName());
        $query->setParameter('groupName', $group->getName());
        return $query->getSingleScalarResult();
    }
 /**
  * @EXT\Route(
  *     "multiple/cursus/register/group/{group}",
  *     name="claro_cursus_multiple_register_group",
  *     options = {"expose"=true}
  * )
  * @EXT\Method("POST")
  * @EXT\ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
  * @EXT\ParamConverter(
  *     "multipleCursus",
  *      class="ClarolineCursusBundle:Cursus",
  *      options={"multipleIds" = true, "name" = "cursusIds"}
  * )
  * @EXT\ParamConverter(
  *     "sessions",
  *      class="ClarolineCursusBundle:CourseSession",
  *      options={"multipleIds" = true, "name" = "sessionIds"}
  * )
  *
  * @param Group $group
  * @param Cursus[] $multipleCursus
  * @param CourseSession[] $sessions
  * @param User $authenticatedUser
  */
 public function cursusGroupRegisterToMultipleCursusAction(Group $group, array $multipleCursus, array $sessions, User $authenticatedUser)
 {
     $this->checkToolAccess();
     $coursesWithSession = array();
     $sessionsToCreate = array();
     $root = 0;
     $cursusRoot = null;
     $registrationDate = new \DateTime();
     $configStartDate = $this->platformConfigHandler->getParameter('cursusbundle_default_session_start_date');
     $configEndDate = $this->platformConfigHandler->getParameter('cursusbundle_default_session_end_date');
     $startDate = empty($configStartDate) ? null : new \DateTime($configStartDate);
     $endDate = empty($configEndDate) ? null : new \DateTime($configEndDate);
     foreach ($sessions as $session) {
         $course = $session->getCourse();
         $coursesWithSession[$course->getId()] = true;
     }
     foreach ($multipleCursus as $cursus) {
         $root = $cursus->getRoot();
         $course = $cursus->getCourse();
         if (!is_null($course) && !isset($coursesWithSession[$course->getId()]) && !in_array($course, $sessionsToCreate)) {
             $sessionsToCreate[] = $course;
         }
     }
     if ($root > 0) {
         $cursusRoot = $this->cursusManager->getOneCursusById($root);
     }
     // Generate the list of sessions where the user will be register
     foreach ($sessionsToCreate as $course) {
         $sessionName = $group->getName();
         $session = $this->cursusManager->createCourseSession($course, $authenticatedUser, $sessionName, $cursusRoot, $registrationDate, $startDate, $endDate);
         $sessions[] = $session;
     }
     $this->cursusManager->registerGroupToMultipleCursus($multipleCursus, $group);
     $this->cursusManager->registerGroupToSessions($sessions, $group);
     return new JsonResponse('success', 200);
 }
Example #5
0
 public function registerGroupToCursusAndSessions(Group $group, array $multipleCursus, array $sessions)
 {
     $this->checkCursusToolRegistrationAccess();
     $coursesWithSession = [];
     $sessionsToCreate = [];
     $root = 0;
     $cursusRoot = null;
     $registrationDate = new \DateTime();
     $configStartDate = $this->platformConfigHandler->getParameter('cursusbundle_default_session_start_date');
     $configEndDate = $this->platformConfigHandler->getParameter('cursusbundle_default_session_end_date');
     $startDate = empty($configStartDate) ? null : new \DateTime($configStartDate);
     $endDate = empty($configEndDate) ? null : new \DateTime($configEndDate);
     foreach ($sessions as $session) {
         $course = $session->getCourse();
         $coursesWithSession[$course->getId()] = true;
     }
     foreach ($multipleCursus as $cursus) {
         $root = $cursus->getRoot();
         $course = $cursus->getCourse();
         if (!is_null($course) && !isset($coursesWithSession[$course->getId()]) && !in_array($course, $sessionsToCreate)) {
             $sessionsToCreate[] = $course;
         }
     }
     if ($root > 0) {
         $cursusRoot = $this->getOneCursusById($root);
         $this->associateCursusToSessions($cursusRoot, $sessions);
     }
     // Generate the list of sessions where the user will be register
     foreach ($sessionsToCreate as $course) {
         $sessionName = $group->getName();
         $session = $this->createCourseSession($course, $sessionName, null, [$cursusRoot], $registrationDate, $startDate, $endDate, false, $course->getPublicRegistration(), $course->getPublicUnregistration(), $course->getRegistrationValidation(), $course->getUserValidation(), $course->getOrganizationValidation(), $course->getMaxUsers(), 0, $course->getValidators(), CourseSession::REGISTRATION_AUTO, $course->getDisplayOrder());
         $sessions[] = $session;
     }
     $results = $this->registerGroupToSessions($sessions, $group);
     if ($results['status'] === 'success') {
         $this->registerGroupToMultipleCursus($multipleCursus, $group);
     }
     return $results;
 }