Add teacher time report by session - refs BT#11032

1.10.x
Angel Fernando Quiroz Campos 9 years ago
parent 5103229da8
commit ad40e23ae2
  1. 115
      main/admin/teacher_time_report_by_session.php
  2. 2
      main/inc/ajax/model.ajax.php
  3. 7
      main/template/default/admin/teacher_time_report.tpl
  4. 44
      main/template/default/admin/teacher_time_report_by_session.tpl
  5. 1
      main/work/work.lib.php
  6. 2
      src/Chamilo/CourseBundle/Entity/CStudentPublication.php
  7. 53
      src/Chamilo/CourseBundle/Entity/Repository/CStudentPublicationRepository.php

@ -0,0 +1,115 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Generate a teacher time report in platform by session only
* @package chamilo.admin
*/
$cidReset = true;
require_once '../inc/global.inc.php';
require_once api_get_path(SYS_CODE_PATH) . 'work/work.lib.php';
api_protect_admin_script();
$em = Database::getManager();
$sessionsInfo = SessionManager::get_sessions_list([], ['name']);
$session = null;
$form = new FormValidator('teacher_time_report_by_session');
$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);
}
$data = [];
if ($session) {
$sessionCourses = $session->getCourses();
foreach ($sessionCourses as $sessionCourse) {
$course = $sessionCourse->getCourse();
$userCourseSubscriptions = $session->getUserCourseSubscriptionsByStatus(
$course,
\Chamilo\CoreBundle\Entity\Session::COACH
);
foreach ($userCourseSubscriptions as $userCourseSubscription) {
$user = $userCourseSubscription->getUser();
if (!array_key_exists($user->getId(), $data)) {
$data[$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()),
'courses' => []
];
}
if (array_key_exists($course->getId(), $data[$user->getId()]['courses'])) {
continue;
}
$works = $em
->getRepository('ChamiloCourseBundle:CStudentPublication')
->findByTeacher($user, $course, $session->getId());
$lastWork = array_pop($works);
$lastFormattedDate = null;
if ($lastWork) {
$lastFormattedDate = api_format_date($lastWork->getSentDate()->getTimestamp(), DATE_TIME_FORMAT_SHORT);
}
$data[$user->getId()]['courses'][$course->getId()] = [
'id' => $course->getId(),
'title' => $course->getTitle(),
'code' => $course->getCode(),
'number_of_students' => $sessionCourse->getNbrUsers(),
'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()
)
)
];
}
}
}
$this_section = SECTION_PLATFORM_ADMIN;
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('Administration')];
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH) . 'admin/teacher_time_report.php',
'name' => get_lang('TeacherTimeReport')
];
$toolName = get_lang('TeacherTimeReportBySession');
$view = new Template($toolName);
$view->assign('form', $form->returnForm());
if ($session) {
$view->assign('session', ['id' => $session->getId(), 'name' => $session->getName()]);
$view->assign('data', $data);
}
$template = $view->get_template('admin/teacher_time_report_by_session.tpl');
$content = $view->fetch($template);
$view->assign('header', $toolName);
$view->assign('content', $content);
$view->display_one_col_template();

@ -1706,7 +1706,7 @@ if (in_array($action, $allowed_actions)) {
}
}
header('Content-Type: application/json;charset=utf-8');
//header('Content-Type: application/json;charset=utf-8');
echo json_encode($response);
}
exit;

@ -30,12 +30,15 @@
<div class="actions">
<div class="row">
<div class="col-md-12">
<a href="{{ _p.web_self }}?export=pdf&from={{ selectedFrom }}&until={{ selectedUntil }}&course={{ selectedCourse }}&session={{ selectedSession }}&teacher={{ selectedTeacher }}">
<a href="{{ _p.web_self ~ '?' ~ {'export':'pdf','from':selectedFrom,'until':selectedUntil,'course':selectedCourse,'session':selectedSession,'teacher':selectedTeacher}|url_encode }}">
{{ 'pdf.png' | img(32, 'ExportToPDF'|get_lang ) }}
</a>
<a href="{{ _p.web_self }}?export=xls&from={{ selectedFrom }}&until={{ selectedUntil }}&course={{ selectedCourse }}&session={{ selectedSession }}&teacher={{ selectedTeacher }}">
<a href="{{ _p.web_self ~ '?' ~ {'export':'xls','from':selectedFrom,'until':selectedUntil,'course':selectedCourse,'session':selectedSession,'teacher':selectedTeacher}|url_encode }}">
{{ 'export_excel.png' | img(32, 'ExportExcel'|get_lang ) }}
</a>
<a href="{{ _p.web_main }}admin/teacher_time_report_by_session.php">
{{ 'session.png'|img(32, 'Sessions'|get_lang) }}
</a>
</div>
</div>
</div>

@ -0,0 +1,44 @@
{{ form }}
{% if session %}
<h3 class="page-header">{{ session.name }}</h3>
{% for row in data %}
<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 in row.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>
<tr>
<td>{{ row.code }}</td>
<td>{{ row.complete_name }}</td>
<td>{{ row.time_in_platform }}</td>
<td>{{ row.first_connection }}</td>
<td>{{ row.last_connection }}</td>
{% for course in row.courses %}
<td>{{ course.number_of_students }}</td>
<td>{{ course.number_of_works }}</td>
<td>{{ course.last_work }}</td>
<td>{{ course.time_spent_of_course }}</td>
{% endfor %}
</tr>
</tbody>
</table>
</div>
{% endfor %}
{% endif %}

@ -1499,6 +1499,7 @@ function getWorkListTeacher(
$where_condition
ORDER BY $column $direction
LIMIT $start, $limit";
echo "<pre>$sql</pre>";
$result = Database::query($sql);
if ($getCount) {

@ -15,7 +15,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Index(name="session_id", columns={"session_id"})
* }
* )
* @ORM\Entity
* @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Entity\Repository\CStudentPublicationRepository")
*/
class CStudentPublication
{

@ -0,0 +1,53 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CourseBundle\Entity\Repository;
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\Query\Expr\OrderBy;
class CStudentPublicationRepository extends EntityRepository
{
/**
* Find all the works registered by a teacher
* @param User $user
* @param Course $course
* @param int $sessionId Optional
* @param int $groupId Optional
* @return array
*/
public function findByTeacher(User $user, Course $course, $sessionId = 0, $groupId = 0)
{
$qb = $this->createQueryBuilder('w');
return $qb
->leftJoin(
'ChamiloCourseBundle:CStudentPublicationAssignment',
'a',
Join::WITH,
'a.publicationId = w.iid AND a.cId = w.cId'
)
->where(
$qb->expr()->andX(
$qb->expr()->eq('w.cId', ':course'),
$qb->expr()->eq('w.sessionId', ':session'),
$qb->expr()->in('w.active', [0, 1]),
$qb->expr()->eq('w.parentId', 0),
$qb->expr()->eq('w.postGroupId', ':group'),
$qb->expr()->eq('w.userId', ':user')
)
)
->orderBy('w.sentDate', 'DESC')
->setParameters([
'course' => intval($course->getId()),
'session' => intval($sessionId),
'group' => intval($groupId),
'user' => $user->getId()
])
->getQuery()
->getResult();
}
}
Loading…
Cancel
Save