diff --git a/main/inc/Entity/User.php b/main/inc/Entity/User.php index 8219cfb8c7..9e86038d8a 100644 --- a/main/inc/Entity/User.php +++ b/main/inc/Entity/User.php @@ -1166,11 +1166,36 @@ class User implements AdvancedUserInterface, \Serializable , EquatableInterface public function getCurriculumScore() { $items = $this->getCurriculumItems(); - $score = 0; + $scorePerCategory = array(); + $maxPerCategory = array(); + /** @var \Entity\CurriculumItemRelUser $itemRelUser */ foreach ($items as $itemRelUser) { - $score += $itemRelUser->getItem()->getScore(); + + $parentId = $itemRelUser->getItem()->getCategory()->getParent()->getId(); + + if (!isset($scorePerCategory[$parentId])) { + $scorePerCategory[$parentId] = 0; + } + + $scorePerCategory[$parentId] += $itemRelUser->getItem()->getScore(); + + if (!isset($scorePerCategory[$parentId])) { + $maxPerCategory[$parentId] = 0; + } + + $maxPerCategory[$parentId] = + $itemRelUser->getItem()->getCategory()->getParent()->getMaxScore(); + } + + $finalScore = 0; + foreach ($scorePerCategory as $categoryId => $scoreInCategory) { + if ($scoreInCategory >= $maxPerCategory[$categoryId]) { + $finalScore += $maxPerCategory[$categoryId]; + } else { + $finalScore += $scoreInCategory; + } } - return $score ; + return $finalScore; } } diff --git a/main/template/minedu/tool/curriculum/category/results.tpl b/main/template/minedu/tool/curriculum/category/results.tpl index 6560e69d73..cf0f428e54 100644 --- a/main/template/minedu/tool/curriculum/category/results.tpl +++ b/main/template/minedu/tool/curriculum/category/results.tpl @@ -18,10 +18,12 @@ {% for user in pagination.currentPageResults %} - {{ user.firstname }} {{ user.lastname }} + {{ user.completeName }} -
{{ user.score }}
+
+ {{ user.getCurriculumScore }} +
diff --git a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php index 670feab5f5..7f99f3a223 100644 --- a/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php +++ b/src/ChamiloLMS/Controller/Tool/Curriculum/CurriculumCategoryController.php @@ -361,7 +361,7 @@ class CurriculumCategoryController extends CommonController $qb = $this->getManager() ->createQueryBuilder() - ->select('u, u.firstname, u.lastname, u.userId, SUM(i.score) as score') + ->select('u') ->from('Entity\User', 'u') ->innerJoin('u.curriculumItems', 'ci') ->innerJoin('ci.item', 'i')