Adding auto attendance see BT#8814

1.9.x
Julio Montoya 10 years ago
parent ea4b07fe8b
commit 6bd4b5df0d
  1. 38
      main/attendance/attendance_controller.php
  2. 7
      main/attendance/attendance_list.php
  3. 11
      main/attendance/calendar_logins.php
  4. 8
      main/attendance/index.php
  5. 97
      main/inc/lib/attendance.lib.php
  6. 58
      main/inc/lib/course.lib.php

@ -536,10 +536,46 @@ class AttendanceController
'pdf_teachers' => $teacherName,
'pdf_course_category' => $courseCategory['name'],
'format' => 'A4-L',
'orientation' => 'L'
'orientation' => 'L'
);
Export::export_html_to_pdf($content, $params);
exit;
}
/**
* Gets attendace base in the table:
* TABLE_STATISTIC_TRACK_E_COURSE_ACCESS
* @throws ViewException
*/
public function calendarLogins()
{
$form = new FormValidator(
'search',
'post',
api_get_self().'?'.api_get_cidreq().'&action=calendar_logins'
);
$form->addDateRangePicker('range', get_lang('Range'));
$form->add_button('submit', get_lang('submit'));
$table = null;
if ($form->validate()) {
$values = $form->getSubmitValues();
$startDate = api_get_utc_datetime($values['range_start']);
$endDate = api_get_utc_datetime($values['range_end']);
$attendance = new Attendance();
$table = $attendance->getAttendanceLogins($startDate, $endDate);
}
$data = array(
'form' => $form->return_form(),
'table' => $table
);
$this->view->set_data($data);
$this->view->set_layout('layout');
$this->view->set_template('calendar_logins');
$this->view->render();
}
}

