Explorar el Código

Add Work Report - refs BT#11031

Angel Fernando Quiroz Campos hace 8 años
padre
commit
0225a3dc1c

+ 12 - 2
main/inc/ajax/model.ajax.php

@@ -982,13 +982,23 @@ switch ($action) {
                 } else {
                     $session_date_string = implode(' ', $session_date);
                 }
-                $sessionUrl = api_get_path(WEB_CODE_PATH).'mySpace/course.php?session_id='.$session['id'];
+
+                $detailButtons = [];
+                $detailButtons[] = Display::url(
+                    Display::return_icon('works.png', get_lang('Works')),
+                    api_get_path(WEB_CODE_PATH) . 'mySpace/works.php'
+                );
+                $detailButtons[] = Display::url(
+                    Display::return_icon('2rightarrow.png'),
+                    api_get_path(WEB_CODE_PATH) . 'mySpace/course.php?session_id=' . $session['id']
+                );
+
                 $result[] = array(
                     'name' => $session['name'],
                     'date' => $session_date_string,
                     'course_per_session' => $count_courses_in_session,
                     'student_per_session' => $count_users_in_session,
-                    'details' => Display::url(Display::return_icon('2rightarrow.png'), $sessionUrl)
+                    'details' => implode(' ', $detailButtons)
                 );
             }
         }

+ 38 - 0
main/inc/lib/tracking.lib.php

@@ -5,6 +5,9 @@ use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField;
 use CpChart\Classes\pCache as pCache;
 use CpChart\Classes\pData as pData;
 use CpChart\Classes\pImage as pImage;
+use Chamilo\UserBundle\Entity\User;
+use Chamilo\CoreBundle\Entity\Course;
+use Chamilo\CoreBundle\Entity\Session;
 
 /**
  *  Class Tracking
@@ -5752,6 +5755,41 @@ class Tracking
         }
         return $data;
     }
+
+    /**
+     * @param User $user
+     * @param string $tool
+     * @param Course $course
+     * @param Session|null $session Optional.
+     * @return \Chamilo\CourseBundle\Entity\CStudentPublication|null
+     * @throws \Doctrine\ORM\NonUniqueResultException
+     */
+    public static function getLastStudentPublication(User $user, $tool, Course $course, Session $session = null)
+    {
+        return Database::getManager()
+            ->createQuery("
+                SELECT csp
+                FROM ChamiloCourseBundle:CStudentPublication csp
+                INNER JOIN ChamiloCourseBundle:CItemProperty cip
+                    WITH (
+                        csp.iid = cip.ref AND
+                        csp.sessionId = cip.session AND
+                        csp.cId = cip.course AND
+                        csp.userId = cip.lasteditUserId
+                    )
+                WHERE
+                    cip.session = :session AND cip.course = :course AND cip.lasteditUserId = :user AND cip.tool = :tool
+                ORDER BY csp.iid DESC
+            ")
+            ->setMaxResults(1)
+            ->setParameters([
+                'tool' => $tool,
+                'session' => $session,
+                'course' => $course,
+                'user' => $user
+            ])
+            ->getOneOrNullResult();
+    }
 }
 
 /**

+ 1 - 2
main/mySpace/course.php

@@ -6,7 +6,6 @@
  */
 
 ob_start();
-$nameTools = 'Cours';
 $cidReset = true;
 
 require_once '../inc/global.inc.php';
@@ -57,7 +56,7 @@ if (api_get_setting('add_users_by_coach') == 'true') {
     }
 }
 
-Display :: display_header($nameTools);
+Display :: display_header(get_lang('Courses'));
 
 $a_courses = array();
 if (api_is_drh() || api_is_session_admin() || api_is_platform_admin()) {

+ 107 - 0
main/mySpace/works.php

@@ -0,0 +1,107 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+ * Courses reporting
+ * @package chamilo.reporting
+ */
+
+require_once '../inc/global.inc.php';
+
+if (api_is_student()) {
+    api_not_allowed(true);
+    exit;
+}
+
+$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')]);
+$form->addButtonFilter(get_lang('Filter'));
+
+foreach ($sessionsInfo as $sessionInfo) {
+    $selectSession->addOption($sessionInfo['name'], $sessionInfo['id']);
+}
+
+if ($form->validate()) {
+    $sessionId = $form->exportValue('session');
+    $session = $em->find('ChamiloCoreBundle:Session', $sessionId);
+}
+
+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'));
+
+        foreach ($userCourseSubscriptions as $userCourseSubscription) {
+            $user = $userCourseSubscription->getUser();
+            
+            $lastPublication = Tracking::getLastStudentPublication($user, 'work', $course, $session);
+            $lastPublicationFormatted = null;
+
+            if ($lastPublication) {
+                $lastPublicationFormatted = api_format_date(
+                    $lastPublication->getSentDate()->getTimestamp(),
+                    DATE_TIME_FORMAT_SHORT
+                );
+            }
+
+            $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);
+        }
+
+        $coursesData[] = [
+            'title' => $course->getTitle(),
+            'detail_table' => $table->toHtml()
+        ];
+    }
+}
+
+$interbreadcrumb[] = [
+    'url' => api_get_path(WEB_CODE_PATH) . 'mySpace/index.php',
+    'name' => get_lang('MySpace')
+];
+
+$view = new Template(get_lang('WorkReport'));
+$view->assign('header', get_lang('WorkReport'));
+$view->assign('form', $form->returnForm());
+
+if ($session) {
+    $view->assign('session', ['name' => $session->getName()]);
+    $view->assign('courses', $coursesData);
+}
+
+$template = $view->get_template('my_space/works.tpl');
+$content = $view->fetch($template);
+$view->assign('content', $content);
+$view->display_one_col_template();

+ 8 - 0
main/template/default/my_space/works.tpl

@@ -0,0 +1,8 @@
+{{ form }}
+{% if session %}
+    <h3 class="page-header">{{ session.name }}</h3>
+    {% for course in courses %}
+        <h4>{{ course.title }}</h4>
+        {{ course.detail_table }}
+    {% endfor %}
+{% endif %}