From 0dc8d1f7143d5a9b25f942388cd91b318cf6df0b Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Mon, 15 Jul 2013 15:14:02 +1200 Subject: [PATCH] Prevent too much info in add_to_log - enter first 10 and last session into log --- locallib.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/locallib.php b/locallib.php index 403bebc..76ad0fe 100644 --- a/locallib.php +++ b/locallib.php @@ -795,10 +795,21 @@ class attendance { } $info_array = array(); + $maxlog = 10; // Only log first 10 sessions and last session in the log info. as we can only store 255 chars. + $i = 0; foreach ($sessions as $sess) { - $info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration); + if ($i > $maxlog) { + $lastsession = end($sessions); + $info_array[] = '...'; + $info_array[] = construct_session_full_date_time($lastsession->sessdate, $lastsession->duration); + break; + } else { + $info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration); + } + $i++; } - add_to_log($this->course->id, 'attendance', 'sessions added', $this->url_manage(), implode(',', $info_array), $this->cm->id); + add_to_log($this->course->id, 'attendance', 'sessions added', $this->url_manage(), + implode(',', $info_array), $this->cm->id); } public function update_session_from_form_data($formdata, $sessionid) {