Browse Source

Fixing score column in the result page see BT#6397

Julio Montoya 11 years ago
parent
commit
1328bf8d3b

+ 28 - 3
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;
     }
 }

+ 4 - 2
main/template/minedu/tool/curriculum/category/results.tpl

@@ -18,10 +18,12 @@
             {% for user in pagination.currentPageResults %}
                 <tr>
                     <td>
-                        {{ user.firstname }} {{ user.lastname }}
+                        {{ user.completeName }}
                     </td>
                     <td>
-                        <div class="label label-success"> {{ user.score }}</div>
+                        <div class="label label-success">
+                            {{ user.getCurriculumScore }}
+                        </div>
                     </td>
 
                     <td>

+ 1 - 1
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')