Browse Source

Implemented logging

MOODLE_23_STABLE
Artem Andreev 14 years ago
parent
commit
b004f67c37
  1. 1
      lang/en/attforblock.php
  2. 1
      lang/ru/attforblock.php
  3. 8
      lib.php
  4. 75
      locallib.php
  5. 6
      renderer.php
  6. 14
      renderhelpers.php
  7. 3
      report.php

1
lang/en/attforblock.php

@ -133,6 +133,7 @@ $string['sessionenddate'] = 'Session end date';
$string['sessionexist'] = 'Session not added (already exists)!';
$string['sessions'] = 'Sessions';
$string['sessionscompleted'] = 'Sessions completed';
$string['sessionsids'] = 'IDs of sessions: ';
$string['sessionsgenerated'] = 'Sessions successfully generated';
$string['sessionstartdate'] = 'Session start date';
$string['sessiontype'] = 'Session type';

1
lang/ru/attforblock.php

@ -116,6 +116,7 @@ $string['sessionenddate'] = 'Дата завершения занятий';
$string['sessionexist'] = 'Занятие не добавлено (уже существует)!';
$string['sessions'] = 'Занятия';
$string['sessionscompleted'] = 'Прошло занятий';
$string['sessionsids'] = 'Идентификаторы занятий: ';
$string['sessionsgenerated'] = 'Занятия успешно созданы';
$string['sessionstartdate'] = 'Дата начала занятий';
$string['sessiontype'] = 'Тип занятия';

8
lib.php

@ -373,14 +373,6 @@ function attforblock_scale_used ($attforblockid, $scaleid) {
//as reference.
$return = false;
//$rec = get_record("attforblock","id","$attforblockid","scale","-$scaleid");
//
//if (!empty($rec) && !empty($scaleid)) {
// $return = true;
//}
return $return;
}
/**

75
locallib.php

@ -4,6 +4,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/gradelib.php');
require_once(dirname(__FILE__).'/renderhelpers.php');
define('VIEW_DAYS', 1);
define('VIEW_WEEKS', 2);
@ -216,7 +217,7 @@ class att_page_with_filter_controls {
global $USER, $SESSION;
if (!array_key_exists('attsessiontype', $SESSION)) {
$SESSION->attsessiontype = array();
$SESSION->attsessiontype = array($this->cm->course => self::SESSTYPE_ALL);
}
elseif (!array_key_exists($this->cm->course, $SESSION->attsessiontype)) {
$SESSION->attsessiontype[$this->cm->course] = self::SESSTYPE_ALL;
@ -709,22 +710,23 @@ class attforblock {
public function add_sessions($sessions) {
global $DB;
$sessionsids = array();
foreach ($sessions as $sess) {
$sess->attendanceid = $this->id;
$sid = $DB->insert_record('attendance_sessions', $sess);
$sess->id = $DB->insert_record('attendance_sessions', $sess);
$description = file_save_draft_area_files($sess->descriptionitemid,
$this->context->id, 'mod_attforblock', 'session', $sid,
$this->context->id, 'mod_attforblock', 'session', $sess->id,
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0),
$sess->description);
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $sid));
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $sess->id));
}
$sessionsids[] = $sid;
$info_array = array();
foreach ($sessions as $sess) {
$info_array[] = construct_session_full_date_time($sess->sessdate, $sess->duration);
}
// TODO: log
//add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
$this->log('sessions added', $this->url_manage(), implode(', ', $info_array));
}
public function update_session_from_form_data($formdata, $sessionid) {
@ -743,8 +745,10 @@ class attforblock {
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->timemodified = time();
$DB->update_record('attendance_sessions', $sess);
// TODO: log
// add_to_log($course->id, 'attendance', 'Session updated', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
$url = $this->url_sessions(array('sessionid' => $sessionid, 'action' => att_sessions_page_params::ACTION_UPDATE));
$info = construct_session_full_date_time($sess->sessdate, $sess->duration);
$this->log('session updated', $url, $info);
}
public function take_from_form_data($formdata) {
@ -787,7 +791,13 @@ class attforblock {
$DB->update_record('attendance_sessions', $rec);
$this->update_users_grade(array_keys($sesslog));
// TODO: log
$params = array(
'sessionid' => $this->pageparams->sessionid,
'grouptype' => $this->pageparams->grouptype);
$url = $this->url_take($params);
$this->log('attendance taked', $url, $USER->firstname.' '.$USER->lastname);
redirect($this->url_manage(), get_string('attendancesuccess','attforblock'));
}
@ -1052,7 +1062,7 @@ class attforblock {
$DB->delete_records_select('attendance_log', "sessionid $sql", $params);
$DB->delete_records_list('attendance_sessions', 'id', $sessionsids);
// TODO: log
$this->log('sessions deleted', null, get_string('sessionsids', 'attforblock').implode(', ', $sessionsids));
}
public function update_sessions_duration($sessionsids, $duration) {
@ -1065,7 +1075,8 @@ class attforblock {
$sess->timemodified = $now;
$DB->update_record('attendance_sessions', $sess);
}
// TODO: log
$this->log('sessions duration updated', $this->url_manage(), get_string('sessionsids', 'attforblock').implode(', ', $sessionsids));
}
public function remove_status($statusid) {
@ -1086,8 +1097,7 @@ class attforblock {
$rec->grade = $grade;
$DB->insert_record('attendance_statuses', $rec);
// TODO: log
//add_to_log($course->id, 'attendance', 'setting added', 'mod/attforblock/attsettings.php?course='.$course->id, $user->lastname.' '.$user->firstname);
$this->log('status added', $this->url_preferences(), $acronym.': '.$description.' ('.$grade.')');
} else {
print_error('cantaddstatus', 'attforblock', $this->url_preferences());
}
@ -1118,7 +1128,27 @@ class attforblock {
}
$DB->update_record('attendance_statuses', $status);
// TODO: log
$this->log('status updated', $this->url_preferences(), implode(' ', $updated));
}
/**
* wrapper around {@see add_to_log()}
*
* @param string $action to be logged
* @param moodle_url $url absolute url, if null will be used $this->url_manage()
* @param mixed $info additional info, usually id in a table
*/
public function log($action, moodle_url $url = null, $info = null) {
if (is_null($url)) {
$url = $this->url_manage();
}
if (is_null($info)) {
$info = $this->id;
}
$logurl = log_convert_url($url);
add_to_log($this->course->id, 'attforblock', $action, $logurl, $info, $this->cm->id);
}
}
@ -1238,4 +1268,15 @@ function has_logs_for_status($statusid) {
return $DB->count_records('attendance_log', array('statusid'=> $statusid)) > 0;
}
function log_convert_url(moodle_url $fullurl) {
static $baseurl;
if (!isset($baseurl)) {
$baseurl = new moodle_url('/mod/attforblock/');
$baseurl = $baseurl->out();
}
return substr($fullurl->out(), strlen($baseurl));
}
?>

