Ejemplo n.º 1
0
 /**
  * @EXT\Route(
  *     "/view_details/{logId}",
  *           name="claro_log_view_details",
  *           options={"expose"=true}
  * )
  * @EXT\ParamConverter(
  *      "log",
  *           class="ClarolineCoreBundle:Log\Log",
  *           options={"id" = "logId", "strictId" = true}
  * )
  *
  * Displays the public profile of an user.
  *
  * @param \Claroline\CoreBundle\Entity\Log\Log $log
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function viewDetailsAction(Log $log)
 {
     $eventLogName = 'create_log_details_' . $log->getAction();
     if ($this->eventDispatcher->hasListeners($eventLogName)) {
         $event = $this->eventDispatcher->dispatch($eventLogName, new LogCreateDelegateViewEvent($log));
         return new Response($event->getResponseContent());
     }
     return $this->render('ClarolineCoreBundle:Log:view_details.html.twig', array('log' => $log));
 }
Ejemplo n.º 2
0
 public function testValidateNoLogWrongBadge()
 {
     $badge = new Badge();
     $badge->setId(rand(PHP_INT_MAX / 2 + 1, PHP_INT_MAX));
     $rule = new BadgeRule();
     $rule->setBadge($badge);
     $log = new Log();
     $log->setDetails(array('badge' => array('id' => rand(0, PHP_INT_MAX / 2))));
     $badgeConstraint = new BadgeConstraint();
     $badgeConstraint->setRule($rule)->setAssociatedLogs(array($log));
     $this->assertFalse($badgeConstraint->validate());
 }
Ejemplo n.º 3
0
 /**
  * @param string $action
  * @param bool   $executeQuery
  *
  * @return array|\Doctrine\ORM\AbstractQuery
  */
 public function findBadgeAutomaticallyAwardedFromAction(Log $log, $executeQuery = true)
 {
     $actiontype = $log->getAction();
     if ($log->getResourceType()) {
         $actiontype = '[[' . $log->getResourceType()->getName() . ']]' . $log->getAction();
     }
     $query = $this->getEntityManager()->createQuery('SELECT b
             FROM IcapBadgeBundle:Badge b
             JOIN b.badgeRules br
             WHERE (br.action = :action
             OR br.action = :action2)
             AND b.automaticAward = true')->setParameter('action', $log->getAction())->setParameter('action2', $actiontype);
     return $executeQuery ? $query->getResult() : $query;
 }
Ejemplo n.º 4
0
 private function createLog(LogGenericEvent $event)
 {
     //Add doer details
     $doer = null;
     $doerIp = null;
     $doerSessionId = null;
     $doerType = null;
     //Event can override the doer
     if ($event->getDoer() === null) {
         $token = $this->tokenStorage->getToken();
         if ($token === null) {
             $doer = null;
             $doerType = Log::doerTypePlatform;
         } else {
             if ($token->getUser() === 'anon.') {
                 $doer = null;
                 $doerType = Log::doerTypeAnonymous;
             } else {
                 $doer = $token->getUser();
                 $doerType = Log::doerTypeUser;
             }
             if ($this->container->isScopeActive('request')) {
                 $request = $this->container->get('request');
                 $doerSessionId = $request->getSession()->getId();
                 $doerIp = $request->getClientIp();
             } else {
                 $doerIp = 'CLI';
             }
         }
     } elseif (LogGenericEvent::PLATFORM_EVENT_TYPE === $event->getDoer()) {
         $doer = null;
         $doerType = Log::doerTypePlatform;
     } else {
         $doer = $event->getDoer();
         $doerType = Log::doerTypeUser;
     }
     $log = new Log();
     //Simple type properties
     $log->setAction($event->getAction())->setToolName($event->getToolName())->setIsDisplayedInAdmin($event->getIsDisplayedInAdmin())->setIsDisplayedInWorkspace($event->getIsDisplayedInWorkspace())->setOtherElementId($event->getOtherElementId());
     //Object properties
     $log->setOwner($event->getOwner());
     if (!($event->getAction() === LogUserDeleteEvent::ACTION && $event->getReceiver() === $doer)) {
         //Prevent self delete case
         //Sometimes, the entity manager has been cleared, so we must merge the doer.
         if ($doer) {
             $doer = $this->om->merge($doer);
         }
         $log->setDoer($doer);
     }
     $log->setDoerType($doerType);
     $log->setDoerIp($doerIp);
     $log->setDoerSessionId($doerSessionId);
     if ($event->getAction() !== LogUserDeleteEvent::ACTION) {
         //Prevent user delete case
         $log->setReceiver($event->getReceiver());
     }
     if ($event->getAction() !== LogGroupDeleteEvent::ACTION) {
         if ($receiverGroup = $event->getReceiverGroup()) {
             $this->om->merge($receiverGroup);
         }
         $log->setReceiverGroup($receiverGroup);
     }
     if (!($event->getAction() === LogResourceDeleteEvent::ACTION && $event->getResource() === $event->getWorkspace())) {
         //Prevent delete workspace case
         $log->setWorkspace($event->getWorkspace());
     }
     if ($event->getAction() !== LogResourceDeleteEvent::ACTION) {
         //Prevent delete resource case
         $log->setResourceNode($event->getResource());
     }
     if ($event->getAction() !== LogWorkspaceRoleDeleteEvent::ACTION) {
         //Prevent delete role case
         $log->setRole($event->getRole());
     }
     if ($doer !== null) {
         $platformRoles = $this->roleManager->getPlatformRoles($doer);
         foreach ($platformRoles as $platformRole) {
             $log->addDoerPlatformRole($platformRole);
         }
         if ($event->getWorkspace() !== null) {
             $workspaceRoles = $this->roleManager->getWorkspaceRolesForUser($doer, $event->getWorkspace());
             foreach ($workspaceRoles as $workspaceRole) {
                 $log->addDoerWorkspaceRole($workspaceRole);
             }
         }
     }
     if ($event->getResource() !== null) {
         $log->setResourceType($event->getResource()->getResourceType());
     }
     //Json_array properties
     $details = $event->getDetails();
     if ($details === null) {
         $details = array();
     }
     if ($doer !== null) {
         $details['doer'] = array('firstName' => $doer->getFirstName(), 'lastName' => $doer->getLastName(), 'publicUrl' => $doer->getPublicUrl());
         if (count($log->getDoerPlatformRoles()) > 0) {
             $doerPlatformRolesDetails = array();
             foreach ($log->getDoerPlatformRoles() as $platformRole) {
                 $doerPlatformRolesDetails[] = $platformRole->getTranslationKey();
             }
             $details['doer']['platformRoles'] = $doerPlatformRolesDetails;
         }
         if (count($log->getDoerWorkspaceRoles()) > 0) {
             $doerWorkspaceRolesDetails = array();
             foreach ($log->getDoerWorkspaceRoles() as $workspaceRole) {
                 $doerWorkspaceRolesDetails[] = $workspaceRole->getTranslationKey();
             }
             $details['doer']['workspaceRoles'] = $doerWorkspaceRolesDetails;
         }
     }
     $log->setDetails($details);
     $this->om->persist($log);
     $this->om->flush();
     $createLogEvent = new LogCreateEvent($log);
     $this->container->get('event_dispatcher')->dispatch(LogCreateEvent::NAME, $createLogEvent);
 }
Ejemplo n.º 5
0
 protected static function createLog(User $doer, $action, Workspace $workspace = null)
 {
     $log = new Log();
     $log->setDoer($doer);
     $log->setAction($action);
     $log->setDoerType(Log::doerTypeUser);
     $log->setDateLog(self::$time);
     if ($workspace) {
         $log->setWorkspace($workspace);
     }
     self::$om->persist($log);
     self::$om->flush();
 }
Ejemplo n.º 6
0
 public function doerProvider()
 {
     $log = new Log();
     $action = uniqid();
     $user = new User();
     $rule = new BadgeRule();
     $rule->setAction($action)->setUser($user)->setUserType(0);
     $badge = new Badge();
     $rule2 = new BadgeRule();
     $rule2->setAction($action)->setUser($user)->setUserType(0)->setBadge($badge);
     $log2 = new Log();
     $log2->setDetails(array('badge' => array('id' => $badge->getId())));
     $badge2 = new Badge();
     $badge2->setId(rand(PHP_INT_MAX / 2 + 1, PHP_INT_MAX));
     $rule3 = new BadgeRule();
     $rule3->setAction($action)->setUser($user)->setUserType(0)->setBadge($badge2);
     $log3 = new Log();
     $log3->setDetails(array('badge' => array('id' => rand(0, PHP_INT_MAX / 2))));
     $rule4 = new BadgeRule();
     $rule4->setAction($action)->setUser($user)->setUserType(0)->setResult(rand(0, PHP_INT_MAX))->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_EQUAL));
     $result = rand(0, PHP_INT_MAX);
     $log4 = new Log();
     $log4->setDetails(array('result' => $result));
     $rule5 = new BadgeRule();
     $rule5->setAction($action)->setUser($user)->setUserType(0)->setResult($result - 1)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_EQUAL));
     $rule6 = new BadgeRule();
     $rule6->setAction($action)->setUser($user)->setUserType(0)->setResult($result)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_EQUAL));
     $log5 = new Log();
     $log5->setDetails(array('result' => 12));
     $rule7 = new BadgeRule();
     $rule7->setAction($action)->setUser($user)->setUserType(0)->setResult(9)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_SUPERIOR));
     $rule8 = new BadgeRule();
     $rule8->setAction($action)->setUser($user)->setUserType(0)->setResult(42)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_SUPERIOR));
     $rule9 = new BadgeRule();
     $rule9->setAction($action)->setUser($user)->setUserType(0)->setResult(12)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_SUPERIOR));
     $rule10 = new BadgeRule();
     $rule10->setAction($action)->setUser($user)->setUserType(0)->setResult(9)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_SUPERIOR_EQUAL));
     $rule11 = new BadgeRule();
     $rule11->setAction($action)->setUser($user)->setUserType(0)->setResult(12)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_SUPERIOR_EQUAL));
     $log6 = new Log();
     $log6->setDetails(array('result' => 9));
     $rule12 = new BadgeRule();
     $rule12->setAction($action)->setUser($user)->setUserType(0)->setResult(12)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_SUPERIOR_EQUAL));
     $rule13 = new BadgeRule();
     $rule13->setAction($action)->setUser($user)->setUserType(0)->setResult(12)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_INFERIOR));
     $log7 = new Log();
     $log7->setDetails(array('result' => 42));
     $rule14 = new BadgeRule();
     $rule14->setAction($action)->setUser($user)->setUserType(0)->setResult(12)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_INFERIOR_EQUAL));
     $rule15 = new BadgeRule();
     $rule15->setAction($action)->setUser($user)->setUserType(0)->setResult(12)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_SUPERIOR_EQUAL));
     $rule16 = new BadgeRule();
     $rule16->setAction($action)->setUser($user)->setUserType(0)->setResult(9)->setResultComparison(Rule::getResultComparisonTypeValue(Rule::RESULT_INFERIOR_EQUAL));
     return array(array($user, $action, $rule, array(), false), array($user, $action, $rule, array($log), array($log)), array($user, $action, $rule2, array($log2), array($log2)), array($user, $action, $rule2, array(), false), array($user, $action, $rule3, array($log3), false), array($user, $action, $rule4, array(), false), array($user, $action, $rule5, array($log4), false), array($user, $action, $rule6, array($log4), array($log4)), array($user, $action, $rule7, array($log5), array($log5)), array($user, $action, $rule8, array($log5), false), array($user, $action, $rule9, array($log5), false), array($user, $action, $rule10, array($log5), array($log5)), array($user, $action, $rule11, array($log5), array($log5)), array($user, $action, $rule12, array($log6), false), array($user, $action, $rule13, array($log6), array($log6)), array($user, $action, $rule13, array($log7), false), array($user, $action, $rule13, array($log5), false), array($user, $action, $rule14, array($log6), array($log6)), array($user, $action, $rule15, array($log5), array($log5)), array($user, $action, $rule16, array($log5), false));
 }
