Browse Source

Merge pull request #740 from AngelFQC/BT9885

Improve User Portal page - refs BT#9885 #TMI
Angel Fernando Quiroz Campos 9 years ago
parent
commit
3ff2254db3

+ 6 - 7
main/inc/lib/course.lib.php

@@ -1881,7 +1881,9 @@ class CourseManager
 
         if (Database::num_rows($rs) > 0) {
             while ($row = Database::fetch_array($rs)) {
-                $coaches[] = $row;
+                $completeName = api_get_person_name($row['firstname'], $row['lastname']);
+
+                $coaches[] = $row + ['full_name' => $completeName];
             }
 
             return $coaches;
@@ -3814,13 +3816,10 @@ class CourseManager
                 self::USER_SEPARATOR,
                 true
             );
-            $course_coachs = CourseManager::get_coachs_from_course_to_string(
+            $course_coachs = self::get_coachs_from_course(
                 $course_info['id_session'],
-                $course_info['real_id'],
-                self::USER_SEPARATOR,
-                true
+                $course_info['real_id']
             );
-            $icon_coachs = Display::return_icon('teacher.png', '', null, ICON_SIZE_TINY);
 
             if ($course_info['status'] == COURSEMANAGER ||
                 ($course_info['status'] == STUDENT && empty($course_info['id_session'])) ||
@@ -3832,7 +3831,7 @@ class CourseManager
             if (($course_info['status'] == STUDENT && !empty($course_info['id_session'])) ||
                 ($is_coach && $course_info['status'] != COURSEMANAGER)
             ) {
-                $params['coaches'] = $icon_coachs.$course_coachs;
+                $params['coaches'] = $course_coachs;
             }
         }
 

+ 72 - 0
main/inc/lib/sessionmanager.lib.php

@@ -6956,4 +6956,76 @@ class SessionManager
         }
         return $array1;
     }
+
+    /**
+     * Get the number of stars achieved in a session when gamification mode is activated
+     * @param int $sessionId The session id
+     * @return int The count
+     */
+    static function getNumberOfStarsFromGamification($sessionId)
+    {
+        $totalStars = 0;
+        $userId = api_get_user_id();
+        $courses = SessionManager::get_course_list_by_session_id($sessionId);
+
+        if (empty($courses)) {
+            return 0;
+        }
+
+        foreach ($courses as $course) {
+            $learnPathListObject = new LearnpathList($userId, $course['code'], $sessionId);
+            $learnPaths = $learnPathListObject->get_flat_list();
+
+            $stars = 0;
+
+            foreach ($learnPaths as $learnPathId => $learnPathInfo) {
+                if (empty($learnPathInfo['seriousgame_mode'])) {
+                    continue;
+                }
+
+                $learnPath = new learnpath($course['code'], $learnPathId, $userId);
+
+                $stars += $learnPath->getCalculateStars();
+            }
+
+            $totalStars += $stars;
+        }
+
+        return $totalStars / count($courses);
+    }
+
+    /**
+     * Get the calculated progress for a session when gamification mode is activated
+     * @param int $sessionId The session id
+     * @return int The progress
+     */
+    public static function getProgressFromGamification($sessionId)
+    {
+        $courses = SessionManager::get_course_list_by_session_id($sessionId);
+        $progress = 0;
+
+        if (empty($courses)) {
+            return 0;
+        }
+
+        foreach ($courses as $course) {
+            $courseProgress = Tracking::get_avg_student_progress(
+                api_get_user_id(),
+                $course['code'],
+                [],
+                $sessionId,
+                false,
+                true
+            );
+
+            if ($courseProgress === false) {
+                continue;
+            }
+
+            $progress += $courseProgress;
+        }
+
+        return $progress / count($courses);
+    }
+
 }

+ 3 - 1
main/install/data.sql

@@ -759,6 +759,8 @@ INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, v
 INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable) VALUES (2, 10, 'tags', 'Tags', 1, 1);
 INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable) VALUES (2, 19, 'video_url', 'VideoUrl', 1, 1);
 
+INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable) VALUES (3, 16, 'image', 'Image', 1, 1);
+
 INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES (8, '1', 'AtOnce',1);
 INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES (8, '8', 'Daily',2);
 INSERT INTO extra_field_options (field_id, option_value, display_text, option_order) VALUES (8, '0', 'No',3);
@@ -1786,4 +1788,4 @@ VALUES
 ('gamification_mode', '1', 'Yes'),
 ('gamification_mode', '0', 'No');
 
-UPDATE settings_current SET selected_value = '1.10.0.41' WHERE variable = 'chamilo_database_version';
+UPDATE settings_current SET selected_value = '1.10.0.42' WHERE variable = 'chamilo_database_version';

+ 1 - 1
main/install/database.sql

@@ -4603,5 +4603,5 @@ CREATE TABLE c_attendance_calendar_rel_group (
 
 -- Version
 LOCK TABLES settings_current WRITE;
-UPDATE settings_current SET selected_value = '1.10.0.41' WHERE variable = 'chamilo_database_version';
+UPDATE settings_current SET selected_value = '1.10.0.42' WHERE variable = 'chamilo_database_version';
 UNLOCK TABLES;

+ 12 - 1
main/template/default/user_portal/session.tpl

@@ -80,7 +80,18 @@
                                 </div>
                                 <div class="col-md-10">
                                     {{ item.title }}
-                                    {{ item.coaches }}
+
+                                    {% if item.coaches|length > 0 %}
+                                        <img src="{{ 'teacher.png'|icon(16) }}">
+
+                                        {% for coach in item.coaches %}
+                                            {{ loop.index > 1 ? ' | ' }}
+
+                                            <a href="{{ _p.web_ajax ~ 'user_manager.ajax.php?' ~ {'a': 'get_user_popup', 'user_id': coach.user_id}|url_encode() }}" class="ajax">
+                                                {{ coach.full_name }}
+                                            </a>
+                                        {% endfor %}
+                                    {% endif %}
                                 </div>
                             </div>
                         {% endfor %}

+ 35 - 0
src/Chamilo/CoreBundle/Migrations/Schema/V110/Version20150624164100.php

@@ -0,0 +1,35 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+namespace Chamilo\CoreBundle\Migrations\Schema\V110;
+
+use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
+use Doctrine\DBAL\Schema\Schema;
+
+/**
+ * Session date changes
+ */
+class Version20150624164100 extends AbstractMigrationChamilo
+{
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $this->addSql("INSERT INTO extra_field
+            (extra_field_type, field_type, variable, display_text, visible, changeable)
+            VALUES (3, 16, 'image', 'Image', 1, 1)");
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+        $this->addSql("DELETE FROM extra_field
+            WHERE variable = 'image' AND
+                extra_field_type = 3 AND
+                field_type = 16");
+    }
+
+}