plugin/exo/Listener/Resource/ExerciseListener.php
public function onLoad(LoadResourceEvent $event)
    {
        /** @var Exercise $exercise */
        $exercise = $event->getResource();
        $currentUser = $this->tokenStorage->getToken()->getUser();

        $canEdit = $this->authorization->isGranted('EDIT', new ResourceCollection([$exercise->getResourceNode()]));

        $options = [];
        if ($canEdit || $exercise->hasStatistics()) {
            $options[] = Transfer::INCLUDE_SOLUTIONS;
        }

        // fetch additional user data
        $nbUserPapers = 0;
        $nbUserPapersDayCount = 0;
        $userEvaluation = null;
        if ($currentUser instanceof User) {
            $nbUserPapers = (int) $this->paperManager->countUserFinishedPapers($exercise, $currentUser);
            $nbUserPapersDayCount = (int) $this->paperManager->countUserFinishedDayPapers($exercise, $currentUser);
            $userEvaluation = $this->serializer->serialize(
                $this->resourceEvalManager->getResourceUserEvaluation($exercise->getResourceNode(), $currentUser)
            );
        }

        $event->setData([
            'quiz' => $this->serializer->serialize($exercise, $options),
            'paperCount' => (int) $this->paperManager->countExercisePapers($exercise),

            // user data
            'userPaperCount' => $nbUserPapers,
            'userPaperDayCount' => $nbUserPapersDayCount,
            'userEvaluation' => $userEvaluation,
        ]);
        $event->stopPropagation();
    }
public function onLoad(LoadResourceEvent $event)
    {
        /** @var Exercise $exercise */
        $exercise = $event->getResource();
        $currentUser = $this->tokenStorage->getToken()->getUser();

        $canEdit = $this->authorization->isGranted('EDIT', new ResourceCollection([$exercise->getResourceNode()]));

        $options = [];
        if ($canEdit || $exercise->hasStatistics()) {
            $options[] = Transfer::INCLUDE_SOLUTIONS;
        }

        // fetch additional user data
        $nbUserPapers = 0;
        $nbUserPapersDayCount = 0;
        $userEvaluation = null;
        if ($currentUser instanceof User) {
            $nbUserPapers = (int) $this->paperManager->countUserFinishedPapers($exercise, $currentUser);
            $nbUserPapersDayCount = (int) $this->paperManager->countUserFinishedDayPapers($exercise, $currentUser);
            $userEvaluation = $this->serializer->serialize(
                $this->resourceEvalManager->getResourceUserEvaluation($exercise->getResourceNode(), $currentUser)
            );
        }

        $event->setData([
            'quiz' => $this->serializer->serialize($exercise, $options),
            'paperCount' => (int) $this->paperManager->countExercisePapers($exercise),

            // user data
            'userPaperCount' => $nbUserPapers,
            'userPaperDayCount' => $nbUserPapersDayCount,
            'userEvaluation' => $userEvaluation,
        ]);
        $event->stopPropagation();
    }
public function onLoad ( LoadResourceEvent $ event ) { /** @var Exercise $exercise */ $ exercise = $ event -> getResource ( ) ; $ currentUser = $ this -> tokenStorage -> getToken ( ) -> getUser ( ) ; $ canEdit = $ this -> authorization -> isGranted ( 'EDIT' , new ResourceCollection ( [ $ exercise -> getResourceNode ( ) ] ) ) ; $ options = [ ] ; if ( $ canEdit || $ exercise -> hasStatistics ( ) ) { $ options [ ] = Transfer :: INCLUDE_SOLUTIONS ; } // fetch additional user data $ nbUserPapers = 0 ; $ nbUserPapersDayCount = 0 ; $ userEvaluation = null ; if ( $ currentUser instanceof User ) { $ nbUserPapers = ( int ) $ this -> paperManager -> countUserFinishedPapers ( $ exercise , $ currentUser ) ; $ nbUserPapersDayCount = ( int ) $ this -> paperManager -> countUserFinishedDayPapers ( $ exercise , $ currentUser ) ; $ userEvaluation = $ this -> serializer -> serialize ( $ this -> resourceEvalManager -> getResourceUserEvaluation ( $ exercise -> getResourceNode ( ) , $ currentUser ) ) ; } $ event -> setData ( [ 'quiz' => $ this -> serializer -> serialize ( $ exercise , $ options ) , 'paperCount' => ( int ) $ this -> paperManager -> countExercisePapers ( $ exercise ) , // user data 'userPaperCount' => $ nbUserPapers , 'userPaperDayCount' => $ nbUserPapersDayCount , 'userEvaluation' => $ userEvaluation , ] ) ; $ event -> stopPropagation ( ) ; }
Loads the Exercise resource.

@DI\Observe("resource.ujm_exercise.load")

@param LoadResourceEvent $event
Loads the Exercise resource .