Ejemplo n.º 7
0
 public function manageEvaluation(User $user, ActivityParameters $activityParams, Log $currentLog, $rulesLogs, $activityStatus)
 {
     $evaluation = $this->evaluationRepo->findEvaluationByUserAndActivityParams($user, $activityParams);
     $isFirstEvaluation = is_null($evaluation);
     $evaluationType = $activityParams->getEvaluationType();
     $ruleScore = null;
     $ruleScoreMax = null;
     if ($evaluationType === AbstractEvaluation::TYPE_AUTOMATIC && count($activityParams->getRules()) > 0) {
         $rule = $activityParams->getRules()->first();
         $ruleScore = $rule->getResult();
         $ruleScoreMax = $rule->getResultMax();
     }
     if (!$isFirstEvaluation) {
         $pastEvals = $this->pastEvaluationRepo->findPastEvaluationsByUserAndActivityParams($user, $activityParams);
     }
     $nbAttempts = $isFirstEvaluation ? 0 : count($pastEvals);
     $totalTime = $isFirstEvaluation ? null : $evaluation->getAttemptsDuration();
     $pastStatus = $activityStatus === AbstractEvaluation::STATUS_INCOMPLETE || $activityStatus === AbstractEvaluation::STATUS_FAILED ? $activityStatus : AbstractEvaluation::STATUS_UNKNOWN;
     $previousStatus = $evaluation ? $evaluation->getStatus() : AbstractEvaluation::STATUS_UNKNOWN;
     if (isset($rulesLogs['rules']) && is_array($rulesLogs['rules'])) {
         foreach ($rulesLogs['rules'] as $ruleLogs) {
             $logs = $ruleLogs['logs'];
             foreach ($logs as $log) {
                 $pastEvalExisted = false;
                 // Checks if this archived log is the same as the log
                 // that triggers the evaluation
                 if ($log->getId() === $currentLog->getId()) {
                     break;
                 }
                 // Checks if the log is already associated to an existing
                 // PastEvaluation
                 if (!$isFirstEvaluation) {
                     foreach ($pastEvals as $pastEval) {
                         if (!is_null($pastEval->getLog()) && $pastEval->getLog()->getId() === $log->getId()) {
                             $pastEvalExisted = true;
                             break;
                         }
                     }
                 }
                 // If the log isn't associated to an existing PastEvaluation
                 if (!$pastEvalExisted) {
                     $logDetails = $log->getDetails();
                     $duration = isset($logDetails['duration']) ? $logDetails['duration'] : null;
                     $score = isset($logDetails['result']) ? $logDetails['result'] : null;
                     $scoreMin = isset($logDetails['resultMin']) ? $logDetails['resultMin'] : null;
                     $scoreMax = isset($logDetails['resultMax']) ? $logDetails['resultMax'] : null;
                     $pastEval = new PastEvaluation();
                     $pastEval->setUser($user);
                     $pastEval->setActivityParameters($activityParams);
                     $pastEval->setLog($log);
                     $pastEval->setType($evaluationType);
                     $pastEval->setDate($log->getDateLog());
                     $pastEval->setNumScore($score);
                     $pastEval->setScoreMin($scoreMin);
                     $pastEval->setScoreMax($scoreMax);
                     $pastEval->setDuration($duration);
                     $pastEval->setStatus($pastStatus);
                     ++$nbAttempts;
                     $totalTime = $this->computeActivityTotalTime($totalTime, $duration);
                     $this->om->persist($pastEval);
                 }
             }
         }
     }
     // Creates a PastEvaluation for the log that triggers the evaluation
     $logDetails = $currentLog->getDetails();
     $duration = isset($logDetails['duration']) ? $logDetails['duration'] : null;
     $score = isset($logDetails['result']) ? $logDetails['result'] : null;
     $scoreMin = isset($logDetails['resultMin']) ? $logDetails['resultMin'] : null;
     $scoreMax = isset($logDetails['resultMax']) ? $logDetails['resultMax'] : null;
     $pastEval = new PastEvaluation();
     $pastEval->setUser($user);
     $pastEval->setActivityParameters($activityParams);
     $pastEval->setLog($currentLog);
     $pastEval->setType($evaluationType);
     $pastEval->setDate($currentLog->getDateLog());
     $pastEval->setNumScore($score);
     $pastEval->setScoreMin($scoreMin);
     $pastEval->setScoreMax($scoreMax);
     $pastEval->setDuration($duration);
     if (($activityStatus === AbstractEvaluation::STATUS_COMPLETED || $activityStatus === AbstractEvaluation::STATUS_PASSED) && !is_null($score) && !is_null($ruleScore)) {
         $realStatus = $this->hasPassingScore($ruleScore, $ruleScoreMax, $score, $scoreMax) ? $activityStatus : AbstractEvaluation::STATUS_FAILED;
         $pastEval->setStatus($realStatus);
     } else {
         $pastEval->setStatus($activityStatus);
     }
     ++$nbAttempts;
     $totalTime = $this->computeActivityTotalTime($totalTime, $duration);
     $this->om->persist($pastEval);
     if ($isFirstEvaluation) {
         $evaluation = new Evaluation();
         $evaluation->setUser($user);
         $evaluation->setActivityParameters($activityParams);
         $evaluation->setType($evaluationType);
         $evaluation->setNumScore($score);
         $evaluation->setScoreMin($scoreMin);
         $evaluation->setScoreMax($scoreMax);
     } else {
         $this->persistBestScore($evaluation, $score, $scoreMin, $scoreMax);
     }
     $evaluation->setDate($currentLog->getDateLog());
     $evaluation->setAttemptsCount($nbAttempts);
     $evaluation->setAttemptsDuration($totalTime);
     $evaluation->setStatus($activityStatus);
     $evaluation->setLog($currentLog);
     $this->om->persist($evaluation);
     $this->om->flush();
     if ($activityStatus !== $previousStatus && $evaluation->isTerminated()) {
         $this->dispatchEvaluation($evaluation);
     }
 }
Ejemplo n.º 8
0
 public function testValidateTwoRightOneWrongLogLogResultSuperiorEqual()
 {
     $result = rand(0, PHP_INT_MAX / 2);
     $badgeRule = new BadgeRule();
     $badgeRule->setOccurrence(1)->setResult($result)->setResultComparison(4);
     $log = new Log();
     $log->setDetails(array('result' => $result + rand(0, PHP_INT_MAX / 2)));
     $log2 = new Log();
     $log2->setDetails(array('result' => $result - 1));
     $log3 = new Log();
     $log3->setDetails(array('result' => $result + rand(0, PHP_INT_MAX / 2)));
     $associatedLogs = array($log, $log2, $log3);
     $resultConstraint = new ResultConstraint();
     $resultConstraint->setRule($badgeRule)->setAssociatedLogs($associatedLogs);
     $this->assertTrue($resultConstraint->validate());
 }