فهرست منبع

Improve skill rendering see BT#13587

- Skill badge and skill title UI are now configured in one place.
- Add skill badge sizes mini, small and big.
- Skill images are now configured in one place skill->get()
- Improve skill table ordered by parents see BT#13587
Julio 7 سال پیش
والد
کامیت
4920086a06

+ 9 - 8
main/badge/issued.php

@@ -12,6 +12,7 @@ use Chamilo\CoreBundle\Entity\SkillRelUserComment;
 require_once __DIR__.'/../inc/global.inc.php';
 
 $issue = isset($_REQUEST['issue']) ? intval($_REQUEST['issue']) : 0;
+$userId = isset($_REQUEST['user']) ? intval($_REQUEST['user']) : 0;
 
 if (empty($issue)) {
     api_not_allowed(true);
@@ -24,9 +25,11 @@ $skillLevelRepo = $entityManager->getRepository('ChamiloSkillBundle:Level');
 
 if (!$skillIssue) {
     Display::addFlash(
-        Display::return_message(get_lang('TheUserXNotYetAchievedTheSkillX'), 'error')
+        Display::return_message(
+            get_lang('SkillNotFound'),
+            'warning'
+        )
     );
-
     header('Location: '.api_get_path(WEB_PATH));
     exit;
 }
@@ -36,7 +39,7 @@ $skill = $skillIssue->getSkill();
 
 if (!$user || !$skill) {
     Display::addFlash(
-        Display::return_message(get_lang('NoResults'), 'error')
+        Display::return_message(get_lang('NoResults'), 'warning')
     );
 
     header('Location: '.api_get_path(WEB_PATH));
@@ -215,12 +218,10 @@ if ($form->validate() && $allowComment) {
     exit;
 }
 
-$badgeInfoError = "";
-$personalBadge = "";
-
+$badgeInfoError = '';
+$personalBadge = '';
 if ($allowDownloadExport) {
     $backpack = 'https://backpack.openbadges.org/';
-
     $configBackpack = api_get_setting('openbadges_backpack');
 
     if (strcmp($backpack, $configBackpack) !== 0) {
@@ -261,7 +262,7 @@ if ($allowDownloadExport) {
         }
 
         if (!$badgeInfoError) {
-            $personalBadge = UserManager::getUserPathById($userId, "web");
+            $personalBadge = UserManager::getUserPathById($userId, 'web');
             $personalBadge = $personalBadge."badges/badge_".$skillRelUserId.".png";
         }
     }

+ 95 - 50
main/inc/lib/skill.lib.php

@@ -456,12 +456,12 @@ class SkillRelGradebook extends Model
      */
     public function updateBySkill($params)
     {
-        $skill_info = $this->existsGradeBookSkill(
+        $skillInfo = $this->existsGradeBookSkill(
             $params['gradebook_id'],
             $params['skill_id']
         );
 
-        if ($skill_info) {
+        if ($skillInfo) {
             return;
         } else {
             $result = $this->save($params);
@@ -607,7 +607,6 @@ class Skill extends Model
       9 => array('#3a5988', '#3a5988', '#3a5988', '#3a5988'),
      10 => array('#393e64', '#393e64', '#393e64', '#393e64'),
     );*/
-
     public function __construct()
     {
         $this->table = Database::get_main_table(TABLE_MAIN_SKILL);
@@ -629,24 +628,97 @@ class Skill extends Model
     public function get($id)
     {
         $result = parent::get($id);
-        $result['web_icon_path'] = api_get_path(WEB_UPLOAD_PATH).'badges/'.$result['icon'];
+        $path = api_get_path(WEB_UPLOAD_PATH).'badges/';
+
+        if (!empty($result['icon'])) {
+            $iconSmall = sprintf(
+                "%s-small.png",
+                sha1($result['name'])
+            );
+
+            $iconBig = sprintf(
+                "%s.png",
+                sha1($result['name'])
+            );
+
+            $iconMini = $path.$iconSmall;
+            $iconSmall = $path.$iconSmall;
+            $iconBig = $path.$iconBig;
+        } else {
+            $iconMini = Display::returnIconPath('badges-default.png', ICON_SIZE_MEDIUM);
+            $iconSmall = Display::returnIconPath('badges-default.png', ICON_SIZE_BIG);
+            $iconBig = Display::returnIconPath('badges-default.png', ICON_SIZE_HUGE);
+        }
+
+        $result['icon_big'] = $iconSmall;
+        $result['icon_small'] = $iconBig;
+        $result['icon_mini'] = $iconMini;
+
+        $result['img_mini'] = Display::img($iconBig, $result['name'], ['width' => ICON_SIZE_MEDIUM]);
+        $result['img_big'] = Display::img($iconBig, $result['name']);
+        $result['img_small'] = Display::img($iconSmall, $result['name']);
 
         return $result;
     }
 
+    /**
+     * @param array $skills
+     * @param string $imageSize mini|small|big
+     * @param bool $addDivWrapper
+     * @return string
+     */
+    public function processSkillList($skills, $imageSize = '', $addDivWrapper = true)
+    {
+        if (empty($skills)) {
+            return '';
+        }
+
+        if (empty($imageSize)) {
+            $imageSize = 'img_small';
+        } else {
+            $imageSize = "img_$imageSize";
+        }
+
+        $html = '';
+        if ($addDivWrapper) {
+            $html = '<div class="scrollbar-inner badges-sidebar">';
+        }
+        $html .= '<ul class="list-unstyled list-badges">';
+        foreach ($skills as $skill) {
+            $html .= '<li class="thumbnail">';
+            $item = $skill[$imageSize];
+            $item .= '<div class="caption">
+                        <p class="text-center">'.$skill['name'].'</p>
+                      </div>';
+            if (isset($skill['url'])) {
+                $html .= Display::url($item, $skill['url'], ['target' => '_blank']);
+            } else {
+                $html .= $item;
+            }
+            $html .= '</li>';
+        }
+        $html .= '</ul>';
+
+        if ($addDivWrapper) {
+            $html .= '</div>';
+        }
+
+        return $html;
+    }
+
     /**
      * @param int $id
      * @return array
      */
     public function getSkillInfo($id)
     {
-        $skill_rel_skill = new SkillRelSkill();
-        $skill_info = $this->get($id);
-        if (!empty($skill_info)) {
-            $skill_info['extra'] = $skill_rel_skill->getSkillInfo($id);
-            $skill_info['gradebooks'] = self::getGradebooksBySkill($id);
+        $skillRelSkill = new SkillRelSkill();
+        $skillInfo = $this->get($id);
+        if (!empty($skillInfo)) {
+            $skillInfo['extra'] = $skillRelSkill->getSkillInfo($id);
+            $skillInfo['gradebooks'] = self::getGradebooksBySkill($id);
         }
-        return $skill_info;
+        return $skillInfo;
     }
 
     /**
@@ -725,11 +797,10 @@ class Skill extends Model
         $webPath = api_get_path(WEB_UPLOAD_PATH);
         if (Database::num_rows($result)) {
             while ($row = Database::fetch_array($result, 'ASSOC')) {
-                $skill_rel_skill = new SkillRelSkill();
-                $parents = $skill_rel_skill->getSkillParents($row['id']);
+                $skillRelSkill = new SkillRelSkill();
+                $parents = $skillRelSkill->getSkillParents($row['id']);
                 $row['level'] = count($parents) - 1;
                 $row['gradebooks'] = self::getGradebooksBySkill($row['id']);
-                $row['web_icon_path'] = $webPath.'badges/'.$row['icon'];
                 $skills[$row['id']] = $row;
             }
         }
@@ -992,7 +1063,7 @@ class Skill extends Model
      *
      * @return array
      */
-    public function getUserSkills($userId, $get_skill_data = false)
+    public function getUserSkills($userId, $getSkillData = false)
     {
         $userId = intval($userId);
         $sql = 'SELECT DISTINCT 
@@ -1010,46 +1081,20 @@ class Skill extends Model
         $result = Database::query($sql);
         $skills = Database::store_result($result, 'ASSOC');
         $uploadPath = api_get_path(WEB_UPLOAD_PATH);
-        $clean_skill = array();
-        $defaultIcon = Display::returnIconPath('badges-default.png', ICON_SIZE_BIG);
-
+        $skillList = array();
         if (!empty($skills)) {
             foreach ($skills as $skill) {
-                if ($get_skill_data) {
-                    $iconThumb = null;
-                    $iconPath = null;
-                    if (!empty($skill['icon'])) {
-                        $iconThumb = sprintf(
-                            "badges/%s-small.png",
-                            sha1($skill['name'])
-                        );
-
-                        $iconPath = sprintf(
-                            "badges/%s.png",
-                            sha1($skill['name'])
-                        );
-                        $skill['icon_image'] = Display::img($uploadPath.$iconThumb, $skill['name']);
-                        $skill['icon'] = $uploadPath.$iconThumb;
-                    } else {
-                        $iconImage = Display::return_icon('badges-default.png', $skill['name'], null, ICON_SIZE_BIG);
-                        $skill['icon_image'] = $iconImage;
-                        $skill['icon'] = $defaultIcon;
-                    }
-
-                    $clean_skill[$skill['id']] = array_merge(
-                        $skill,
-                        array(
-                            'web_icon_thumb_path' => $uploadPath.$iconThumb,
-                            'web_icon_path' => $uploadPath.$iconPath
-                        )
-                    );
+                if ($getSkillData) {
+                    $skillData = $this->get($skill['id']);
+                    $skillData['url'] = api_get_path(WEB_PATH).'badge/'.$skill['issue'].'/user/'.$userId;
+                    $skillList[$skill['id']] = array_merge($skill, $skillData);
                 } else {
-                    $clean_skill[$skill['id']] = $skill['id'];
+                    $skillList[$skill['id']] = $skill['id'];
                 }
             }
         }
 
-        return $clean_skill;
+        return $skillList;
     }
 
     /**
@@ -1086,12 +1131,12 @@ class Skill extends Model
                         'name' => get_lang('Root'),
                         'parent_id' => '0'
                     );
-                    $skill_info = $this->getSkillInfo($skill_id);
+                    $skillInfo = $this->getSkillInfo($skill_id);
 
                     // 2nd node
-                    $skills[$skill_id] = $skill_info;
+                    $skills[$skill_id] = $skillInfo;
                     // Uncomment code below to hide the searched skill
-                    $skills[$skill_id]['data']['parent_id'] = $skill_info['extra']['parent_id'];
+                    $skills[$skill_id]['data']['parent_id'] = $skillInfo['extra']['parent_id'];
                     $skills[$skill_id]['parent_id'] = 1;
                 }
             }

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

@@ -2140,7 +2140,7 @@ class SocialManager extends UserManager
 
         $template = new Template(null, false, false, false, false, false);
         $template->assign('ranking', $ranking);
-        $template->assign('skills', $skills);
+        $template->assign('skills', $skill->processSkillList($skills));
         $template->assign('user_id', $userId);
         $template->assign(
             'show_skills_report_link',

+ 10 - 26
main/inc/lib/tracking.lib.php

@@ -6470,40 +6470,25 @@ class Tracking
         $em = Database::getManager();
         $skillsRelUser = $em->getRepository('ChamiloCoreBundle:SkillRelUser')->findBy($filter);
 
-        $html = '
-            <div class="table-responsive">
+        $html = '<div class="table-responsive">
                 <table class="table" id="skillList">
                     <thead>
                         <tr>
-                            <th>' . get_lang('AchievedSkills').'</th>
+                            <th>'.get_lang('AchievedSkills').'</th>
                         </tr>
                     </thead>
                     <tbody>
-                        <tr>
-                            <td>
-        ';
-
+                    <tr><td>';
+        $skillManager = new Skill();
         if (count($skillsRelUser)) {
-            $html .= '<div class="scrollbar-inner badges-sidebar">
-                        <ul class="list-unstyled list-badges">
-            ';
-
+            $skills = [];
             foreach ($skillsRelUser as $userSkill) {
-                $skill = $userSkill->getSkill();
-
-                $html .= '<li class="thumbnail">
-                            <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>
-                                </div>
-                            </a>
-                        </li>
-                ';
+                $skill = $skillManager->get($userSkill->getSkill()->getId());
+                $skill['url'] = api_get_path(WEB_PATH).'badge/'.$userSkill->getId().'/user/'.$userId;
+                $skills[] = $skill;
             }
+            $html .= $skillManager->processSkillList($skills);
 
-            $html .= '</ul></div>
-            ';
         } else {
             $html .= get_lang('WithoutAchievedSkills');
         }
@@ -6512,8 +6497,7 @@ class Tracking
                         </tr>
                     </tbody>
                 </table>
-            </div>
-        ';
+            </div>';
 
         return $html;
     }

+ 8 - 6
main/social/my_skills_report.php

@@ -58,7 +58,7 @@ if ($isStudent) {
         }
 
         $tableRow = array(
-            'skill_badge' => $resultData['icon_image'],
+            'skill_badge' => $resultData['img_mini'],
             'skill_name' => $resultData['name'],
             'achieved_at' => api_get_local_time($resultData['acquired_skill_at']),
             'course_image' => '',
@@ -72,8 +72,7 @@ if ($isStudent) {
         $tableRows[] = $tableRow;
     }
 
-    $table = new HTML_Table(['class' => 'table']);
-
+    $table = new HTML_Table(['class' => 'table table-bordered']);
     if (!empty($skillParents)) {
         $column = 0;
         $skillAdded = [];
@@ -84,7 +83,7 @@ if ($isStudent) {
             $parentInfo = $objSkill->getSkillInfo($parentId);
             $parentName = '';
             if ($data['passed']) {
-                $parentName = $parentInfo['name'];
+                $parentName = $objSkill->processSkillList([$parentInfo], 'mini', false);
             }
             $table->setHeaderContents(0, $column, $parentName);
             $row = 1;
@@ -93,13 +92,16 @@ if ($isStudent) {
                 if ($skillData['id'] == $parentId) {
                     continue;
                 }
+                if (empty($skillData['id'])) {
+                    continue;
+                }
                 $skillAdded[] = $skillData['id'];
-                $skillsToShow[] = $skillData['name'];
+                $skillsToShow[] = $skillData;
             }
             $table->setCellContents(
                 $row,
                 $column,
-                implode(' ', $skillsToShow)
+                $objSkill->processSkillList($skillsToShow, 'mini', false)
             );
             $row++;
             $column++;

+ 2 - 2
main/template/default/layout/layout_2_col.tpl

@@ -158,9 +158,9 @@
                                             <div class="badge_sidebar">
                                             {% for skill in badge.skills %}
                                                 {% if badge.finished %}
-                                                    <img class="badge_sidebar_image " src = "{{ skill.web_icon_path }}" />
+                                                    <img class="badge_sidebar_image " src ="{{ skill.icon_big }}" />
                                                 {% else %}
-                                                    <img class="badge_sidebar_image badge_sidebar_image_transparency" src = "{{ skill.web_icon_path }}" />
+                                                    <img class="badge_sidebar_image badge_sidebar_image_transparency" src = "{{ skill.icon_big }}" />
                                                 {% endif %}
                                                 <div class="badge_sidebar_title">
                                                 {{ skill.name }}

+ 2 - 2
main/template/default/skill/badge_create.tpl

@@ -734,7 +734,7 @@
                         </div>
                         <p class="openbadges-text">{{'BadgePreview' | get_lang }}</p>
                         <div class="openbadges-img {{ skill.icon ? '' : 'hide' }}" id="badge-container">
-                            <img id="badge-preview" class="img-responsive" alt="{{ 'BadgePreview' | get_lang }}" src="{{ skill.icon ? skill.web_icon_path : '' }}">
+                            <img id="badge-preview" class="img-responsive" alt="{{ 'BadgePreview' | get_lang }}" src="{{ skill.icon_big }}">
                         </div>
                     </div>
                 </div>
@@ -758,4 +758,4 @@
         });
 
     })
-</script>
+</script>

+ 1 - 1
main/template/default/skill/badge_list.tpl

@@ -33,7 +33,7 @@
                                     {% if skill.icon is empty %}
                                         <img src="{{ 'badges-default.png' | icon(128) }}" width="50" height="50" alt="{{ skill.name }}">
                                     {% else %}
-                                        <img src="{{ skill.web_icon_path }}" width="50" height="50" alt="{{ skill.name }}">
+                                        <img src="{{ skill.icon_big }}" width="50" height="50" alt="{{ skill.name }}">
                                     {% endif %}
 
                                     {{ skill.name }}

+ 1 - 1
main/template/default/skill/list.tpl

@@ -45,7 +45,7 @@
                         {% if skill.icon is empty %}
                             <img src="{{ 'badges-default.png' | icon(32) }}" width="32" height="32" alt="{{ skill.name }}">
                         {% else %}
-                            <img src="{{ skill.web_icon_path }}" width="32" height="32" alt="{{ skill.name }}">
+                            <img src="{{ skill.icon_small }}" width="32" height="32" alt="{{ skill.name }}">
                         {% endif %}
 
                     </td>

+ 5 - 7
main/template/default/skill/skill_wheel_student.tpl

@@ -170,21 +170,19 @@
                             <figcaption class="avatar-author">{{ user_info.complete_name }}</figcaption>
                         </figure>
                         <p class="text-center">
-                            <a href="{{ _p.web_main }}social/skills_ranking.php" class="btn btn-default" target="_blank">{{ 'YourSkillRankingX'|get_lang|format(ranking) }}</a>
+                            <a href="{{ _p.web_main }}social/skills_ranking.php" class="btn btn-default" target="_blank">
+                                {{ 'YourSkillRankingX'|get_lang|format(ranking) }}
+                            </a>
                         </p>
                         <div class="text-center">
                             {% if skills is not empty %}
                                 {% for skill in skills %}
-                                    {% if skill.icon is empty %}
-                                        <img src="{{ 'badges.png'|icon(32) }}" width="32" height="32" alt="{{ skill.name }}" title="{{ skill.name }}">
-                                    {% else %}
-                                        <img src="{{ skill.web_icon_thumb_path }}" width="32" height="32" alt="{{ skill.name }}" title="{{ skill.name }}">
-                                    {% endif %}
+                                    {{ skill.img_small }}
                                 {% endfor %}
                             {% endif %}
 
                             {% for i in 1..(5 - ranking) %}
-                                <img src="{{ 'badges-default.png'|icon(32) }}" width="32" height="32">
+                                <img src="{{ 'badges-default.png'|icon(64) }}" width="64" height="64">
                             {% endfor %}
                         </div>
                     </div>

+ 1 - 14
main/template/default/social/skills_block.tpl

@@ -33,20 +33,7 @@ jQuery(document).ready(function(){
         <div id="skillList" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
             <div class="panel-body">
                 {% if skills %}
-                    <div class="scrollbar-inner badges-sidebar">
-                        <ul class="list-unstyled list-badges">
-                            {% for skill in skills %}
-                                <li class="thumbnail">
-                                    <a href="{{ _p.web }}skill/{{ skill.id }}/user/{{ user_id }}" target="_blank">
-                                        <img title="{{ skill.name }}" class="img-responsive" src="{{ skill.icon }}" width="64" height="64" alt="{{ skill.name }}">
-                                        <div class="caption">
-                                            <p class="text-center">{{ skill.name }}</p>
-                                        </div>
-                                    </a>
-                                </li>
-                            {% endfor %}
-                        </ul>
-                    </div>
+                    {{ skills }}
                 {% else %}
                     <p>{{ 'WithoutAchievedSkills'|get_lang }}</p>
                     <p>