@ -16,7 +16,12 @@ if (api_is_allowed_to_edit(null, true)) {
$param_gradebook = '&gradebook='.Security::remove_XSS($_SESSION['gradebook']);
}
echo '<div class="actions">';
echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=attendance_add">'.Display::return_icon('new_attendance_list.png',get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=attendance_add">'.
Display::return_icon('new_attendance_list.png',get_lang('CreateANewAttendance'),'',ICON_SIZE_MEDIUM).'</a>';
echo '<a href="index.php?'.api_get_cidreq().$param_gradebook.'&action=calendar_logins">'.
Display::return_icon('attendance_list.png',get_lang('Logins'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
}
$attendance = new Attendance();

@ -0,0 +1,11 @@
<?php
/* For licensing terms, see /license.txt */
// See AttendanceController::calendarLogins function
echo '<div class="actions">';
echo '<a href="index.php?'.api_get_cidreq().'&action=calendar_list='.$param_gradebook.'">'.
Display::return_icon('back.png',get_lang('AttendanceCalendar'),'',ICON_SIZE_MEDIUM).'</a>';
echo '</div>';
echo $form;
echo $table;

@ -48,7 +48,8 @@ $actions = array(
'attendance_delete_select',
'attendance_restore',
'attendance_sheet_export_to_pdf',
'attendance_sheet_list_no_edit'
'attendance_sheet_list_no_edit',
'calendar_logins'
);
$actions_calendar = array(
@ -303,6 +304,11 @@ switch ($action) {
case 'calendar_list' :
$attendance_controller->attendance_calendar($action, $attendance_id, $calendar_id);
break;
case 'calendar_logins':
if (api_is_allowed_to_edit(null, true)) {
$attendance_controller->calendarLogins();
}
break;
default :
$attendance_controller->attendance_list();
}

@ -1483,4 +1483,101 @@ class Attendance
{
return $this->attendance_weight;
}
/**
* @param string $startDate in UTC time
* @param string $endDate in UTC time
*
* @return string
*/
public function getAttendanceLogins($startDate, $endDate)
{
$sessionId = api_get_session_id();
$courseCode = api_get_course_id();
if (!empty($sessionId)) {
$users = CourseManager:: get_user_list_from_course_code(
$courseCode,
$sessionId,
'',
'lastname'
);
} else {
$users = CourseManager:: get_user_list_from_course_code(
$courseCode,
0,
'',
'lastname'
);
}
$dateTimeStartOriginal = new DateTime($startDate);
$dateTimeStart = new DateTime($startDate);
$dateTimeEnd= new DateTime($endDate);
$interval = $dateTimeStart->diff($dateTimeEnd);
$days = intval($interval->format('%a'));
$dateList = array($dateTimeStart->format('Y-m-d'));
$headers = array(
get_lang('User'),
$dateTimeStart->format('Y-m-d')
);
for ($i = 0; $i < $days; $i++) {
$dateTimeStart = $dateTimeStart->add(new DateInterval('P1D'));
$date = $dateTimeStart->format('Y-m-d');
$dateList[] = $date;
$headers[] = $date;
}
$accessData = CourseManager::getCourseAccessPerCourseAndSession(
$courseCode,
$sessionId,
$dateTimeStartOriginal->format('Y-m-d H:i:s'),
$dateTimeEnd->format('Y-m-d H:i:s')
);
$results = array();
if (!empty($accessData)) {
foreach ($accessData as $data) {
$onlyDate = substr($data['login_course_date'], 0, 10);
$results[$data['user_id']][$onlyDate] = true;
}
}
$table = new HTML_Table(array('class' => 'data_table'));
$row = 0;
$column = 0;
foreach ($headers as $header) {
$table->setHeaderContents($row, $column, $header);
$column++;
}
$row = 1;
foreach ($users as $user) {
$table->setCellContents(
$row,
0,
$user['lastname'].' '.$user['firstname'].' ('.$user['username'].')'
);
$row ++;
}
$column = 1;
$row = 1;
foreach ($users as $user) {
foreach ($dateList as $date) {
$status = null;
if (isset($results[$user['user_id']]) &&
isset($results[$user['user_id']][$date])
) {
$status = 'X';
}
$table->setCellContents($row, $column, $status);
$column++;
}
$row++;
$column = 1;
}
return $table->toHtml();
}
}

@ -1382,7 +1382,6 @@ class CourseManager
// if the $order_by does not contain 'ORDER BY' we have to check if it is a valid field that can be sorted on
if (!strstr($order_by,'ORDER BY')) {
$order_by = Database::escape_string($order_by);
if (!empty($order_by)) {
$order_by = 'ORDER BY '.$order_by;
} else {
@ -1415,7 +1414,6 @@ class CourseManager
if (SessionManager::orderCourseIsEnabled()) {
//$order_by = "ORDER BY position";
}
} else {
if ($return_count) {
$sql = " SELECT COUNT(*) as count";
@ -1424,9 +1422,21 @@ class CourseManager
}
} else {
if (empty($course_code)) {
$sql = 'SELECT DISTINCT course.title, course.code, course_rel_user.status as status_rel, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.* ';
$sql = 'SELECT DISTINCT
course.title,
course.code,
course_rel_user.status as status_rel,
user.user_id,
course_rel_user.role,
course_rel_user.tutor_id,
user.* ';
} else {
$sql = 'SELECT DISTINCT course_rel_user.status as status_rel, user.user_id, course_rel_user.role, course_rel_user.tutor_id, user.* ';
$sql = 'SELECT DISTINCT
course_rel_user.status as status_rel,
user.user_id,
course_rel_user.role,
course_rel_user.tutor_id,
user.* ';
}
}
@ -1490,6 +1500,7 @@ class CourseManager
}
$sql .= ' '.$order_by.' '.$limit;
$rs = Database::query($sql);
$users = array();
@ -5055,6 +5066,10 @@ class CourseManager
public static function getCourseAccessPerSessionAndUser($sessionId, $userId, $limit = null)
{
$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$sessionId = intval($sessionId);
$userId = intval($userId);
$sql = "SELECT * FROM $table
WHERE session_id = $sessionId AND user_id = $userId";
@ -5067,6 +5082,38 @@ class CourseManager
return Database::store_result($result);
}
/**
* Get information from the track_e_course_access table
* @param string $courseCode
* @param int $sessionId
* @param string $startDate
* @param string $endDate
* @return array
*/
public static function getCourseAccessPerCourseAndSession(
$courseCode,
$sessionId,
$startDate,
$endDate
) {
$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$courseCode = Database::escape_string($courseCode);
$sessionId = intval($sessionId);
$startDate = Database::escape_string($startDate);
$endDate = Database::escape_string($endDate);
$sql = "SELECT * FROM $table
WHERE
course_code = $courseCode AND
session_id = $sessionId AND
login_course_date BETWEEN $startDate AND $endDate
";
$result = Database::query($sql);
return Database::store_result($result);
}
/**
* Get login information from the track_e_course_access table, for any
* course in the given session
@ -5076,6 +5123,9 @@ class CourseManager
*/
public static function getFirstCourseAccessPerSessionAndUser($sessionId, $userId)
{
$sessionId = intval($sessionId);
$userId = intval($userId);
$table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS);
$sql = "SELECT * FROM $table
WHERE session_id = $sessionId AND user_id = $userId

Loading…
Cancel
Save