6
renderer.php

@ -151,8 +151,6 @@ class mod_attforblock_renderer extends plugin_renderer_base {
* @return string html code
*/
protected function render_attforblock_manage_data(attforblock_manage_data $sessdata) {
// TODO: nosessionexists
// TODO: log
$o = $this->render_sess_manage_table($sessdata) . $this->render_sess_manage_control($sessdata);
$o = html_writer::tag('form', $o, array('method' => 'post', 'action' => $sessdata->url_sessions()->out()));
$o = $this->output->container($o, 'generalbox attwidth');
@ -645,9 +643,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
}
private function construct_time($datetime, $duration) {
$starttime = userdate($datetime, get_string('strftimehm', 'attforblock'));
$endtime = userdate($datetime + $duration, get_string('strftimehm', 'attforblock'));
$time = html_writer::tag('nobr', $starttime . ($duration > 0 ? ' - ' . $endtime : ''));
$time = html_writer::tag('nobr', construct_session_time($datetime, $duration));
return $time;
}

14
renderhelpers.php

@ -154,4 +154,18 @@ class user_sessions_cells_text_generator extends user_sessions_cells_generator {
}
}
function construct_session_time($datetime, $duration) {
$starttime = userdate($datetime, get_string('strftimehm', 'attforblock'));
$endtime = userdate($datetime + $duration, get_string('strftimehm', 'attforblock'));
return $starttime . ($duration > 0 ? ' - ' . $endtime : '');
}
function construct_session_full_date_time($datetime, $duration) {
$sessinfo = userdate($datetime, get_string('strftimedmyw', 'attforblock'));
$sessinfo .= ' '.construct_session_time($datetime, $duration);
return $sessinfo;
}
?>

3
report.php

@ -44,7 +44,8 @@ $tabs = new attforblock_tabs($att, attforblock_tabs::TAB_REPORT);
$filtercontrols = new attforblock_filter_controls($att);
$reportdata = new attforblock_report_data($att);
// TODO: log
global $USER;
$att->log('report viewed', null, $USER->firstname.' '.$USER->lastname);
/// Output starts here

Loading…
Cancel
Save