public function __construct(CourseSessionUser $sessionUser)
 {
     $session = $sessionUser->getSession();
     $course = $session->getCourse();
     $user = $sessionUser->getUser();
     $details = array();
     $details['username'] = $user->getUsername();
     $details['firsName'] = $user->getFirstName();
     $details['lastName'] = $user->getLastName();
     $details['sessionId'] = $session->getId();
     $details['sessionName'] = $session->getName();
     $details['sessionCreationDate'] = $session->getCreationDate()->format('d/m/Y H:i:s');
     $details['userType'] = $sessionUser->getUserType();
     $details['courseId'] = $course->getId();
     $details['courseTitle'] = $course->getTitle();
     $details['courseCode'] = $course->getCode();
     $details['registrationDate'] = $sessionUser->getRegistrationDate()->format('d/m/Y H:i:s');
     parent::__construct(self::ACTION, $details, $user);
 }
示例#2
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();
 }
示例#3
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;
 }