Esempio n. 1
0
 /**
  * @DI\Observe("claroline.log.create")
  *
  * @param \Claroline\CoreBundle\Event\LogCreateEvent $event
  */
 public function onLog(LogCreateEvent $event)
 {
     /** @var \Icap\BadgeBundle\Repository\BadgeRuleRepository $badgeRuleRepository */
     $badgeRuleRepository = $this->entityManager->getRepository('IcapBadgeBundle:BadgeRule');
     /** @var \Icap\BadgeBundle\Entity\Badge[] $badges */
     $badges = $badgeRuleRepository->findBadgeAutomaticallyAwardedFromAction($event->getLog());
     if (0 < count($badges)) {
         $doer = $event->getLog()->getDoer();
         $receiver = $event->getLog()->getReceiver();
         foreach ($badges as $badge) {
             $nbRules = count($badge->getRules());
             if (null !== $doer && !$this->userHasBadge($doer, $badge)) {
                 $resources = $this->ruleValidator->validate($badge, $doer);
                 if (0 < $resources['validRules'] && $resources['validRules'] >= $nbRules) {
                     $this->badgeManager->addBadgeToUser($badge, $doer);
                 }
             }
             if (null !== $receiver && !$this->userHasBadge($receiver, $badge)) {
                 $resources = $this->ruleValidator->validate($badge, $receiver);
                 if (0 < $resources['validRules'] && $resources['validRules'] >= $nbRules) {
                     $this->badgeManager->addBadgeToUser($badge, $receiver);
                 }
             }
         }
     }
 }
 /**
  * @DI\Observe("claroline.log.create")
  *
  * @param \Claroline\CoreBundle\Event\LogCreateEvent $event
  */
 public function onLog(LogCreateEvent $event)
 {
     $log = $event->getLog();
     $action = $log->getAction();
     $user = $log->getReceiver();
     $group = $log->getReceiverGroup();
     $sessions = ['learner' => [], 'tutor' => []];
     if ($action === 'group-add_user') {
         $multipleCursus = $this->cursusManager->getCursusByGroup($group);
         //check if the user is already persisted in database
         $force = $user->getId() ? false : true;
         $this->cursusManager->registerUserToMultipleCursus($multipleCursus, $user, true, false, $force);
         $sessionGroups = $this->cursusManager->getSessionGroupsByGroup($group);
         foreach ($sessionGroups as $sessionGroup) {
             $groupType = $sessionGroup->getGroupType();
             if ($groupType === 0) {
                 $sessions['learner'][] = $sessionGroup->getSession();
             } elseif ($groupType === 1) {
                 $sessions['tutor'][] = $sessionGroup->getSession();
             }
         }
         if (count($sessions['learner']) > 0) {
             $this->cursusManager->registerUsersToSessions($sessions['learner'], [$user], 0, $force);
         }
         if (count($sessions['tutor']) > 0) {
             $this->cursusManager->registerUsersToSessions($sessions['tutor'], [$user], 1, $force);
         }
     } elseif ($action === 'group-remove_user') {
         $multipleCursus = $this->cursusManager->getCursusByGroup($group);
         $cursusUsers = $this->cursusManager->getCursusUsersFromCursusAndUsers($multipleCursus, [$user]);
         $this->cursusManager->deleteCursusUsers($cursusUsers);
         $sessionGroups = $this->cursusManager->getSessionGroupsByGroup($group);
         foreach ($sessionGroups as $sessionGroup) {
             $groupType = $sessionGroup->getGroupType();
             if ($groupType === 0) {
                 $sessions['learner'][] = $sessionGroup->getSession();
             } elseif ($groupType === 1) {
                 $sessions['tutor'][] = $sessionGroup->getSession();
             }
         }
         $sessionUsers = [];
         if (count($sessions['learner']) > 0) {
             $sessionUsers = $this->cursusManager->getSessionUsersBySessionsAndUsers($sessions['learner'], [$user], 0);
         }
         if (count($sessions['tutor']) > 0) {
             $sessionTutors = $this->cursusManager->getSessionUsersBySessionsAndUsers($sessions['tutor'], [$user], 1);
             $sessionUsers = array_merge($sessionUsers, $sessionTutors);
         }
         $this->cursusManager->deleteCourseSessionUsers($sessionUsers);
     }
 }
 /**
  * @DI\Observe("claroline.log.create")
  *
  * @param \Claroline\CoreBundle\Event\LogCreateEvent $event
  */
 public function onLog(LogCreateEvent $event)
 {
     $log = $event->getLog();
     $action = $log->getAction();
     $user = $log->getReceiver();
     $group = $log->getReceiverGroup();
     $sessions = array('learner' => array(), 'tutor' => array());
     if ($action === 'group-add_user') {
         $multipleCursus = $this->cursusManager->getCursusByGroup($group);
         $this->cursusManager->registerUserToMultipleCursus($multipleCursus, $user);
         $sessionGroups = $this->cursusManager->getSessionGroupsByGroup($group);
         foreach ($sessionGroups as $sessionGroup) {
             $groupType = $sessionGroup->getGroupType();
             if ($groupType === 0) {
                 $sessions['learner'][] = $sessionGroup->getSession();
             } elseif ($groupType === 1) {
                 $sessions['tutor'][] = $sessionGroup->getSession();
             }
         }
         if (count($sessions['learner']) > 0) {
             $this->cursusManager->registerUsersToSessions($sessions['learner'], array($user), 0);
         }
         if (count($sessions['tutor']) > 0) {
             $this->cursusManager->registerUsersToSessions($sessions['tutor'], array($user), 1);
         }
     } elseif ($action === 'group-remove_user') {
         $multipleCursus = $this->cursusManager->getCursusByGroup($group);
         $cursusUsers = $this->cursusManager->getCursusUsersFromCursusAndUsers($multipleCursus, array($user));
         $this->cursusManager->deleteCursusUsers($cursusUsers);
         $sessionGroups = $this->cursusManager->getSessionGroupsByGroup($group);
         foreach ($sessionGroups as $sessionGroup) {
             $groupType = $sessionGroup->getGroupType();
             if ($groupType === 0) {
                 $sessions['learner'][] = $sessionGroup->getSession();
             } elseif ($groupType === 1) {
                 $sessions['tutor'][] = $sessionGroup->getSession();
             }
         }
         $sessionUsers = array();
         if (count($sessions['learner']) > 0) {
             $sessionUsers = $this->cursusManager->getSessionUsersBySessionsAndUsers($sessions['learner'], array($user), 0);
         }
         if (count($sessions['tutor']) > 0) {
             $sessionTutors = $this->cursusManager->getSessionUsersBySessionsAndUsers($sessions['tutor'], array($user), 1);
             $sessionUsers = array_merge($sessionUsers, $sessionTutors);
         }
         $this->cursusManager->deleteCourseSessionUsers($sessionUsers);
     }
 }
 /**
  * @DI\Observe("claroline.log.create")
  *
  * @param \Claroline\CoreBundle\Event\LogCreateEvent $event
  */
 public function onLog(LogCreateEvent $event)
 {
     $log = $event->getLog();
     $dateLog = $log->getDateLog();
     $action = $log->getAction();
     $resourceNode = $log->getResourceNode();
     $user = $log->getDoer();
     if (!is_null($user)) {
         $activityRules = is_null($resourceNode) ? $this->activityManager->getActivityRuleByActionWithNoResource($action) : $this->activityManager->getActivityRuleByActionAndResource($action, $resourceNode);
         if (count($activityRules) > 0) {
             foreach ($activityRules as $activityRule) {
                 $activityParams = $activityRule->getActivityParameters();
                 $accessFrom = $activityRule->getActiveFrom();
                 $accessUntil = $activityRule->getActiveUntil();
                 if ((is_null($accessFrom) || $dateLog >= $accessFrom) && (is_null($accessUntil) || $dateLog <= $accessUntil)) {
                     $nbRules = is_null($activityParams->getRules()) ? 0 : count($activityParams->getRules());
                     if ($nbRules > 0) {
                         $rules = $activityParams->getRules();
                         $ruleType = 'result';
                         foreach ($rules as $rule) {
                             if (is_null($rule->getResult())) {
                                 $ruleType = 'occurrence';
                                 break;
                             }
                         }
                         $rulesLogs = $this->ruleValidator->validate($activityParams, $user);
                         if (isset($rulesLogs['validRules']) && $rulesLogs['validRules'] >= $nbRules) {
                             $activityStatus = $ruleType === 'occurrence' ? AbstractEvaluation::STATUS_COMPLETED : AbstractEvaluation::STATUS_PASSED;
                         } else {
                             $activityStatus = $ruleType === 'occurrence' ? AbstractEvaluation::STATUS_INCOMPLETE : AbstractEvaluation::STATUS_FAILED;
                         }
                         $this->activityManager->manageEvaluation($user, $activityParams, $log, $rulesLogs, $activityStatus);
                     }
                 }
             }
         }
     }
 }