Browse Source

Allow show issued skill one by one through skill_rel_user - refs #7901

Angel Fernando Quiroz Campos 9 years ago
parent
commit
dbb3d2c3cb

+ 1 - 1
.htaccess

@@ -39,4 +39,4 @@ RewriteRule ^courses/([^/]+)/course-pic.png$ app/courses/$1/course-pic.png [QSA,
 RewriteRule ^session/(\d{1,})/about/?$ main/session/about.php?session_id=$1 [L]
 
 # Issued badges friendly URL
-RewriteRule ^badge/(\d{1,})/user/(\d{1,}) main/badge/issued.php?skill=$1&user=$2 [L]
+RewriteRule ^badge/issue/(\d{1,})/user/(\d{1,})/? main/badge/issued.php?issue=$1&user=$2 [L]

+ 21 - 73
main/badge/issued.php

@@ -7,19 +7,15 @@
  */
 require_once '../inc/global.inc.php';
 
-$userId = isset($_GET['user']) ? intval($_GET['user']) : 0;
-$skillId = isset($_GET['skill']) ? intval($_GET['skill']) : 0;
-
-if (!isset($_GET['user'], $_GET['skill'])) {
+if (!isset($_GET['user'], $_GET['issue'])) {
     header('Location: ' . api_get_path(WEB_PATH));
     exit;
 }
 
 $entityManager = Database::getManager();
-$user = $entityManager->find('ChamiloUserBundle:User', $_GET['user']);
-$skill = $entityManager->find('ChamiloCoreBundle:Skill', $_GET['skill']);
+$skillIssue = $entityManager->find('ChamiloCoreBundle:SkillRelUser', $_GET['issue']);
 
-if (!$user || !$skill) {
+if (!$skillIssue) {
     Display::addFlash(
         Display::return_message(get_lang('NoResults'), 'error')
     );
@@ -28,75 +24,32 @@ if (!$user || !$skill) {
     exit;
 }
 
-$skillUserRepo = $entityManager->getRepository('ChamiloCoreBundle:SkillRelUser');
-$userSkills = $skillUserRepo->findBy([
-    'user' => $user->getId(),
-    'skill' => $skill->getId()
-]);
-
-if (!$userSkills) {
+if ($skillIssue->getUser()->getId() !== intval($_GET['user'])) {
     Display::addFlash(
-        Display::return_message(
-            sprintf(get_lang('TheUserXNotYetAchievedTheSkillX'), $user->getCompleteName(), $skill->getName()),
-            'error'
-        )
+        Display::return_message(get_lang('NoResults'), 'error')
     );
 
     header('Location: ' . api_get_path(WEB_PATH));
     exit;
 }
 
-$userInfo = [
-    'id' => $user->getId(),
-    'complete_name' => $user->getCompleteName()
-];
-
-$skillInfo = [
-    'id' => $skill->getId(),
-    'name' => $skill->getName(),
-    'short_code' => $skill->getShortCode(),
-    'description' => $skill->getDescription(),
-    'criteria' => $skill->getCriteria(),
-    'badge_image' => $skill->getWebIconPath(),
-    'courses' => []
+$skillIssueDate = api_get_local_time($skillIssue->getAcquiredSkillAt());
+
+$skillIssueInfo = [
+    'id' => $skillIssue->getId(),
+    'datetime' => api_format_date($skillIssueDate, DATE_TIME_FORMAT_SHORT),
+    'argumentation' => $skillIssue->getArgumentation(),
+    'source_name' => $skillIssue->getSourceName(),
+    'user_complete_name' => $skillIssue->getUser()->getCompleteName(),
+    'skill_badge_image' => $skillIssue->getSkill()->getWebIconPath(),
+    'skill_name' => $skillIssue->getSkill()->getName(),
+    'skill_short_code' => $skillIssue->getSkill()->getShortCode(),
+    'skill_description' => $skillIssue->getSkill()->getDescription(),
+    'skill_criteria' => $skillIssue->getSkill()->getCriteria(),
+    'badge_asserion' => [$skillIssue->getAssertionUrl()]
 ];
 
-$badgeAssertions = [];
-
-foreach ($userSkills as $userSkill) {
-    $sessionId = 0;
-    $course = $userSkill->getCourse();
-    $session = $userSkill->getSession();
-
-    $courseName = '';
-
-    if ($session) {
-        $courseName = "[{$session->getName()}] ";
-    }
-
-    if ($course) {
-        $courseName .= $course->getTitle();
-    }
-
-    $userSkillDate = api_get_local_time($userSkill->getAcquiredSkillAt());
-    $skillInfo['courses'][] = [
-        'name' => $courseName,
-        'date_issued' => api_format_date($userSkillDate, DATE_TIME_FORMAT_LONG),
-        'argumentation' => $userSkill->getArgumentation()
-    ];
-
-    $assertionUrl = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?";
-    $assertionUrl .= http_build_query(array(
-        'user' => $user->getId(),
-        'skill' => $skill->getId(),
-        'course' => $course ? $course->getId() : 0,
-        'session' => $session ? $session->getId() : 0
-    ));
-
-    $badgeAssertions[] = $assertionUrl;
-}
-
-$allowExport = api_get_user_id() == $user->getId();
+$allowExport = api_get_user_id() === $skillIssue->getUser()->getId();
 
 if ($allowExport) {
     $backpack = 'https://backpack.openbadges.org/';
@@ -111,14 +64,9 @@ if ($allowExport) {
 }
 
 $template = new Template('');
-$template->assign('skill_info', $skillInfo);
-$template->assign('user_info', $userInfo);
+$template->assign('issue_info', $skillIssueInfo);
 $template->assign('allow_export', $allowExport);
 
-if ($allowExport) {
-    $template->assign('assertions', $badgeAssertions);
-}
-
 $content = $template->fetch(
     $template->get_template('skill/issued.tpl')
 );

+ 27 - 12
main/inc/lib/social.lib.php

@@ -725,9 +725,9 @@ class SocialManager extends UserManager
             array('shared_profile', 'groups', 'group_edit', 'member_list', 'waiting_list', 'invite_friends')
         )) {
 
-            
+
             $links = '<ul class="nav nav-pills nav-stacked">';
-            
+
             $active = $show == 'home' ? 'active' : null;
             $links .= '
                 <li class="home-icon ' . $active . '">
@@ -793,7 +793,7 @@ class SocialManager extends UserManager
                     </a>
                 </li>';
             $links .='</ul>';
-            
+
             $html .= Display::panelCollapse(
                     get_lang('SocialNetwork'),
                     $links,
@@ -813,7 +813,7 @@ class SocialManager extends UserManager
         }
 
         if ($show == 'shared_profile') {
-            
+
             $links =  '<ul class="nav nav-pills nav-stacked">';
 
             // My own profile
@@ -1558,7 +1558,7 @@ class SocialManager extends UserManager
             $image = $domain . $image;
         }
         $title = $graph->title;
-        
+
         $html  = '<div class="thumbnail">';
         $html .= '<a target="_blank" href="'.$link.'"><h3>'.$title.'</h3>';
         $html .= empty($image) ? '' : '<img alt="" src="'.$image.'" /></a>';
@@ -1567,7 +1567,7 @@ class SocialManager extends UserManager
         $html .= '</div>';
         return $html;
     }
-    
+
     /**
      * verify if Url Exist - Using Curl
      * @param $URI url
@@ -1832,7 +1832,7 @@ class SocialManager extends UserManager
             api_get_path(WEB_CODE_PATH).'social/profile.php',
             null,
             array('enctype' => 'multipart/form-data') ,
-            FormValidator::LAYOUT_HORIZONTAL    
+            FormValidator::LAYOUT_HORIZONTAL
         );
 
         $form->addTextarea(
@@ -1881,15 +1881,30 @@ class SocialManager extends UserManager
             return null;
         }
 
-        $skill = new Skill();
+        $entityManager = Database::getManager();
+        $user = $entityManager->find('ChamiloUserBundle:User', $userId);
 
-        $ranking = $skill->get_user_skill_ranking($userId);
-        $skills = $skill->get_user_skills($userId, true);
+        if (!$user) {
+            return null;
+        }
+
+        $achievedSkills = $user->getAchievedSkills();
+        $ranking = $achievedSkills->count();
+        $skillsInfo = [];
+
+        foreach ($achievedSkills as $userSkill) {
+            $skillsInfo[] = [
+                'id' => $userSkill->getSkill()->getId(),
+                'name' => $userSkill->getSkill()->getName(),
+                'icon' => $userSkill->getSkill()->getWebIconPath(true),
+                'source_name' => $userSkill->getSourceName(),
+                'issue_url' => $userSkill->getIssueUrl()
+            ];
+        }
 
         $template = new Template(null, false, false, false, false, false);
         $template->assign('ranking', $ranking);
-        $template->assign('skills', $skills);
-        $template->assign('user_id', $userId);
+        $template->assign('skills', $skillsInfo);
         $template->assign(
             'show_skills_report_link',
             api_is_student() || api_is_student_boss() || api_is_drh()

+ 15 - 17
main/template/default/skill/issued.tpl

@@ -2,42 +2,40 @@
     <div class="col-md-5">
         <div class="thumbnail">
             <figure class="text-center">
-                <img class="img-responsive center-block" src="{{ skill_info.badge_image }}" alt="{{ skill_info.name }}">
+                <img class="img-responsive center-block" src="{{ issue_info.skill_badge_image }}" alt="{{ issue_info.skill_name }}">
                 <figcaption>
-                    <p class="lead">{{ skill_info.name }}</p>
-                    {% if skill_info.short_code %}
-                        <p>{{ skill_info.short_code }}</p>
+                    <p class="lead">{{ issue_info.skill_name }}</p>
+                    {% if issue_info.skill_short_code %}
+                        <p>{{ issue_info.skill_short_code }}</p>
                     {% endif %}
                 </figcaption>
             </figure>
             <div class="caption">
-                {% if skill_info.description %}
-                    <p>{{ skill_info.description }}</p>
+                {% if issue_info.skill_description %}
+                    <p>{{ issue_info.skill_description }}</p>
                 {% endif %}
-                {% if skill_info.criteria %}
+                {% if issue_info.skill_criteria %}
                     <h3>{{ 'CriteriaToEarnTheBadge'|get_lang }}</h3>
-                    <p>{{ skill_info.criteria }}</p>
+                    <p>{{ issue_info.skill_criteria }}</p>
                 {% endif %}
             </div>
         </div>
     </div>
     <div class="col-md-7">
         <h3>{{ 'RecipientDetails'|get_lang }}</h3>
-        <p class="lead">{{ user_info.complete_name }}</p>
+        <p class="lead">{{ issue_info.user_complete_name }}</p>
         <h4>{{ 'SkillAcquiredAt'|get_lang }}</h4>
         <ul class="fa-ul">
-        {% for course in skill_info.courses %}
             <li>
-                {% if course.name %}
-                    <em class="fa-li fa fa-clock-o fa-fw"></em> {{ 'TimeXThroughCourseY'|get_lang|format(course.date_issued, course.name) }}
+                {% if issue_info.source_name %}
+                    <em class="fa-li fa fa-clock-o fa-fw"></em> {{ 'TimeXThroughCourseY'|get_lang|format(issue_info.datetime, issue_info.source_name) }}
                 {% else %}
-                    <em class="fa-li fa fa-clock-o fa-fw"></em> {{ course.date_issued }}
+                    <em class="fa-li fa fa-clock-o fa-fw"></em> {{ issue_info.datetime }}
                 {% endif %}
-                {% if course.argumentation %}
-                    <p>{{ course.argumentation }}</p>
+                {% if issue_info.argumentation %}
+                    <p>{{ issue_info.argumentation }}</p>
                 {% endif %}
             </li>
-        {% endfor %}
         </ul>
         <hr>
         {% if allow_export %}
@@ -55,7 +53,7 @@
             $('#badge-export-button').on('click', function (e) {
                 e.preventDefault();
 
-                OpenBadges.issue({{ assertions|json_encode() }});
+                OpenBadges.issue({{ issue_info.badge_asserion|json_encode() }});
             });
         });
     </script>

+ 15 - 9
main/template/default/social/skills_block.tpl

@@ -29,18 +29,24 @@
         <div id="skillList" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
             <div class="panel-body">
                 {% if skills %}
-                    <ul class="list-unstyled list-badges">
+                    <figure class="list-badges">
                         {% for skill in skills %}
-                            <li class="thumbnail">
-                                <a href="{{ _p.web }}badge/{{ skill.id }}/user/{{ user_id }}" target="_blank">
-                                    <img title="{{ skill.name }}" class="img-responsive" src="{{ skill.icon ? skill.web_icon_thumb_path : 'badges-default.png'|icon(64) }}" width="64" height="64" alt="{{ skill.name }}">
-                                    <div class="caption">
-                                        <p class="text-center">{{ skill.name }}</p>
-                                    </div>
+                            <figure class="thumbnail">
+                                <a href="{{ skill.issue_url }}" target="_blank">
+                                    <img title="{{ skill.name }}" class="img-responsive" src="{{ skill.icon }}" width="64" height="64" alt="{{ skill.name }}">
                                 </a>
-                            </li>
+                                <figcaption class="caption text-center">
+                                    <a href="{{ skill.issue_url }}" target="_blank">
+                                        {{ skill.name }}
+                                        {% if skill.source_name %}
+                                            <br>
+                                            <small>{{ skill.source_name }}</small>
+                                        {% endif %}
+                                    </a>
+                                </figcaption>
+                            </figure>
                         {% endfor %}
-                    </ul>
+                    </figure>
                 {% else %}
                     <p>{{ 'WithoutAchievedSkills'|get_lang }}</p>
                     <p>

+ 46 - 0
src/Chamilo/CoreBundle/Entity/SkillRelUser.php

@@ -233,4 +233,50 @@ class SkillRelUser
     {
         return $this->argumentation;
     }
+
+    /**
+     * Get the source which the skill was obtained
+     * @return string
+     */
+    public function getSourceName()
+    {
+        $source = '';
+
+        if ($this->session) {
+            $source .= "[{$this->session->getName()}] ";
+        }
+
+        if ($this->course) {
+            $source .= $this->course->getTitle();
+        }
+
+        return $source;
+    }
+
+    /**
+     * Get the URL for the issue
+     * @return string
+     */
+    public function getIssueUrl()
+    {
+        return api_get_path(WEB_PATH) . "badge/issue/{$this->id}/user/{$this->user->getId()}/";
+    }
+
+    /**
+     * Get the URL for the assertion
+     * @return string
+     */
+    public function getAssertionUrl()
+    {
+        $url = api_get_path(WEB_CODE_PATH) . "badge/assertion.php?";
+
+        $url .= http_build_query(array(
+            'user' => $this->user->getId(),
+            'skill' => $this->skill->getId(),
+            'course' => $this->course ? $this->course->getId() : 0,
+            'session' => $this->session ? $this->session->getId() : 0
+        ));
+
+        return $url;
+    }
 }