Bläddra i källkod

Unify user skills UI see BT#13587

- UI depends of setting: "skill_levels_names"
Julio 7 år sedan
förälder
incheckning
25775b61a5

+ 136 - 3
main/inc/lib/skill.lib.php

@@ -1063,9 +1063,22 @@ class Skill extends Model
      *
      * @return array
      */
-    public function getUserSkills($userId, $getSkillData = false)
+    public function getUserSkills($userId, $getSkillData = false, $courseId = 0, $sessionId = 0)
     {
-        $userId = intval($userId);
+        $userId = (int) $userId;
+        $courseId = (int) $courseId;
+        $sessionId = (int) $sessionId;
+
+        $courseCondition = '';
+        if (!empty($courseId)) {
+            $courseCondition = " AND course_id = $courseId ";
+        }
+
+        $sessionCondition = '';
+        if (!empty($sessionId)) {
+            $sessionCondition = " AND course_id = $sessionId ";
+        }
+
         $sql = 'SELECT DISTINCT 
                     s.id, 
                     s.name,
@@ -1076,7 +1089,8 @@ class Skill extends Model
                 FROM '.$this->table_skill_rel_user.' u
                 INNER JOIN '.$this->table.' s
                 ON u.skill_id = s.id
-                WHERE user_id = '.$userId;
+                WHERE 
+                    user_id = '.$userId.' '.$sessionCondition.' '.$courseCondition;
 
         $result = Database::query($sql);
         $skills = Database::store_result($result, 'ASSOC');
@@ -1097,6 +1111,125 @@ class Skill extends Model
         return $skillList;
     }
 
