plugin/exo/Manager/AttemptManager.php
public function startOrContinue(Exercise $exercise, User $user = null)
    {
        $paper = null; // The paper to use for the new attempt

        // If it's not an anonymous, load the previous unfinished papers
        $unfinishedPapers = (null !== $user) ? $this->paperRepository->findUnfinishedPapers($exercise, $user) : [];
        if (!empty($unfinishedPapers)) {
            if ($exercise->isInterruptible()) {
                // Continue a previous attempt
                $paper = $unfinishedPapers[0];
            } else {
                // Close the paper
                $this->end($unfinishedPapers[0], false);
            }
        }

        // Start a new attempt is needed
        if (empty($paper)) {
            // Get the last paper for generation
            $lastPaper = $this->getLastPaper($exercise, $user);

            // Generate a new paper
            $paper = $this->paperGenerator->create($exercise, $user, $lastPaper);

            // Save the new paper
            $this->om->persist($paper);
            $this->om->flush();
        }

        return $paper;
    }
public function startOrContinue(Exercise $exercise, User $user = null)
    {
        $paper = null; // The paper to use for the new attempt

        // If it's not an anonymous, load the previous unfinished papers
        $unfinishedPapers = (null !== $user) ? $this->paperRepository->findUnfinishedPapers($exercise, $user) : [];
        if (!empty($unfinishedPapers)) {
            if ($exercise->isInterruptible()) {
                // Continue a previous attempt
                $paper = $unfinishedPapers[0];
            } else {
                // Close the paper
                $this->end($unfinishedPapers[0], false);
            }
        }

        // Start a new attempt is needed
        if (empty($paper)) {
            // Get the last paper for generation
            $lastPaper = $this->getLastPaper($exercise, $user);

            // Generate a new paper
            $paper = $this->paperGenerator->create($exercise, $user, $lastPaper);

            // Save the new paper
            $this->om->persist($paper);
            $this->om->flush();
        }

        return $paper;
    }
public function startOrContinue ( Exercise $ exercise , User $ user = null ) { $ paper = null ; // The paper to use for the new attempt // If it's not an anonymous, load the previous unfinished papers $ unfinishedPapers = ( null !== $ user ) ? $ this -> paperRepository -> findUnfinishedPapers ( $ exercise , $ user ) : [ ] ; if ( ! empty ( $ unfinishedPapers ) ) { if ( $ exercise -> isInterruptible ( ) ) { // Continue a previous attempt $ paper = $ unfinishedPapers [ 0 ] ; } else { // Close the paper $ this -> end ( $ unfinishedPapers [ 0 ] , false ) ; } } // Start a new attempt is needed if ( empty ( $ paper ) ) { // Get the last paper for generation $ lastPaper = $ this -> getLastPaper ( $ exercise , $ user ) ; // Generate a new paper $ paper = $ this -> paperGenerator -> create ( $ exercise , $ user , $ lastPaper ) ; // Save the new paper $ this -> om -> persist ( $ paper ) ; $ this -> om -> flush ( ) ; } return $ paper ; }
Starts or continues an exercise paper.

Returns an unfinished paper if the user has one (and exercise allows continue)
or creates a new paper in the other cases.
Note : an anonymous user will never be able to continue a paper

@param Exercise $exercise - the exercise to play
@param User     $user     - the user who wants to play the exercise

@return Paper - a new paper or an unfinished one
Starts or continues an exercise paper .