コード例 #1
0
 /**
  * Check if the solution of the Paper is available to User.
  *
  * @param Exercise $exercise
  * @param Paper    $paper
  *
  * @return bool
  */
 public function isSolutionAvailable(Exercise $exercise, Paper $paper)
 {
     $correctionMode = $exercise->getCorrectionMode();
     switch ($correctionMode) {
         case CorrectionMode::AFTER_END:
             $available = !empty($paper->getEnd());
             break;
         case CorrectionMode::AFTER_LAST_ATTEMPT:
             $available = 0 === $exercise->getMaxAttempts() || $paper->getNumPaper() === $exercise->getMaxAttempts();
             break;
         case CorrectionMode::AFTER_DATE:
             $now = new \DateTime();
             $available = empty($exercise->getDateCorrection()) || $now >= $exercise->getDateCorrection();
             break;
         case CorrectionMode::NEVER:
         default:
             $available = false;
             break;
     }
     return $available;
 }
コード例 #2
0
 /**
  * Export metadata of the Exercise in a JSON-encodable format.
  *
  * @param Exercise $exercise
  *
  * @return array
  */
 private function exportMetadata(Exercise $exercise)
 {
     $node = $exercise->getResourceNode();
     $creator = $node->getCreator();
     $authorName = sprintf('%s %s', $creator->getFirstName(), $creator->getLastName());
     // Accessibility dates
     $startDate = $node->getAccessibleFrom() ? $node->getAccessibleFrom()->format('Y-m-d\\TH:i:s') : null;
     $endDate = $node->getAccessibleUntil() ? $node->getAccessibleUntil()->format('Y-m-d\\TH:i:s') : null;
     $correctionDate = $exercise->getDateCorrection() ? $exercise->getDateCorrection()->format('Y-m-d\\TH:i:s') : null;
     return ['authors' => [['name' => $authorName]], 'created' => $node->getCreationDate()->format('Y-m-d\\TH:i:s'), 'title' => $node->getName(), 'description' => $exercise->getDescription(), 'type' => $exercise->getType(), 'pick' => $exercise->getPickSteps(), 'random' => $exercise->getShuffle(), 'keepSteps' => $exercise->getKeepSteps(), 'maxAttempts' => $exercise->getMaxAttempts(), 'lockAttempt' => $exercise->getLockAttempt(), 'dispButtonInterrupt' => $exercise->getDispButtonInterrupt(), 'metadataVisible' => $exercise->isMetadataVisible(), 'statistics' => $exercise->hasStatistics(), 'anonymous' => $exercise->getAnonymous(), 'duration' => $exercise->getDuration(), 'markMode' => $exercise->getMarkMode(), 'correctionMode' => $exercise->getCorrectionMode(), 'correctionDate' => $correctionDate, 'startDate' => $startDate, 'endDate' => $endDate, 'published' => $node->isPublished(), 'publishedOnce' => $exercise->wasPublishedOnce(), 'minimalCorrection' => $exercise->isMinimalCorrection()];
 }
コード例 #3
0
 /**
  * To control the max attemps, allow to know if an user can again execute an exercise
  *
  * @access public
  *
  * @param \UJM\ExoBundle\Entity\Exercise $exercise
  * @param \UJM\ExoBundle\Entity\User $user
  * @param boolean $exoAdmin
  *
  * @return boolean
  */
 public function controlMaxAttemps($exercise, $user, $exoAdmin)
 {
     if ($exoAdmin === false && $exercise->getMaxAttempts() > 0 && $exercise->getMaxAttempts() <= $this->getNbPaper($user->getId(), $exercise->getId(), true)) {
         return false;
     } else {
         return true;
     }
 }