Show only one table in teachers time by session report - refs BT#11032

1.10.x
Angel Fernando Quiroz Campos 9 years ago
parent 3756e449d4
commit e0a22db146
  1. 96
      main/admin/teachers_time_by_session_report.php
  2. 29
      main/template/default/admin/teachers_time_by_session_report.tpl

@ -5,6 +5,10 @@
* Generate a teacher time report in platform by session only * Generate a teacher time report in platform by session only
* @package chamilo.admin * @package chamilo.admin
*/ */
use \Chamilo\CoreBundle\Entity\Session;
use \Doctrine\Common\Collections\Criteria;
$cidReset = true; $cidReset = true;
require_once '../inc/global.inc.php'; require_once '../inc/global.inc.php';
@ -12,6 +16,8 @@ require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php';
api_protect_admin_script(); api_protect_admin_script();
$toolName = get_lang('TeacherTimeReportBySession');
$em = Database::getManager(); $em = Database::getManager();
$sessionsInfo = SessionManager::get_sessions_list([], ['name']); $sessionsInfo = SessionManager::get_sessions_list([], ['name']);
$session = null; $session = null;
@ -31,22 +37,27 @@ if (isset($_GET['session']) && intval($_GET['session'])) {
} }
$data = []; $data = [];
$coursesInfo = [];
$usersInfo = [];
if ($session) { if ($session) {
$sessionCourses = $session->getCourses(); $sessionCourses = $session->getCourses();
foreach ($sessionCourses as $sessionCourse) { foreach ($sessionCourses as $sessionCourse) {
$course = $sessionCourse->getCourse(); $course = $sessionCourse->getCourse();
$userCourseSubscriptions = $session->getUserCourseSubscriptionsByStatus( $coursesInfo[$course->getId()] = $course->getCode();
$course, $criteria = Criteria::create()->where(
\Chamilo\CoreBundle\Entity\Session::COACH Criteria::expr()->eq("status", Session::COACH)
); );
$userCourseSubscriptions = $session
->getUserCourseSubscriptions()
->matching($criteria);
foreach ($userCourseSubscriptions as $userCourseSubscription) { foreach ($userCourseSubscriptions as $userCourseSubscription) {
$user = $userCourseSubscription->getUser(); $user = $userCourseSubscription->getUser();
if (!array_key_exists($user->getId(), $data)) { if (!array_key_exists($user->getId(), $usersInfo)) {
$data[$user->getId()] = [ $usersInfo[$user->getId()] = [
'code' => $user->getOfficialCode(), 'code' => $user->getOfficialCode(),
'complete_name' => $user->getCompleteName(), 'complete_name' => $user->getCompleteName(),
'time_in_platform' => api_time_to_hms( 'time_in_platform' => api_time_to_hms(
@ -54,11 +65,15 @@ if ($session) {
), ),
'first_connection' => Tracking::get_first_connection_date($user->getId()), 'first_connection' => Tracking::get_first_connection_date($user->getId()),
'last_connection' => Tracking::get_last_connection_date($user->getId()), 'last_connection' => Tracking::get_last_connection_date($user->getId()),
'courses' => []
]; ];
} }
if (array_key_exists($course->getId(), $data[$user->getId()]['courses'])) { $usersInfo[$user->getId()][$course->getId() . '_number_of_students'] = null;
$usersInfo[$user->getId()][$course->getId() . '_number_of_works'] = null;
$usersInfo[$user->getId()][$course->getId() . '_last_work'] = null;
$usersInfo[$user->getId()][$course->getId() . '_time_spent_of_course'] = null;
if (!$session->hasCoachInCourseWithStatus($user, $course)) {
continue; continue;
} }
@ -66,43 +81,52 @@ if ($session) {
->getRepository('ChamiloCourseBundle:CStudentPublication') ->getRepository('ChamiloCourseBundle:CStudentPublication')
->findByTeacher($user, $course, $session->getId()); ->findByTeacher($user, $course, $session->getId());
$lastWork = array_pop($works); $lastWork = array_pop($works);
$lastFormattedDate = null;
if ($lastWork) { $usersInfo[$user->getId()][$course->getId() . '_number_of_students'] = $sessionCourse->getNbrUsers();
$lastFormattedDate = api_format_date($lastWork->getSentDate()->getTimestamp(), DATE_TIME_FORMAT_SHORT); $usersInfo[$user->getId()][$course->getId() . '_number_of_works'] = count($works);
$usersInfo[$user->getId()][$course->getId() . '_time_spent_of_course'] = api_time_to_hms(
Tracking::get_time_spent_on_the_course($user->getId(), $course->getId(), $session->getId())
);
if (!$lastWork) {
continue;
} }
$data[$user->getId()]['courses'][$course->getId()] = [ $lastFormattedDate = api_format_date($lastWork->getSentDate()->getTimestamp(), DATE_TIME_FORMAT_SHORT);
'id' => $course->getId(),
'title' => $course->getTitle(), $usersInfo[$user->getId()][$course->getId() . '_last_work'] = api_format_date(
'code' => $course->getCode(), $lastWork->getSentDate()->getTimestamp(),
'number_of_students' => $sessionCourse->getNbrUsers(), DATE_TIME_FORMAT_SHORT
'number_of_works' => count($works), );
'last_work' => $lastFormattedDate,
'time_spent_of_course' => api_time_to_hms(
Tracking::get_time_spent_on_the_course(
$user->getId(),
$course->getId(),
$session->getId()
)
)
];
} }
} }
} }
if (isset($_GET['export']) && $session && $data) { if (isset($_GET['export']) && $session && ($coursesInfo && $usersInfo)) {
$dataToExport = [];
$fileName = get_lang('TeacherTimeReport') . ' ' . api_get_local_time(); $fileName = get_lang('TeacherTimeReport') . ' ' . api_get_local_time();
$dataToExport = [];
$dataToExport[] = [$toolName, $session->getName()];
$dataToExport['headers'] = [
get_lang('OfficialCode'),
get_lang('CoachName'),
get_lang('TimeSpentOnThePlatform'),
get_lang('FirstLoginInPlatform'),
get_lang('LatestLoginInPlatform'),
];
foreach ($coursesInfo as $courseCode) {
$dataToExport['headers'][] = $courseCode;
$dataToExport['headers'][] = get_lang('NumberOfWorks');
$dataToExport['headers'][] = get_lang('LastWork');
$dataToExport['headers'][] = sprintf(get_lang('TimeReportForCourseX'), $courseCode);
}
foreach ($usersInfo as $user) {
$dataToExport[] = $user;
}
foreach ($data as $row) { foreach ($data as $row) {
$headers = [
get_lang('OfficialCode'),
get_lang('Name'),
get_lang('TimeSpentOnThePlatform'),
get_lang('FirstLoginInPlatform'),
get_lang('LatestLoginInPlatform')
];
$contents = [ $contents = [
$row['code'], $row['code'],
$row['complete_name'], $row['complete_name'],
@ -145,7 +169,6 @@ $interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH) . 'admin/teacher_time_report.php', 'url' => api_get_path(WEB_CODE_PATH) . 'admin/teacher_time_report.php',
'name' => get_lang('TeacherTimeReport') 'name' => get_lang('TeacherTimeReport')
]; ];
$toolName = get_lang('TeacherTimeReportBySession');
$actions = []; $actions = [];
@ -167,7 +190,8 @@ $view->assign('form', $form->returnForm());
if ($session) { if ($session) {
$view->assign('session', ['id' => $session->getId(), 'name' => $session->getName()]); $view->assign('session', ['id' => $session->getId(), 'name' => $session->getName()]);
$view->assign('data', $data); $view->assign('courses', $coursesInfo);
$view->assign('users', $usersInfo);
} }
$template = $view->get_template('admin/teachers_time_by_session_report.tpl'); $template = $view->get_template('admin/teachers_time_by_session_report.tpl');

@ -2,6 +2,35 @@
{% if session %} {% if session %}
<h3 class="page-header">{{ session.name }}</h3> <h3 class="page-header">{{ session.name }}</h3>
<div class="table-responsive">
<table class="table table-hover table-striped">
<thead>
<tr>
<th>{{ 'OfficialCode'|get_lang }}</th>
<th>{{ 'CoachName'|get_lang }}</th>
<th>{{ 'TimeSpentOnThePlatform'|get_lang }}</th>
<th>{{ 'FirstLoginInPlatform'|get_lang }}</th>
<th>{{ 'LatestLoginInPlatform'|get_lang }}</th>
{% for course_code in courses %}
<th>{{ course_code }}</th>
<th>{{ 'NumberOfWorks'|get_lang }}</th>
<th>{{ 'LastWork'|get_lang }}</th>
<th>{{ 'TimeReportForCourseX'|get_lang|format(course.code) }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for user in users %}
<tr>
{% for data in user %}
<td>{{ data }}</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</div>
{% for row in data %} {% for row in data %}
<div class="table-responsive"> <div class="table-responsive">

Loading…
Cancel
Save