+    /**
+     * @param int $userId
+     * @param int $courseId
+     * @param int $sessionId
+     *
+     * @return string
+     */
+    public function getUserSkillsTable($userId, $courseId = 0, $sessionId = 0)
+    {
+        $skills = $this->getUserSkills($userId, true, $courseId, $sessionId);
+
+        $courseTempList = [];
+        $skillParents = [];
+        $tableRows = [];
+        foreach ($skills as $resultData) {
+            $parents = $this->get_parents($resultData['id']);
+            foreach ($parents as $parentData) {
+                if ($parentData['id'] == 1 || $parentData['parent_id'] == 1) {
+                    continue;
+                }
+                $skillParents[$parentData['id']]['passed'] = in_array($parentData['id'], array_keys($skills));
+                $skillParents[$parentData['id']][] = $resultData;
+            }
+
+            $courseId = $resultData['course_id'];
+            if (!empty($courseId)) {
+                if (isset($courseTempList[$courseId])) {
+                    $courseInfo = $courseTempList[$courseId];
+                } else {
+                    $courseInfo = api_get_course_info_by_id($courseId);
+                    $courseTempList[$courseId] = $courseInfo;
+                }
+            }
+
+            $tableRow = array(
+                'skill_badge' => $resultData['img_mini'],
+                'skill_name' => $resultData['name'],
+                'achieved_at' => api_get_local_time($resultData['acquired_skill_at']),
+                'course_image' => '',
+                'course_name' => ''
+            );
+
+            if (!empty($courseInfo)) {
+                $tableRow['course_image'] = $courseInfo['course_image_source'];
+                $tableRow['course_name'] = $courseInfo['title'];
+            }
+            $tableRows[] = $tableRow;
+        }
+
+        $allowLevels = api_get_configuration_value('skill_levels_names');
+
+        $tableResult = '<div class="table-responsive">
+                <table class="table" id="skillList">
+                    <thead>
+                        <tr>
+                            <th>'.get_lang('AchievedSkills').'</th>
+                        </tr>
+                    </thead>
+                    <tbody>
+                    <tr><td>';
+        //$allowLevels = [];
+        if (!empty($skillParents)) {
+            if (empty($allowLevels)) {
+                $tableResult .= $this->processSkillList($skills);
+            } else {
+                $table = new HTML_Table(['class' => 'table table-bordered']);
+                if (!empty($skillParents)) {
+                    $column = 0;
+                    $skillAdded = [];
+                    foreach ($skillParents as $parentId => $data) {
+                        if (in_array($parentId, $skillAdded)) {
+                            continue;
+                        }
+                        $parentName = '';
+                        if ($data['passed']) {
+                            $parentInfo = $skills[$parentId];
+                            $parentName = $this->processSkillList([$parentInfo], 'mini', false);
+                        }
+                        $table->setHeaderContents(0, $column, $parentName);
+                        $row = 1;
+                        $skillsToShow = [];
+                        foreach ($data as $skillData) {
+                            if ($skillData['id'] == $parentId) {
+                                continue;
+                            }
+                            if (empty($skillData['id'])) {
+                                continue;
+                            }
+                            $skillAdded[] = $skillData['id'];
+                            $skillsToShow[] = $skillData;
+                        }
+                        $table->setCellContents(
+                            $row,
+                            $column,
+                            $this->processSkillList($skillsToShow, 'mini', false)
+                        );
+                        $row++;
+                        $column++;
+                    }
+                }
+                $tableResult .= $table->toHtml();
+            }
+        } else {
+            $tableResult .= get_lang('WithoutAchievedSkills');
+        }
+
+        $tableResult .= '</td>
+                        </tr>
+                    </tbody>
+                </table>
+            </div>';
+
+
+        return [
+            'skills' => $tableRows,
+            'table' => $tableResult
+        ];
+    }
+
     /**
      * @param int $user_id
      * @param int $skill_id

+ 2 - 2
main/inc/lib/social.lib.php

@@ -2136,11 +2136,11 @@ class SocialManager extends UserManager
 
         $skill = new Skill();
         $ranking = $skill->getUserSkillRanking($userId);
-        $skills = $skill->getUserSkills($userId, true);
+        //$skills = $skill->getUserSkills($userId, true);
 
         $template = new Template(null, false, false, false, false, false);
         $template->assign('ranking', $ranking);
-        $template->assign('skills', $skill->processSkillList($skills));
+        $template->assign('skills', $skill->getUserSkillsTable($userId)['table']);
         $template->assign('user_id', $userId);
         $template->assign(
             'show_skills_report_link',

+ 1 - 41
main/inc/lib/tracking.lib.php

@@ -5284,7 +5284,6 @@ class Tracking
             if (!empty($exercise_list)) {
                 $score = $weighting = $exe_id = 0;
                 foreach ($exercise_list as $exercices) {
-
                     $exercise_obj = new Exercise($course_info['real_id']);
                     $exercise_obj->read($exercices['id']);
                     $visible_return = $exercise_obj->is_visible();
@@ -6458,47 +6457,8 @@ class Tracking
         if (Skill::isAllow($userId, false) === false) {
             return '';
         }
-
-        $userId = intval($userId);
-        $courseId = intval($courseId);
-        $sessionId = intval($sessionId);
-
-        $filter = ['user' => $userId];
-        $filter['course'] = $courseId ?: null;
-        $filter['session'] = $sessionId ?: null;
-
-        $em = Database::getManager();
-        $skillsRelUser = $em->getRepository('ChamiloCoreBundle:SkillRelUser')->findBy($filter);
-
-        $html = '<div class="table-responsive">
-                <table class="table" id="skillList">
-                    <thead>
-                        <tr>
-                            <th>'.get_lang('AchievedSkills').'</th>
-                        </tr>
-                    </thead>
-                    <tbody>
-                    <tr><td>';
         $skillManager = new Skill();
-        if (count($skillsRelUser)) {
-            $skills = [];
-            foreach ($skillsRelUser as $userSkill) {
-                $skill = $skillManager->get($userSkill->getSkill()->getId());
-                $skill['url'] = api_get_path(WEB_PATH).'badge/'.$userSkill->getId().'/user/'.$userId;
-                $skills[] = $skill;
-            }
-            $html .= $skillManager->processSkillList($skills);
-
-        } else {
-            $html .= get_lang('WithoutAchievedSkills');
-        }
-
-        $html .= '</td>
-                        </tr>
-                    </tbody>
-                </table>
-            </div>';
-
+        $html = $skillManager->getUserSkillsTable($userId, $courseId, $sessionId)['table'];
         return $html;
     }
 

+ 0 - 1
main/mySpace/myStudents.php

@@ -1588,7 +1588,6 @@ if (empty($details)) {
     </div>
 <?php
 } //end details
-
 echo Tracking::displayUserSkills(
     $user_info['user_id'],
     $courseInfo ? $courseInfo['real_id'] : 0,

+ 3 - 75
main/social/my_skills_report.php

@@ -33,81 +33,9 @@ $tpl->assign('allow_skill_tool', api_get_setting('allow_skills_tool') === 'true'
 $tpl->assign('allow_drh_skills_management', api_get_setting('allow_hr_skills_management') === 'true');
 
 if ($isStudent) {
-    $skills = $objSkill->getUserSkills($userId, true);
-    $courseTempList = [];
-    $skillParents = [];
-    foreach ($skills as $resultData) {
-        $parents = $objSkill->get_parents($resultData['id']);
-
-        foreach ($parents as $parentData) {
-            if ($parentData['id'] == 1 || $parentData['parent_id'] == 1) {
-                continue;
-            }
-            $skillParents[$parentData['id']]['passed'] = in_array($parentData['id'], array_keys($skills));
-            $skillParents[$parentData['id']][] = $resultData;
-        }
-
-        $courseId = $resultData['course_id'];
-        if (!empty($courseId)) {
-            if (isset($courseTempList[$courseId])) {
-                $courseInfo = $courseTempList[$courseId];
-            } else {
-                $courseInfo = api_get_course_info_by_id($courseId);
-                $courseTempList[$courseId] = $courseInfo;
-            }
-        }
-
-        $tableRow = array(
-            'skill_badge' => $resultData['img_mini'],
-            'skill_name' => $resultData['name'],
-            'achieved_at' => api_get_local_time($resultData['acquired_skill_at']),
-            'course_image' => '',
-            'course_name' => ''
-        );
-
-        if (!empty($courseInfo)) {
-            $tableRow['course_image'] = $courseInfo['course_image_source'];
-            $tableRow['course_name'] = $courseInfo['title'];
-        }
-        $tableRows[] = $tableRow;
-    }
-
-    $table = new HTML_Table(['class' => 'table table-bordered']);
-    if (!empty($skillParents)) {
-        $column = 0;
-        $skillAdded = [];
-        foreach ($skillParents as $parentId => $data) {
-            if (in_array($parentId, $skillAdded)) {
-                continue;
-            }
-            $parentInfo = $objSkill->getSkillInfo($parentId);
-            $parentName = '';
-            if ($data['passed']) {
-                $parentName = $objSkill->processSkillList([$parentInfo], 'mini', false);
-            }
-            $table->setHeaderContents(0, $column, $parentName);
-            $row = 1;
-            $skillsToShow = [];
-            foreach ($data as $skillData) {
-                if ($skillData['id'] == $parentId) {
-                    continue;
-                }
-                if (empty($skillData['id'])) {
-                    continue;
-                }
-                $skillAdded[] = $skillData['id'];
-                $skillsToShow[] = $skillData;
-            }
-            $table->setCellContents(
-                $row,
-                $column,
-                $objSkill->processSkillList($skillsToShow, 'mini', false)
-            );
-            $row++;
-            $column++;
-        }
-    }
-    $tpl->assign('skill_table', $table->toHtml());
+    $result = $objSkill->getUserSkillsTable($userId);
+    $tableRows = $result['skills'];
+    $tpl->assign('skill_table', $result['table']);
     $tplPath = 'skill/student_report.tpl';
 } elseif ($isStudentBoss) {
     $selectedStudent = isset($_REQUEST['student']) ? intval($_REQUEST['student']) : 0;

+ 3 - 1
main/template/default/skill/student_report.tpl

@@ -32,7 +32,9 @@
         </tbody>
     </table>
 
-    {{ skill_table }}
+    {% if skill_table %}
+        {{ skill_table }}
+    {% endif %}
 {% else %}
     <div class="alert alert-info">
         {{ 'NoResults' | get_lang }}