Exemplo n.º 1
0
 protected function persistEvaluation(Activity $activity, User $user, $status, Evaluation $previous = null, ActivityParameters $parameters = null)
 {
     $params = $parameters ? $parameters : ($previous ? $previous->getActivityParameters() : new ActivityParameters());
     $params->setActivity($activity);
     if ($previous) {
         $pastEval = new PastEvaluation();
         $pastEval->setActivityParameters($params);
         $pastEval->setUser($user);
         $pastEval->setStatus($previous->getStatus());
         $this->om->persist($pastEval);
     }
     $eval = $previous ?: new Evaluation();
     $eval->setActivityParameters($params);
     $eval->setUser($user);
     $eval->setStatus($status);
     $eval->setDate(new \DateTime());
     $this->om->persist($params);
     $this->om->persist($eval);
     return $eval;
 }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
0
 /**
  * @Route(
  *     "edit/activity/past/evaluation/{pastEvaluationId}",
  *     name="claro_activity_past_evaluation_edit",
  *     options={"expose"=true}
  * )
  * @ParamConverter("currentUser", options={"authenticatedUser" = true})
  * @ParamConverter(
  *      "pastEvaluation",
  *      class="ClarolineCoreBundle:Activity\PastEvaluation",
  *      options={"id" = "pastEvaluationId", "strictId" = true}
  * )
  * @Template()
  */
 public function editActivityPastEvaluationAction(User $currentUser, PastEvaluation $pastEvaluation)
 {
     $isWorkspaceManager = false;
     $activityParams = $pastEvaluation->getActivityParameters();
     $activity = $activityParams->getActivity();
     if (!is_null($activity)) {
         $workspace = $activity->getResourceNode()->getWorkspace();
         $roleNames = $currentUser->getRoles();
         $isWorkspaceManager = $this->isWorkspaceManager($workspace, $roleNames);
     }
     if (!$isWorkspaceManager) {
         throw new AccessDeniedException();
     }
     $form = $this->formFactory->create(new ActivityPastEvaluationType(), $pastEvaluation);
     $form->handleRequest($this->request);
     if ($form->isValid()) {
         $this->activityManager->editPastEvaluation($pastEvaluation);
         return new Response('success', 204);
     }
     return array('form' => $form->createView(), 'pastEvaluation' => $pastEvaluation);
 }