diff --git a/main/admin/teacher_time_report_by_session.php b/main/admin/teacher_time_report_by_session.php new file mode 100644 index 0000000000..5c1dabf4e6 --- /dev/null +++ b/main/admin/teacher_time_report_by_session.php @@ -0,0 +1,115 @@ +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(); diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 8040f5b301..7dae7b0b06 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -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; diff --git a/main/template/default/admin/teacher_time_report.tpl b/main/template/default/admin/teacher_time_report.tpl index 3537d26ef3..6c5dda04b9 100644 --- a/main/template/default/admin/teacher_time_report.tpl +++ b/main/template/default/admin/teacher_time_report.tpl @@ -30,12 +30,15 @@
{{ 'OfficialCode'|get_lang }} | +{{ 'Name'|get_lang }} | +{{ 'TimeSpentOnThePlatform'|get_lang }} | +{{ 'FirstLoginInPlatform'|get_lang }} | +{{ 'LatestLoginInPlatform'|get_lang }} | + + {% for course in row.courses %} +{{ course.code }} | +{{ 'NumberOfWorks'|get_lang }} | +{{ 'LastWork'|get_lang }} | +{{ 'TimeReportForCourseX'|get_lang|format(course.code) }} | + {% endfor %} +
---|---|---|---|---|---|---|---|---|
{{ row.code }} | +{{ row.complete_name }} | +{{ row.time_in_platform }} | +{{ row.first_connection }} | +{{ row.last_connection }} | + + {% for course in row.courses %} +{{ course.number_of_students }} | +{{ course.number_of_works }} | +{{ course.last_work }} | +{{ course.time_spent_of_course }} | + {% endfor %} +
$sql"; $result = Database::query($sql); if ($getCount) { diff --git a/src/Chamilo/CourseBundle/Entity/CStudentPublication.php b/src/Chamilo/CourseBundle/Entity/CStudentPublication.php index 360bd6e835..2fb6773c71 100644 --- a/src/Chamilo/CourseBundle/Entity/CStudentPublication.php +++ b/src/Chamilo/CourseBundle/Entity/CStudentPublication.php @@ -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 { diff --git a/src/Chamilo/CourseBundle/Entity/Repository/CStudentPublicationRepository.php b/src/Chamilo/CourseBundle/Entity/Repository/CStudentPublicationRepository.php new file mode 100644 index 0000000000..1ef4fb6e78 --- /dev/null +++ b/src/Chamilo/CourseBundle/Entity/Repository/CStudentPublicationRepository.php @@ -0,0 +1,53 @@ +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(); + } +} \ No newline at end of file