|
@ -329,9 +329,14 @@ class attforblock { |
|
|
|
|
|
|
|
|
private $currentgroup; |
|
|
private $currentgroup; |
|
|
|
|
|
|
|
|
private $sessioninfo; |
|
|
|
|
|
|
|
|
|
|
|
private $statuses; |
|
|
private $statuses; |
|
|
|
|
|
|
|
|
|
|
|
// Cache |
|
|
|
|
|
|
|
|
|
|
|
// array by sessionid |
|
|
|
|
|
private $sessioninfo = array(); |
|
|
|
|
|
|
|
|
// arrays by userid |
|
|
// arrays by userid |
|
|
private $usertakensesscount = array(); |
|
|
private $usertakensesscount = array(); |
|
|
private $userstatusesstat = array(); |
|
|
private $userstatusesstat = array(); |
|
@ -480,7 +485,13 @@ class attforblock { |
|
|
'cgroup' => $this->get_current_group()); |
|
|
'cgroup' => $this->get_current_group()); |
|
|
$sessions = $DB->get_records_select('attendance_sessions', $where, $params, 'sessdate asc'); |
|
|
$sessions = $DB->get_records_select('attendance_sessions', $where, $params, 'sessdate asc'); |
|
|
foreach ($sessions as $sess) { |
|
|
foreach ($sessions as $sess) { |
|
|
$sess->description = file_rewrite_pluginfile_urls($sess->description, 'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); |
|
|
if (empty($sess->description)) { |
|
|
|
|
|
$sess->description = get_string('nodescription', 'attforblock'); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$sess->description = file_rewrite_pluginfile_urls($sess->description, |
|
|
|
|
|
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $sessions; |
|
|
return $sessions; |
|
@ -814,12 +825,36 @@ class attforblock { |
|
|
public function get_session_info($sessionid) { |
|
|
public function get_session_info($sessionid) { |
|
|
global $DB; |
|
|
global $DB; |
|
|
|
|
|
|
|
|
if (!isset($this->sessioninfo)) |
|
|
if (!array_key_exists($sessionid, $this->sessioninfo)) |
|
|
$this->sessioninfo = $DB->get_record('attendance_sessions', array('id' => $sessionid)); |
|
|
$this->sessioninfo[$sessionid] = $DB->get_record('attendance_sessions', array('id' => $sessionid)); |
|
|
$this->sessioninfo->description = file_rewrite_pluginfile_urls($this->sessioninfo->description, |
|
|
if (empty($this->sessioninfo[$sessionid]->description)) { |
|
|
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $this->sessioninfo->id); |
|
|
$this->sessioninfo[$sessionid]->description = get_string('nodescription', 'attforblock'); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$this->sessioninfo[$sessionid]->description = file_rewrite_pluginfile_urls($this->sessioninfo[$sessionid]->description, |
|
|
|
|
|
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $this->sessioninfo[$sessionid]->id); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $this->sessioninfo[$sessionid]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
return $this->sessioninfo; |
|
|
public function get_sessions_info($sessionids) { |
|
|
|
|
|
global $DB; |
|
|
|
|
|
|
|
|
|
|
|
list($sql, $params) = $DB->get_in_or_equal($sessionids); |
|
|
|
|
|
$sessions = $DB->get_records_select('attendance_sessions', "id $sql", $params, 'sessdate asc'); |
|
|
|
|
|
|
|
|
|
|
|
foreach ($sessions as $sess) { |
|
|
|
|
|
if (empty($sess->description)) { |
|
|
|
|
|
$sess->description = get_string('nodescription', 'attforblock'); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$sess->description = file_rewrite_pluginfile_urls($sess->description, |
|
|
|
|
|
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $sessions; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function get_session_log($sessionid) { |
|
|
public function get_session_log($sessionid) { |
|
@ -890,7 +925,7 @@ class attforblock { |
|
|
|
|
|
|
|
|
foreach ($userids as $userid) { |
|
|
foreach ($userids as $userid) { |
|
|
$grades[$userid]->userid = $userid; |
|
|
$grades[$userid]->userid = $userid; |
|
|
$grades[$userid]->rawgrade = $this->get_user_grade($userid) / $this->get_user_max_grade($userid) * 100; |
|
|
$grades[$userid]->rawgrade = calc_user_grade_percent($this->get_user_grade($userid), $this->get_user_max_grade($userid)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return grade_update('mod/attforblock', $this->course->id, 'mod', 'attforblock', |
|
|
return grade_update('mod/attforblock', $this->course->id, 'mod', 'attforblock', |
|
@ -922,11 +957,40 @@ class attforblock { |
|
|
'edate' => $this->pageparams->enddate); |
|
|
'edate' => $this->pageparams->enddate); |
|
|
$sessions = $DB->get_records_sql($sql, $params); |
|
|
$sessions = $DB->get_records_sql($sql, $params); |
|
|
foreach ($sessions as $sess) { |
|
|
foreach ($sessions as $sess) { |
|
|
$sess->description = file_rewrite_pluginfile_urls($sess->description, 'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); |
|
|
if (empty($sess->description)) { |
|
|
|
|
|
$sess->description = get_string('nodescription', 'attforblock'); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
$sess->description = file_rewrite_pluginfile_urls($sess->description, |
|
|
|
|
|
'pluginfile.php', $this->context->id, 'mod_attforblock', 'session', $sess->id); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $sessions; |
|
|
return $sessions; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function delete_sessions($sessionsids) { |
|
|
|
|
|
global $DB; |
|
|
|
|
|
|
|
|
|
|
|
list($sql, $params) = $DB->get_in_or_equal($sessionsids); |
|
|
|
|
|
$DB->delete_records_select('attendance_log', "sessionid $sql", $params); |
|
|
|
|
|
$DB->delete_records_list('attendance_sessions', 'id', $sessionsids); |
|
|
|
|
|
|
|
|
|
|
|
// TODO: log |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function change_sessions_duration($sessionsids, $duration) { |
|
|
|
|
|
global $DB; |
|
|
|
|
|
|
|
|
|
|
|
$now = time(); |
|
|
|
|
|
$sessions = $DB->get_records_list('attendance_sessions', 'id', $sessionsids); |
|
|
|
|
|
foreach ($sessions as $sess) { |
|
|
|
|
|
$sess->duration = $duration; |
|
|
|
|
|
$sess->timemodified = $now; |
|
|
|
|
|
$DB->update_record('attendance_sessions', $sess); |
|
|
|
|
|
} |
|
|
|
|
|
// TODO: log |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1013,19 +1077,26 @@ function get_user_courses_attendances($userid) { |
|
|
return $DB->get_records_sql($sql, $params); |
|
|
return $DB->get_records_sql($sql, $params); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function calc_user_grade_percent($grade, $maxgrade) { |
|
|
|
|
|
if ($maxgrade == 0) |
|
|
|
|
|
return 0; |
|
|
|
|
|
else |
|
|
|
|
|
return $grade / $maxgrade * 100; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
function update_all_users_grades($attid, $course, $context) { |
|
|
function update_all_users_grades($attid, $course, $context) { |
|
|
global $COURSE; |
|
|
global $COURSE; |
|
|
|
|
|
|
|
|
$grades = array(); |
|
|
$grades = array(); |
|
|
|
|
|
|
|
|
$userids = get_enrolled_users($context, 'mod/attforblock:canbelisted', 0, 'u.id'); |
|
|
$userids = array_keys(get_enrolled_users($context, 'mod/attforblock:canbelisted', 0, 'u.id')); |
|
|
|
|
|
|
|
|
$statuses = get_statuses($attid); |
|
|
$statuses = get_statuses($attid); |
|
|
foreach ($userids as $userid) { |
|
|
foreach ($userids as $userid) { |
|
|
$grades[$userid]->userid = $userid; |
|
|
$grades[$userid]->userid = $userid; |
|
|
$userstatusesstat = get_user_statuses_stat($attid, $course->startdate, $userid); |
|
|
$userstatusesstat = get_user_statuses_stat($attid, $course->startdate, $userid); |
|
|
$usertakensesscount = get_user_taken_sessions_count($attid, $course->startdate, $userid); |
|
|
$usertakensesscount = get_user_taken_sessions_count($attid, $course->startdate, $userid); |
|
|
$grades[$userid]->rawgrade = get_user_grade($userstatusesstat, $statuses) / get_user_max_grade($usertakensesscount, $statuses) * 100; |
|
|
$grades[$userid]->rawgrade = calc_user_grade_percent(get_user_grade($userstatusesstat, $statuses), get_user_max_grade($usertakensesscount, $statuses)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return grade_update('mod/attforblock', $course->id, 'mod', 'attforblock', |
|
|
return grade_update('mod/attforblock', $course->id, 'mod', 'attforblock', |
|
|