|
|
|
|
@ -1567,6 +1567,7 @@ class Attendance |
|
|
|
|
$row['date'] = api_format_date($row['date_time'], DATE_FORMAT_SHORT); |
|
|
|
|
$row['time'] = api_format_date($row['date_time'], TIME_NO_SEC_FORMAT); |
|
|
|
|
$row['groups'] = $this->getGroupListByAttendanceCalendar($row['id'], $course_id); |
|
|
|
|
$row['duration'] = Attendance::getAttendanceCalendarExtraFieldValue('duration', $row['id']); |
|
|
|
|
if ($type == 'today') { |
|
|
|
|
if (date('d-m-Y', api_strtotime($row['date_time'], 'UTC')) == date('d-m-Y', time())) { |
|
|
|
|
$data[] = $row; |
|
|
|
|
@ -1746,10 +1747,11 @@ class Attendance |
|
|
|
|
* |
|
|
|
|
* @param int $attendanceId |
|
|
|
|
* @param array $groupList |
|
|
|
|
* @param array $extraValues |
|
|
|
|
* |
|
|
|
|
* @return int affected rows |
|
|
|
|
*/ |
|
|
|
|
public function attendance_calendar_add($attendanceId, $groupList = []) |
|
|
|
|
public function attendance_calendar_add($attendanceId, $groupList = [], $extraValues = []) |
|
|
|
|
{ |
|
|
|
|
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
|
|
|
$affected_rows = 0; |
|
|
|
|
@ -1775,6 +1777,13 @@ class Attendance |
|
|
|
|
$sql = "UPDATE $tbl_attendance_calendar SET id = iid WHERE iid = $id"; |
|
|
|
|
Database::query($sql); |
|
|
|
|
$affected_rows++; |
|
|
|
|
|
|
|
|
|
if (!empty($extraValues)) { |
|
|
|
|
// It saves extra fields values |
|
|
|
|
$extraFieldValue = new ExtraFieldValue('attendance_calendar'); |
|
|
|
|
$extraValues['item_id'] = $id; |
|
|
|
|
$extraFieldValue->saveFieldValues($extraValues); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$this->addAttendanceCalendarToGroup($id, $course_id, $groupList); |
|
|
|
|
//} |
|
|
|
|
@ -1892,7 +1901,7 @@ class Attendance |
|
|
|
|
* @param int $attendanceId |
|
|
|
|
* @param int $start_date start date in tms |
|
|
|
|
* @param int $end_date end date in tms |
|
|
|
|
* @param string $repeat_type daily, weekly, monthlyByDate |
|
|
|
|
* @param string $repeat_type daily, weekly, biweekly, xdays, monthlyByDate |
|
|
|
|
* @param array $groupList |
|
|
|
|
*/ |
|
|
|
|
public function attendance_repeat_calendar_add( |
|
|
|
|
@ -1900,58 +1909,80 @@ class Attendance |
|
|
|
|
$start_date, |
|
|
|
|
$end_date, |
|
|
|
|
$repeat_type, |
|
|
|
|
$groupList = [] |
|
|
|
|
$groupList = [], |
|
|
|
|
$extraValues = [] |
|
|
|
|
) { |
|
|
|
|
$attendanceId = intval($attendanceId); |
|
|
|
|
// save start date |
|
|
|
|
$datetimezone = api_get_utc_datetime($start_date); |
|
|
|
|
$this->set_date_time($datetimezone); |
|
|
|
|
$this->attendance_calendar_add($attendanceId, $groupList); |
|
|
|
|
$this->attendance_calendar_add($attendanceId, $groupList, $extraValues); |
|
|
|
|
|
|
|
|
|
// 86400 = 24 hours in seconds |
|
|
|
|
// 604800 = 1 week in seconds |
|
|
|
|
// 1296000 = 1 biweek in seconds |
|
|
|
|
// 2419200 = 1 month in seconds |
|
|
|
|
// 86400 x xdays = interval by x days (in seconds) |
|
|
|
|
// Saves repeated dates |
|
|
|
|
$seconds = 0; |
|
|
|
|
switch ($repeat_type) { |
|
|
|
|
case 'daily': |
|
|
|
|
$j = 1; |
|
|
|
|
for ($i = $start_date + 86400; ($i <= $end_date); $i += 86400) { |
|
|
|
|
$datetimezone = api_get_utc_datetime($i); |
|
|
|
|
$this->set_date_time($datetimezone); |
|
|
|
|
$this->attendance_calendar_add($attendanceId, $groupList); |
|
|
|
|
$j++; |
|
|
|
|
} |
|
|
|
|
$seconds = 86400; |
|
|
|
|
break; |
|
|
|
|
case 'weekly': |
|
|
|
|
$j = 1; |
|
|
|
|
for ($i = $start_date + 604800; ($i <= $end_date); $i += 604800) { |
|
|
|
|
$datetimezone = api_get_utc_datetime($i); |
|
|
|
|
$this->set_date_time($datetimezone); |
|
|
|
|
$this->attendance_calendar_add($attendanceId, $groupList); |
|
|
|
|
$j++; |
|
|
|
|
} |
|
|
|
|
$seconds = 604800; |
|
|
|
|
break; |
|
|
|
|
case 'biweekly': |
|
|
|
|
$seconds = 1296000; |
|
|
|
|
break; |
|
|
|
|
case 'monthlyByDate': |
|
|
|
|
$seconds = 2419200; |
|
|
|
|
break; |
|
|
|
|
case 'xdays': |
|
|
|
|
$seconds = isset($extraValues['xdays_number']) ? (int) $extraValues['xdays_number'] * 86400 : 0; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($seconds > 0) { |
|
|
|
|
$j = 1; |
|
|
|
|
//@todo fix bug with february |
|
|
|
|
for ($i = $start_date + 2419200; ($i <= $end_date); $i += 2419200) { |
|
|
|
|
for ($i = $start_date + $seconds; ($i <= $end_date); $i += $seconds) { |
|
|
|
|
$datetimezone = api_get_utc_datetime($i); |
|
|
|
|
$this->set_date_time($datetimezone); |
|
|
|
|
$this->attendance_calendar_add($attendanceId, $groupList); |
|
|
|
|
$this->attendance_calendar_add($attendanceId, $groupList, $extraValues); |
|
|
|
|
$j++; |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the value of a attendance calendar extra field. Returns null if it was not found. |
|
|
|
|
* |
|
|
|
|
* @param string $variable Name of the extra field |
|
|
|
|
* @param string $calendarId Calendar id |
|
|
|
|
* |
|
|
|
|
* @return string Value |
|
|
|
|
*/ |
|
|
|
|
public static function getAttendanceCalendarExtraFieldValue($variable, $calendarId) |
|
|
|
|
{ |
|
|
|
|
$extraFieldValues = new ExtraFieldValue('attendance_calendar'); |
|
|
|
|
$result = $extraFieldValues->get_values_by_handler_and_field_variable($calendarId, $variable); |
|
|
|
|
if (!empty($result['value'])) { |
|
|
|
|
return $result['value']; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* edit a datetime inside attendance calendar table. |
|
|
|
|
* |
|
|
|
|
* @param int attendance calendar id |
|
|
|
|
* @param int attendance id |
|
|
|
|
* @param array extra values |
|
|
|
|
* |
|
|
|
|
* @return int affected rows |
|
|
|
|
*/ |
|
|
|
|
public function attendance_calendar_edit($calendar_id, $attendanceId) |
|
|
|
|
public function attendance_calendar_edit($calendar_id, $attendanceId, $extraValues = []) |
|
|
|
|
{ |
|
|
|
|
$tbl_attendance_calendar = Database::get_course_table(TABLE_ATTENDANCE_CALENDAR); |
|
|
|
|
$affected_rows = 0; |
|
|
|
|
@ -1972,6 +2003,11 @@ class Attendance |
|
|
|
|
Database::query($sql); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// It saves extra fields values |
|
|
|
|
$extraFieldValue = new ExtraFieldValue('attendance_calendar'); |
|
|
|
|
$extraValues['item_id'] = $calendar_id; |
|
|
|
|
$extraFieldValue->saveFieldValues($extraValues); |
|
|
|
|
|
|
|
|
|
// update locked attendance |
|
|
|
|
$is_all_calendar_done = self::is_all_attendance_calendar_done($attendanceId); |
|
|
|
|
if (!$is_all_calendar_done) { |
|
|
|
|
@ -2635,6 +2671,191 @@ class Attendance |
|
|
|
|
return $signature; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* It exports the attendance sheet to Xls format. |
|
|
|
|
* |
|
|
|
|
* @param $attendanceId |
|
|
|
|
* @param $studentId |
|
|
|
|
* @param $courseId |
|
|
|
|
* @param $groupId |
|
|
|
|
* @param $filterType |
|
|
|
|
* @param $myCalendarId |
|
|
|
|
*/ |
|
|
|
|
public function exportAttendanceSheetToXls( |
|
|
|
|
$attendanceId, |
|
|
|
|
$studentId, |
|
|
|
|
$courseId, |
|
|
|
|
$groupId, |
|
|
|
|
$filterType, |
|
|
|
|
$myCalendarId |
|
|
|
|
) { |
|
|
|
|
$users = $this->get_users_rel_course($attendanceId, $groupId); |
|
|
|
|
$calendar = $this->get_attendance_calendar( |
|
|
|
|
$attendanceId, |
|
|
|
|
$filterType, |
|
|
|
|
$myCalendarId, |
|
|
|
|
$groupId |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
if (!empty($studentId)) { |
|
|
|
|
$userId = (int) $studentId; |
|
|
|
|
} else { |
|
|
|
|
$userId = api_get_user_id(); |
|
|
|
|
} |
|
|
|
|
$courseInfo = api_get_course_info($courseId); |
|
|
|
|
|
|
|
|
|
$userPresence = []; |
|
|
|
|
$faults = []; |
|
|
|
|
if (api_is_allowed_to_edit(null, true) || api_is_drh()) { |
|
|
|
|
$userPresence = $this->get_users_attendance_sheet($attendanceId, 0, $groupId); |
|
|
|
|
} else { |
|
|
|
|
$userPresence = $this->get_users_attendance_sheet($attendanceId, $userId, $groupId); |
|
|
|
|
$faults = $this->get_faults_of_user($userId, $attendanceId, $groupId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Set headers pdf. |
|
|
|
|
$teacherInfo = CourseManager::get_teacher_list_from_course_code($courseInfo['code']); |
|
|
|
|
$teacherName = null; |
|
|
|
|
foreach ($teacherInfo as $teacherData) { |
|
|
|
|
if ($teacherName != null) { |
|
|
|
|
$teacherName = $teacherName." / "; |
|
|
|
|
} |
|
|
|
|
$teacherName .= api_get_person_name($teacherData['firstname'], $teacherData['lastname']); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get data table |
|
|
|
|
$dataTable = []; |
|
|
|
|
$headTable = ['#', get_lang('Name')]; |
|
|
|
|
foreach ($calendar as $classDay) { |
|
|
|
|
$labelDuration = !empty($classDay['duration']) ? get_lang('Duration').' : '.$classDay['duration'] : ''; |
|
|
|
|
$headTable[] = |
|
|
|
|
api_format_date($classDay['date_time'], DATE_FORMAT_NUMBER_NO_YEAR).' '. |
|
|
|
|
api_format_date($classDay['date_time'], TIME_NO_SEC_FORMAT).' '. |
|
|
|
|
$labelDuration; |
|
|
|
|
} |
|
|
|
|
$dataTable[] = $headTable; |
|
|
|
|
$dataUsersPresence = $userPresence; |
|
|
|
|
$count = 1; |
|
|
|
|
|
|
|
|
|
if (!empty($users)) { |
|
|
|
|
foreach ($users as $user) { |
|
|
|
|
$cols = 1; |
|
|
|
|
$result = []; |
|
|
|
|
$result['count'] = $count; |
|
|
|
|
$result['full_name'] = api_get_person_name($user['firstname'], $user['lastname']); |
|
|
|
|
foreach ($calendar as $classDay) { |
|
|
|
|
$comment = $this->getComment($user['user_id'], $classDay['id']); |
|
|
|
|
$txtComment = !empty($comment) ? '[comment]'.$comment : ''; |
|
|
|
|
if (1 == (int) $classDay['done_attendance']) { |
|
|
|
|
if (1 == (int) $dataUsersPresence[$user['user_id']][$classDay['id']]['presence']) { |
|
|
|
|
$result[$classDay['id']] = get_lang('UserAttendedSymbol').$txtComment; |
|
|
|
|
} else { |
|
|
|
|
$result[$classDay['id']] = get_lang('UserNotAttendedSymbol').$txtComment; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
$result[$classDay['id']] = ' '; |
|
|
|
|
} |
|
|
|
|
$cols++; |
|
|
|
|
} |
|
|
|
|
$count++; |
|
|
|
|
$dataTable[] = $result; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$filename = get_lang('Attendance').'-'.api_get_local_time(); |
|
|
|
|
Export::arrayToXlsAndComments($dataTable, $filename); |
|
|
|
|
|
|
|
|
|
exit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Get the user comment in attendance sheet. |
|
|
|
|
* |
|
|
|
|
* @param $userId |
|
|
|
|
* @param $attendanceCalendarId |
|
|
|
|
* |
|
|
|
|
* @return false|string |
|
|
|
|
*/ |
|
|
|
|
public function getComment( |
|
|
|
|
$userId, |
|
|
|
|
$attendanceCalendarId |
|
|
|
|
) { |
|
|
|
|
$allowComment = api_get_configuration_value('attendance_allow_comments'); |
|
|
|
|
if (!$allowComment) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$repo = $em->getRepository('ChamiloCourseBundle:CAttendanceSheet'); |
|
|
|
|
|
|
|
|
|
$criteria = [ |
|
|
|
|
'userId' => $userId, |
|
|
|
|
'attendanceCalendarId' => $attendanceCalendarId, |
|
|
|
|
'cId' => $courseId, |
|
|
|
|
]; |
|
|
|
|
$attendanceSheet = $repo->findOneBy($criteria); |
|
|
|
|
|
|
|
|
|
$comment = ""; |
|
|
|
|
if ($attendanceSheet) { |
|
|
|
|
/** @var CAttendanceSheet $attendanceSheet */ |
|
|
|
|
$comment = $attendanceSheet->getComment(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return $comment; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* It saves the user comment from attendance sheet. |
|
|
|
|
* |
|
|
|
|
* @param $userId |
|
|
|
|
* @param $attendanceCalendarId |
|
|
|
|
* @param $comment string |
|
|
|
|
* |
|
|
|
|
* @return false or void when it is saved. |
|
|
|
|
*/ |
|
|
|
|
public function saveComment( |
|
|
|
|
$userId, |
|
|
|
|
$attendanceCalendarId, |
|
|
|
|
$comment, |
|
|
|
|
$attendanceId |
|
|
|
|
) { |
|
|
|
|
$allowComment = api_get_configuration_value('attendance_allow_comments'); |
|
|
|
|
if (!$allowComment) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$courseId = api_get_course_int_id(); |
|
|
|
|
$em = Database::getManager(); |
|
|
|
|
$criteria = [ |
|
|
|
|
'userId' => $userId, |
|
|
|
|
'attendanceCalendarId' => $attendanceCalendarId, |
|
|
|
|
'cId' => $courseId, |
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
$repo = $em->getRepository('ChamiloCourseBundle:CAttendanceSheet'); |
|
|
|
|
$attendanceSheet = $repo->findOneBy($criteria); |
|
|
|
|
|
|
|
|
|
/** @var CAttendanceSheet $attendanceSheet */ |
|
|
|
|
if ($attendanceSheet) { |
|
|
|
|
$attendanceSheet->setComment($comment); |
|
|
|
|
$em->persist($attendanceSheet); |
|
|
|
|
$em->flush(); |
|
|
|
|
} else { |
|
|
|
|
$attendanceSheet = new CAttendanceSheet(); |
|
|
|
|
$attendanceSheet |
|
|
|
|
->setCId($courseId) |
|
|
|
|
->setPresence(0) |
|
|
|
|
->setUserId($userId) |
|
|
|
|
->setAttendanceCalendarId($attendanceCalendarId) |
|
|
|
|
->setComment($comment); |
|
|
|
|
|
|
|
|
|
$em->persist($attendanceSheet); |
|
|
|
|
$em->flush(); |
|
|
|
|
} |
|
|
|
|
$this->updateUsersResults([$userId], $attendanceId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* It saves the user sign from attendance sheet. |
|
|
|
|
* |
|
|
|
|
|