Browse Source

Allow show the badge list even when the badge not have course and/or session - refs BT#10856

Angel Fernando Quiroz Campos 8 years ago
parent
commit
d22bf7302f

+ 6 - 11
main/inc/lib/tracking.lib.php

@@ -5835,8 +5835,8 @@ class Tracking
     /**
      * Get the HTML code for show a block with the achieved user skill on course/session
      * @param int $userId
-     * @param int $courseId
-     * @param int $sessionId
+     * @param int $courseId Optional.
+     * @param int $sessionId Optional.
      * @return string
      */
     public static function displayUserSkills($userId, $courseId = 0, $sessionId = 0)
@@ -5851,13 +5851,8 @@ class Tracking
 
         $filter = ['user' => $userId];
 
-        if (!empty($courseId)) {
-            $filter['course'] = $courseId;
-        }
-
-        if (!empty($sessionId)) {
-            $filter['session'] = $sessionId;
-        }
+        $filter['course'] = $courseId ?: null;
+        $filter['session'] = $sessionId ?: null;
 
         $em = Database::getManager();
 
@@ -5883,11 +5878,11 @@ class Tracking
             ';
 
             foreach ($skillsRelUser as $userSkill) {
-                $skill = $em->find('ChamiloCoreBundle:Skill', $userSkill->getSkill()->getId());
+                $skill = $userSkill->getSkill();
 
                 $html .= '
                                             <li class="thumbnail">
-                                                <a href="' . api_get_path(WEB_PATH) . 'badge/' . $skill->getId() . '/user/' . $userId . '" target="_blank">
+                                                <a href="' . api_get_path(WEB_PATH) . 'badge/' . $userSkill->getId() . '/user/' . $userId . '" target="_blank">
                                                     <img class="img-responsive" title="' . $skill->getName() . '" src="' . $skill->getWebIconPath() . '" width="64" height="64">
                                                     <div class="caption">
                                                         <p class="text-center">' . $skill->getName() . '</p>

+ 6 - 2
main/mySpace/myStudents.php

@@ -1304,9 +1304,13 @@ if (!empty($student_id)) {
         </table>
         </div>
     <?php
-        echo Tracking::displayUserSkills($user_info['user_id'], $courseInfo['id'], $sessionId);
-
     } //end details
+
+    echo Tracking::displayUserSkills(
+        $user_info['user_id'],
+        $courseInfo ? $courseInfo['real_id'] : 0,
+        $sessionId
+    );
 }
 
 if ($export) {

+ 14 - 12
src/Chamilo/CoreBundle/Entity/Repository/SkillRepository.php

@@ -29,29 +29,31 @@ class SkillRepository extends EntityRepository
     {
         $qb = $this->createQueryBuilder('s');
 
-        $qb->innerJoin(
-            'ChamiloCoreBundle:SkillRelUser',
-            'su',
-            Join::WITH,
-            's.id = su.skill'
-        )
-        ->where(
-            $qb->expr()->eq('su.user', $user)
-        );
+        $qb
+            ->innerJoin(
+                'ChamiloCoreBundle:SkillRelUser',
+                'su',
+                Join::WITH,
+                's.id = su.skill'
+            )
+            ->where(
+                $qb->expr()->eq('su.user', $user->getId())
+            );
 
         if ($course) {
             $qb->andWhere(
-                $qb->expr()->eq('su.course', $course)
+                $qb->expr()->eq('su.course', $course->getId())
             );
         }
 
         if ($session) {
             $qb->andWhere(
-                $qb->expr()->eq('su.session', $session)
+                $qb->expr()->eq('su.session', $session->getId())
             );
         }
 
-        $qb->setMaxResults(1)
+        $qb
+            ->setMaxResults(1)
             ->orderBy('su.id', 'DESC');
 
         return $qb->getQuery()->getOneOrNullResult();