|
@ -14,7 +14,13 @@ |
|
|
// You should have received a copy of the GNU General Public License |
|
|
// You should have received a copy of the GNU General Public License |
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
|
|
|
/// Library of functions and constants for module attforblock |
|
|
/** |
|
|
|
|
|
* Library of functions and constants for module attforblock |
|
|
|
|
|
* |
|
|
|
|
|
* @package mod_attendance |
|
|
|
|
|
* @copyright 2011 Artem Andreev <andreev.artem@gmail.com> |
|
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* Returns the information if the module supports a feature |
|
|
* Returns the information if the module supports a feature |
|
@ -68,7 +74,7 @@ function attforblock_add_instance($attforblock) { |
|
|
att_add_default_statuses($attforblock->id); |
|
|
att_add_default_statuses($attforblock->id); |
|
|
|
|
|
|
|
|
attforblock_grade_item_update($attforblock); |
|
|
attforblock_grade_item_update($attforblock); |
|
|
// attforblock_update_grades($attforblock); |
|
|
//attforblock_update_grades($attforblock); |
|
|
return $attforblock->id; |
|
|
return $attforblock->id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -100,11 +106,11 @@ function attforblock_delete_instance($id) { |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($sessids = array_keys($DB->get_records('attendance_sessions', array('attendanceid'=> $id), '', 'id'))) { |
|
|
if ($sessids = array_keys($DB->get_records('attendance_sessions', array('attendanceid'=> $id), '', 'id'))) { |
|
|
$DB->delete_records_list('attendance_log', 'sessionid', $sessids); |
|
|
$DB->delete_records_list('attendance_log', 'sessionid', $sessids); |
|
|
$DB->delete_records('attendance_sessions', array('attendanceid'=> $id)); |
|
|
$DB->delete_records('attendance_sessions', array('attendanceid'=> $id)); |
|
|
} |
|
|
} |
|
|
$DB->delete_records('attendance_statuses', array('attendanceid'=> $id)); |
|
|
$DB->delete_records('attendance_statuses', array('attendanceid'=> $id)); |
|
|
|
|
|
|
|
|
$DB->delete_records('attforblock', array('id'=> $id)); |
|
|
$DB->delete_records('attforblock', array('id'=> $id)); |
|
|
|
|
|
|
|
@ -124,7 +130,7 @@ function attforblock_delete_course($course, $feedback=true){ |
|
|
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); |
|
|
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); |
|
|
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); |
|
|
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); |
|
|
} |
|
|
} |
|
|
$DB->delete_records('attforblock', array('course'=> $course->id)); |
|
|
$DB->delete_records('attforblock', array('course'=> $course->id)); |
|
|
|
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
@ -136,8 +142,8 @@ function attforblock_delete_course($course, $feedback=true){ |
|
|
function attforblock_reset_course_form_definition(&$mform) { |
|
|
function attforblock_reset_course_form_definition(&$mform) { |
|
|
$mform->addElement('header', 'attendanceheader', get_string('modulename', 'attforblock')); |
|
|
$mform->addElement('header', 'attendanceheader', get_string('modulename', 'attforblock')); |
|
|
|
|
|
|
|
|
$mform->addElement('static', 'description', get_string('description', 'attforblock'), |
|
|
$mform->addElement('static', 'description', get_string('description', 'attforblock'), |
|
|
get_string('resetdescription', 'attforblock')); |
|
|
get_string('resetdescription', 'attforblock')); |
|
|
$mform->addElement('checkbox', 'reset_attendance_log', get_string('deletelogs','attforblock')); |
|
|
$mform->addElement('checkbox', 'reset_attendance_log', get_string('deletelogs','attforblock')); |
|
|
|
|
|
|
|
|
$mform->addElement('checkbox', 'reset_attendance_sessions', get_string('deletesessions','attforblock')); |
|
|
$mform->addElement('checkbox', 'reset_attendance_sessions', get_string('deletesessions','attforblock')); |
|
@ -163,7 +169,7 @@ function attforblock_reset_userdata($data) { |
|
|
$attids = array_keys($DB->get_records('attforblock', array('course'=> $data->courseid), '', 'id')); |
|
|
$attids = array_keys($DB->get_records('attforblock', array('course'=> $data->courseid), '', 'id')); |
|
|
|
|
|
|
|
|
if (!empty($data->reset_attendance_log)) { |
|
|
if (!empty($data->reset_attendance_log)) { |
|
|
$sess = $DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'); |
|
|
$sess = $DB->get_records_list('attendance_sessions', 'attendanceid', $attids, '', 'id'); |
|
|
if (!empty($sess)) { |
|
|
if (!empty($sess)) { |
|
|
list($sql, $params) = $DB->get_in_or_equal(array_keys($sess)); |
|
|
list($sql, $params) = $DB->get_in_or_equal(array_keys($sess)); |
|
|
$DB->delete_records_select('attendance_log', "sessionid $sql", $params); |
|
|
$DB->delete_records_select('attendance_log', "sessionid $sql", $params); |
|
@ -179,7 +185,7 @@ function attforblock_reset_userdata($data) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!empty($data->reset_attendance_statuses)) { |
|
|
if (!empty($data->reset_attendance_statuses)) { |
|
|
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); |
|
|
$DB->delete_records_list('attendance_statuses', 'attendanceid', $attids); |
|
|
foreach($attids as $attid) { |
|
|
foreach($attids as $attid) { |
|
|
att_add_default_statuses($attid); |
|
|
att_add_default_statuses($attid); |
|
|
} |
|
|
} |
|
@ -192,7 +198,7 @@ function attforblock_reset_userdata($data) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!empty($data->reset_attendance_sessions)) { |
|
|
if (!empty($data->reset_attendance_sessions)) { |
|
|
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); |
|
|
$DB->delete_records_list('attendance_sessions', 'attendanceid', $attids); |
|
|
|
|
|
|
|
|
$status[] = array( |
|
|
$status[] = array( |
|
|
'component' => get_string('modulenameplural', 'attforblock'), |
|
|
'component' => get_string('modulenameplural', 'attforblock'), |
|
@ -224,15 +230,15 @@ function attforblock_user_outline($course, $user, $mod, $attforblock) { |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
$result->time = 0; |
|
|
$result->time = 0; |
|
|
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { |
|
|
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { |
|
|
$statuses = att_get_statuses($attforblock->id); |
|
|
$statuses = att_get_statuses($attforblock->id); |
|
|
$grade = att_get_user_grade(att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id), $statuses); |
|
|
$grade = att_get_user_grade(att_get_user_statuses_stat($attforblock->id, $course->startdate, $user->id), $statuses); |
|
|
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses); |
|
|
$maxgrade = att_get_user_max_grade(att_get_user_taken_sessions_count($attforblock->id, $course->startdate, $user->id), $statuses); |
|
|
|
|
|
|
|
|
$result->info = $grade.' / '.$maxgrade; |
|
|
$result->info = $grade.' / '.$maxgrade; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $result; |
|
|
return $result; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function attforblock_user_complete($course, $user, $mod, $attforblock) { |
|
|
function attforblock_user_complete($course, $user, $mod, $attforblock) { |
|
@ -243,9 +249,9 @@ function attforblock_user_complete($course, $user, $mod, $attforblock) { |
|
|
require_once(dirname(__FILE__).'/renderhelpers.php'); |
|
|
require_once(dirname(__FILE__).'/renderhelpers.php'); |
|
|
require_once($CFG->libdir.'/gradelib.php'); |
|
|
require_once($CFG->libdir.'/gradelib.php'); |
|
|
|
|
|
|
|
|
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { |
|
|
if (has_capability('mod/attforblock:canbelisted', $mod->context, $user->id)) { |
|
|
echo construct_full_user_stat_html_table($attforblock, $course, $user); |
|
|
echo construct_full_user_stat_html_table($attforblock, $course, $user); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//return true; |
|
|
//return true; |
|
|
} |
|
|
} |
|
@ -276,7 +282,7 @@ function attforblock_cron () { |
|
|
/*function attforblock_get_user_grades($attforblock, $userid=0) { |
|
|
/*function attforblock_get_user_grades($attforblock, $userid=0) { |
|
|
global $CFG, $DB; |
|
|
global $CFG, $DB; |
|
|
|
|
|
|
|
|
require_once('_locallib.php'); |
|
|
require_once('_locallib.php'); |
|
|
|
|
|
|
|
|
if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) { |
|
|
if (! $course = $DB->get_record('course', array('id'=> $attforblock->course))) { |
|
|
error("Course is misconfigured"); |
|
|
error("Course is misconfigured"); |
|
@ -284,17 +290,17 @@ function attforblock_cron () { |
|
|
|
|
|
|
|
|
$result = false; |
|
|
$result = false; |
|
|
if ($userid) { |
|
|
if ($userid) { |
|
|
$result = array(); |
|
|
$result = array(); |
|
|
$result[$userid]->userid = $userid; |
|
|
$result[$userid]->userid = $userid; |
|
|
$result[$userid]->rawgrade = $attforblock->grade * get_percent($userid, $course, $attforblock) / 100; |
|
|
$result[$userid]->rawgrade = $attforblock->grade * get_percent($userid, $course, $attforblock) / 100; |
|
|
} else { |
|
|
} else { |
|
|
if ($students = get_course_students($course->id)) { |
|
|
if ($students = get_course_students($course->id)) { |
|
|
$result = array(); |
|
|
$result = array(); |
|
|
foreach ($students as $student) { |
|
|
foreach ($students as $student) { |
|
|
$result[$student->id]->userid = $student->id; |
|
|
$result[$student->id]->userid = $student->id; |
|
|
$result[$student->id]->rawgrade = $attforblock->grade * get_percent($student->id, $course, $attforblock) / 100; |
|
|
$result[$student->id]->rawgrade = $attforblock->grade * get_percent($student->id, $course, $attforblock) / 100; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return $result; |
|
|
return $result; |
|
@ -351,7 +357,7 @@ function attforblock_cron () { |
|
|
function attforblock_grade_item_update($attforblock, $grades=NULL) { |
|
|
function attforblock_grade_item_update($attforblock, $grades=NULL) { |
|
|
global $CFG, $DB; |
|
|
global $CFG, $DB; |
|
|
|
|
|
|
|
|
require_once('locallib.php'); |
|
|
require_once('locallib.php'); |
|
|
|
|
|
|
|
|
if (!function_exists('grade_update')) { //workaround for buggy PHP versions |
|
|
if (!function_exists('grade_update')) { //workaround for buggy PHP versions |
|
|
require_once($CFG->libdir.'/gradelib.php'); |
|
|
require_once($CFG->libdir.'/gradelib.php'); |
|
|