Example #1
0
 public function registerGroupToSessions(array $sessions, Group $group, $type = 0)
 {
     $registrationDate = new \DateTime();
     $this->om->startFlushSuite();
     foreach ($sessions as $session) {
         $users = $group->getUsers()->toArray();
         $sessionGroup = $this->sessionGroupRepo->findOneSessionGroupBySessionAndGroup($session, $group, $type);
         if (is_null($sessionGroup)) {
             $sessionGroup = new CourseSessionGroup();
             $sessionGroup->setSession($session);
             $sessionGroup->setGroup($group);
             $sessionGroup->setGroupType($type);
             $sessionGroup->setRegistrationDate($registrationDate);
             $this->om->persist($sessionGroup);
         }
         foreach ($users as $user) {
             $sessionUser = $this->sessionUserRepo->findOneSessionUserBySessionAndUserAndType($session, $user, $type);
             if (is_null($sessionUser)) {
                 $sessionUser = new CourseSessionUser();
                 $sessionUser->setSession($session);
                 $sessionUser->setUser($user);
                 $sessionUser->setUserType($type);
                 $sessionUser->setRegistrationDate($registrationDate);
                 $this->om->persist($sessionUser);
             }
         }
         $role = null;
         if (intval($type) === 0) {
             $role = $session->getLearnerRole();
         } elseif (intval($type) === 1) {
             $role = $session->getTutorRole();
         }
         if (!is_null($role)) {
             $this->roleManager->associateRole($group, $role);
         }
     }
     $this->om->endFlushSuite();
 }
Example #2
0
 public function registerGroupToSessions(array $sessions, Group $group, $type = 0)
 {
     $users = $group->getUsers()->toArray();
     $results = ['status' => 'success', 'datas' => []];
     if (intval($type) === CourseSessionUser::LEARNER) {
         foreach ($sessions as $session) {
             $course = $session->getCourse();
             $remainingPlaces = $this->getSessionRemainingPlace($session);
             if (!is_null($remainingPlaces) && $remainingPlaces < count($users)) {
                 $results['status'] = 'failed';
                 $results['datas'][] = ['sessionId' => $session->getId(), 'sessionName' => $session->getName(), 'courseId' => $course->getId(), 'courseTitle' => $course->getTitle(), 'courseCode' => $course->getCode(), 'remainingPlaces' => $remainingPlaces];
             }
         }
     }
     if ($results['status'] === 'success') {
         $this->om->startFlushSuite();
         $registrationDate = new \DateTime();
         foreach ($sessions as $session) {
             $sessionGroup = $this->sessionGroupRepo->findOneSessionGroupBySessionAndGroup($session, $group, $type);
             if (is_null($sessionGroup)) {
                 $sessionGroup = new CourseSessionGroup();
                 $sessionGroup->setSession($session);
                 $sessionGroup->setGroup($group);
                 $sessionGroup->setGroupType($type);
                 $sessionGroup->setRegistrationDate($registrationDate);
                 $this->om->persist($sessionGroup);
             }
             foreach ($users as $user) {
                 $sessionUser = $this->sessionUserRepo->findOneSessionUserBySessionAndUserAndType($session, $user, $type);
                 if (is_null($sessionUser)) {
                     $sessionUser = new CourseSessionUser();
                     $sessionUser->setSession($session);
                     $sessionUser->setUser($user);
                     $sessionUser->setUserType($type);
                     $sessionUser->setRegistrationDate($registrationDate);
                     $this->om->persist($sessionUser);
                 }
             }
             $role = null;
             if (intval($type) === 0) {
                 $role = $session->getLearnerRole();
             } elseif (intval($type) === 1) {
                 $role = $session->getTutorRole();
             }
             if (!is_null($role)) {
                 $this->roleManager->associateRole($group, $role);
             }
         }
         $this->om->endFlushSuite();
     }
     return $results;
 }