Kaynağa Gözat

Show only one table in works in session report - refs BT#11031

Angel Fernando Quiroz Campos 8 yıl önce
ebeveyn
işleme
90b8e7fcc2
2 değiştirilmiş dosya ile 91 ekleme ve 49 silme
  1. 62 45
      main/mySpace/works.php
  2. 29 4
      main/template/default/my_space/works.tpl

+ 62 - 45
main/mySpace/works.php

@@ -7,6 +7,11 @@
 
 require_once '../inc/global.inc.php';
 
+use \Chamilo\CoreBundle\Entity\Session;
+use \Doctrine\Common\Collections\Criteria;
+
+api_block_anonymous_users(true);
+
 if (api_is_student()) {
     api_not_allowed(true);
     exit;
@@ -15,7 +20,6 @@ if (api_is_student()) {
 $em = Database::getManager();
 $session = null;
 $sessionsInfo = SessionManager::getSessionsFollowedByUser(api_get_user_id(), COURSEMANAGER);
-$coursesData = [];
 
 $form = new FormValidator('work_report');
 $selectSession = $form->addSelect('session', get_lang('Session'), [0 => get_lang('None')]);
@@ -30,60 +34,69 @@ if ($form->validate()) {
     $session = $em->find('ChamiloCoreBundle:Session', $sessionId);
 }
 
+$coursesInfo = [];
+$usersInfo = [];
+
 if ($session) {
-    $userSubscriptions = $session->getUsers();
     $sessionCourses = $session->getCourses();
 
     foreach ($sessionCourses as $sessionCourse) {
         $course = $sessionCourse->getCourse();
-        $userCourseSubscriptions = $session->getUserCourseSubscriptionsByStatus($course, 0);
-        $courseInfo = [
-            'title' => $course->getTitle()
-        ];
-
-        $table = new HTML_Table(['class' => 'table table-hover table-striped']);
-        $table->setHeaderContents(0, 0, get_lang('OfficialCode'));
-        $table->setHeaderContents(0, 1, get_lang('StudentName'));
-        $table->setHeaderContents(0, 2, get_lang('TimeSpentOnThePlatform'));
-        $table->setHeaderContents(0, 3, get_lang('FirstLoginInPlatform'));
-        $table->setHeaderContents(0, 4, get_lang('LatestLoginInPlatform'));
-        $table->setHeaderContents(0, 5, get_lang('Course'));
-        $table->setHeaderContents(0, 6, get_lang('Progress'));
-        $table->setHeaderContents(0, 7, get_lang('SentDate'));
+        $coursesInfo[$course->getId()] =  $course->getCode();
+        $criteria = Criteria::create()->where(
+            Criteria::expr()->eq("status", Session::STUDENT)
+        );
+        $userCourseSubscriptions = $session
+            ->getUserCourseSubscriptions()
+            ->matching($criteria);
 
         foreach ($userCourseSubscriptions as $userCourseSubscription) {
             $user = $userCourseSubscription->getUser();
-            
+
+            if (!array_key_exists($user->getId(), $usersInfo)) {
+                $usersInfo[$user->getId()] = [
+                    'code' => $user->getOfficialCode(),
+                    'complete_name' => $user->getCompleteName(),
+                    'time_in_platform' => api_time_to_hms(
+                        Tracking::get_time_spent_on_the_platform($user->getId())
+                    ),
+                    'first_connection' => Tracking::get_first_connection_date($user->getId()),
+                    'last_connection' => Tracking::get_last_connection_date($user->getId())
+                ];
+            }
+
+            $usersInfo[$user->getId()][$course->getId() . '_score'] = null;
+            $usersInfo[$user->getId()][$course->getId() . '_progress'] = null;
+            $usersInfo[$user->getId()][$course->getId() . '_last_sent_date'] = null;
+
+            if (!$session->hasStudentInCourse($user, $course)) {
+                continue;
+            }
+
+            $usersInfo[$user->getId()][$course->getId() . '_score'] = Tracking::get_avg_student_score(
+                $user->getId(),
+                $course->getCode(),
+                null,
+                $session->getId()
+            );
+            $usersInfo[$user->getId()][$course->getId() . '_progress'] = Tracking::get_avg_student_progress(
+                $user->getId(),
+                $course->getCode(),
+                null,
+                $session->getId()
+            );
+
             $lastPublication = Tracking::getLastStudentPublication($user, 'work', $course, $session);
-            $lastPublicationFormatted = null;
 
-            if ($lastPublication) {
-                $lastPublicationFormatted = api_format_date(
-                    $lastPublication->getSentDate()->getTimestamp(),
-                    DATE_TIME_FORMAT_SHORT
-                );
+            if (!$lastPublication) {
+                continue;
             }
 
-            $data = [
-                $user->getOfficialCode(),
-                $user->getCompleteName(),
-                api_time_to_hms(
-                    Tracking::get_time_spent_on_the_platform($user->getId())
-                ),
-                Tracking::get_first_connection_date($user->getId()),
-                Tracking::get_last_connection_date($user->getId()),
-                Tracking::get_avg_student_score($user->getId(), $course->getCode(), null, $session->getId()),
-                Tracking::get_avg_student_progress($user->getId(), $course->getCode(), null, $session->getId()),
-                $lastPublicationFormatted
-            ];
-
-            $table->addRow($data);
+            $usersInfo[$user->getId()][$course->getId() . '_last_sent_date'] = api_format_date(
+                $lastPublication->getSentDate()->getTimestamp(),
+                DATE_TIME_FORMAT_SHORT
+            );
         }
-
-        $coursesData[] = [
-            'title' => $course->getTitle(),
-            'detail_table' => $table->toHtml()
-        ];
     }
 }
 
@@ -92,16 +105,20 @@ $interbreadcrumb[] = [
     'name' => get_lang('MySpace')
 ];
 
-$view = new Template(get_lang('WorkReport'));
-$view->assign('header', get_lang('WorkReport'));
+$toolName = get_lang('WorkReport');
+
+$view = new Template($toolName);
 $view->assign('form', $form->returnForm());
 
 if ($session) {
     $view->assign('session', ['name' => $session->getName()]);
-    $view->assign('courses', $coursesData);
+    $view->assign('courses', $coursesInfo);
+    $view->assign('users', $usersInfo);
 }
 
 $template = $view->get_template('my_space/works.tpl');
 $content = $view->fetch($template);
+
+$view->assign('header', $toolName);
 $view->assign('content', $content);
 $view->display_one_col_template();

+ 29 - 4
main/template/default/my_space/works.tpl

@@ -1,8 +1,33 @@
 {{ form }}
+
 {% if session %}
     <h3 class="page-header">{{ session.name }}</h3>
-    {% for course in courses %}
-        <h4>{{ course.title }}</h4>
-        {{ course.detail_table }}
-    {% endfor %}
+    <div class="table-responsive">
+        <table class="table table-hover table-striped">
+            <thead>
+                <tr>
+                    <th>{{ 'OfficialCode'|get_lang }}</th>
+                    <th>{{ 'Name'|get_lang }}</th>
+                    <th>{{ 'TimeSpentOnThePlatform'|get_lang }}</th>
+                    <th>{{ 'FirstLoginInPlatform'|get_lang }}</th>
+                    <th>{{ 'LatestLoginInPlatform'|get_lang }}</th>
+
+                    {% for course_code in courses %}
+                        <th title="{{ header.title }}">{{ course_code }}</th>
+                        <th>{{ 'Progress'|get_lang }}</th>
+                        <th>{{ 'LastSentWorkDate'|get_lang }}</th>
+                    {% endfor %}
+                </tr>
+            </thead>
+            <tbody>
+                {% for user in users %}
+                    <tr>
+                        {% for data in user %}
+                            <td>{{ data }}</td>
+                        {% endfor %}
+                    </tr>
+                {% endfor %}
+            </tbody>
+        </table>
+    </div>
 {% endif %}