Browse Source

Fix externallib (#431)

MOODLE_37_STABLE
Ruslan Kabalin 5 years ago
committed by Dan Marsden
parent
commit
622fd3bfcb
  1. 28
      externallib.php
  2. 2
      tests/generator/lib.php

28
externallib.php

@ -148,16 +148,18 @@ class mod_wsattendance_external extends external_api {
require_capability('mod/attendance:manageattendances', $context); require_capability('mod/attendance:manageattendances', $context);
// Delete attendance instance. // Delete attendance instance.
attendance_delete_instance($params['attendanceid']); $result = attendance_delete_instance($params['attendanceid']);
rebuild_course_cache($cm->course, true); rebuild_course_cache($cm->course, true);
return $result;
} }
/** /**
* Describes remove_attendance return values. * Describes remove_attendance return values.
* *
* @return void * @return external_value
*/ */
public static function remove_attendance_returns() { public static function remove_attendance_returns() {
return new external_value(PARAM_BOOL, 'attendance deletion result');
} }
/** /**
@ -286,7 +288,7 @@ class mod_wsattendance_external extends external_api {
* Delete session from attendance instance. * Delete session from attendance instance.
* *
* @param int $sessionid * @param int $sessionid
* @return int $sessionid * @return bool
*/ */
public static function remove_session(int $sessionid) { public static function remove_session(int $sessionid) {
global $DB; global $DB;
@ -310,14 +312,17 @@ class mod_wsattendance_external extends external_api {
// Delete session. // Delete session.
$attendance->delete_sessions(array($sessionid)); $attendance->delete_sessions(array($sessionid));
attendance_update_users_grade($attendance); attendance_update_users_grade($attendance);
return true;
} }
/** /**
* Describes remove_session return values. * Describes remove_session return values.
* *
* @return void * @return external_value
*/ */
public static function remove_session_returns() { public static function remove_session_returns() {
return new external_value(PARAM_BOOL, 'attendance session deletion result');
} }
/** /**
@ -494,6 +499,8 @@ class mod_wsattendance_external extends external_api {
* @param int $statusset * @param int $statusset
*/ */
public static function update_user_status($sessionid, $studentid, $takenbyid, $statusid, $statusset) { public static function update_user_status($sessionid, $studentid, $takenbyid, $statusid, $statusset) {
global $DB;
$params = self::validate_parameters(self::update_user_status_parameters(), array( $params = self::validate_parameters(self::update_user_status_parameters(), array(
'sessionid' => $sessionid, 'sessionid' => $sessionid,
'studentid' => $studentid, 'studentid' => $studentid,
@ -502,12 +509,21 @@ class mod_wsattendance_external extends external_api {
'statusset' => $statusset, 'statusset' => $statusset,
)); ));
// Make sure session is open for marking.
$session = $DB->get_record('attendance_sessions', array('id' => $params['sessionid']), '*', MUST_EXIST); $session = $DB->get_record('attendance_sessions', array('id' => $params['sessionid']), '*', MUST_EXIST);
list($canmark, $reason) = attendance_can_student_mark($attforsession); $cm = get_coursemodule_from_instance('attendance', $session->attendanceid, 0, false, MUST_EXIST);
// Check permissions.
$context = context_module::instance($cm->id);
self::validate_context($context);
require_capability('mod/attendance:view', $context);
// If not a teacher, make sure session is open for self-marking.
if (!has_capability('mod/attendance:takeattendances', $context)) {
list($canmark, $reason) = attendance_can_student_mark($session);
if (!$canmark) { if (!$canmark) {
throw new invalid_parameter_exception($reason); throw new invalid_parameter_exception($reason);
} }
}
// Check user id is valid. // Check user id is valid.
$student = $DB->get_record('user', array('id' => $params['studentid']), '*', MUST_EXIST); $student = $DB->get_record('user', array('id' => $params['studentid']), '*', MUST_EXIST);

2
tests/generator/lib.php

@ -40,7 +40,7 @@ class mod_attendance_generator extends testing_module_generator {
* *
* @param array|stdClass $record * @param array|stdClass $record
* @param array $options * @param array $options
* @return stdClass activity record with extra cmid field * @return stdClass mod_attendance_structure
*/ */
public function create_instance($record = null, array $options = null) { public function create_instance($record = null, array $options = null) {
global $CFG; global $CFG;

Loading…
Cancel
Save