Skip to content

Commit

Permalink
[Path] uses overview resource in evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Feb 21, 2023
1 parent 80d8a12 commit c039540
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 24 deletions.
11 changes: 11 additions & 0 deletions src/plugin/path/Manager/EvaluationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,17 @@ public function compute(Path $path, User $user): ResourceEvaluation
// the path evaluation aggregates the progression/score of all its required/evaluated resource
// and the status of the steps which don't contain any resource.
$aggregator = new EvaluationAggregator();

if (!empty($path->getOverviewResource()) && $path->getOverviewResource()->isRequired()) {
$resourceEvaluation = $this->resourceEvalManager->getUserEvaluation($path->getOverviewResource(), $user, false);
if (!$resourceEvaluation) {
// no evaluation, adds an empty evaluation for correct progression check
$resourceEvaluation = new GenericEvaluation(0);
}

$aggregator->addEvaluation($resourceEvaluation, $path->getOverviewResource()->isEvaluated());
}

foreach ($path->getSteps() as $step) {
if (!empty($step->getResource()) && $step->getResource()->isRequired()) {
// the step contains a required resource, we need to get the evaluation for this resource
Expand Down
30 changes: 6 additions & 24 deletions src/plugin/path/Repository/PathRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class PathRepository extends EntityRepository
{
/**
* Find all the Path using the $resourceNode as a primary resource of a Step.
* Find all the Path using the $resourceNode as an overview resource or a primary resource of a Step.
*
* @return Path[]
*/
Expand All @@ -23,34 +23,15 @@ public function findByPrimaryResource(ResourceNode $resourceNode)
FROM Innova\PathBundle\Entity\Path\Path AS p
LEFT JOIN Innova\PathBundle\Entity\Step AS s WITH (s.path = p)
LEFT JOIN s.resource AS n
WHERE s.resource = :resourceNode
WHERE s.resource = :resourceNode
OR p.overviewResource = :resourceNode
')
->setParameter('resourceNode', $resourceNode)
->getResult();
}

/**
* Find all the required resources embedded in a Path as a primary resource of a Step.
* NB. This is used by the evaluation system of the Path, other embedded resources are not needed in this case.
*
* @return ResourceNode[]
*/
public function findRequiredResources(Path $path)
{
return $this->getEntityManager()
->createQuery('
SELECT n
FROM Claroline\CoreBundle\Entity\Resource\ResourceNode AS n
LEFT JOIN Innova\PathBundle\Entity\Step AS s WITH (s.resource = n)
WHERE n.required = 1
AND s.path = :pathResource
')
->setParameter('pathResource', $path)
->getResult();
}

/**
* Find user evaluations for the required resources embedded in a Path as a primary resource of a Step.
* Find user evaluations for the required resources embedded in a Path as an overview resource or a primary resource of a Step.
* NB. This is used by the evaluation system of the Path, other embedded resources are not needed in this case.
*
* @return ResourceUserEvaluation[]
Expand All @@ -63,9 +44,10 @@ public function findRequiredEvaluations(Path $path, User $user)
FROM Claroline\CoreBundle\Entity\Resource\ResourceUserEvaluation AS e
LEFT JOIN e.resourceNode AS n
LEFT JOIN Innova\PathBundle\Entity\Step AS s WITH (s.resource = n)
LEFT JOIN Innova\PathBundle\Entity\Path\Path AS p WITH (p.overviewResource = n)
WHERE n.required = 1
AND s.path = :pathResource
AND e.user = :user
AND (s.path = :pathResource OR p = :pathResource)
')
->setParameter('pathResource', $path)
->setParameter('user', $user)
Expand Down

0 comments on commit c039540

Please sign in to comment.