Browse Source

Added "mod_attendance_get_sessions" API function

40-behatfixes
Peter Rundqvist 3 years ago
parent
commit
c349f489d9
  1. 20
      classes/attendance_webservices_handler.php
  2. 11
      db/services.php
  3. 61
      externallib.php

20
classes/attendance_webservices_handler.php

@ -158,4 +158,24 @@ class attendance_handler {
$DB->update_record('attendance_sessions', $attendancesession);
}
}
/**
* For this attendance instance, returns all sessions.
*
* @param int $attendanceid
* @return mixed
*/
public static function get_sessions($attendanceid) {
global $DB;
$sessions = $DB->get_records('attendance_sessions', array('attendanceid' => $attendanceid), 'id ASC');
$sessionsinfo = array();
foreach($sessions as $session) {
$sessionsinfo[$session->id] = self::get_session($session->id);
}
return $sessionsinfo;
}
}

11
db/services.php

@ -67,13 +67,19 @@ $functions = array(
'description' => 'Method that retrieves the session data',
'type' => 'read',
),
'mod_attendance_update_user_status' => array(
'classname' => 'mod_attendance_external',
'methodname' => 'update_user_status',
'classpath' => 'mod/attendance/externallib.php',
'description' => 'Method that updates the user status in a session.',
'type' => 'write',
),
'mod_attendance_get_sessions' => array(
'classname' => 'mod_attendance_external',
'methodname' => 'get_sessions',
'classpath' => 'mod/attendance/externallib.php',
'description' => 'Method that retrieves the sessions in an attendance instance.',
'type' => 'read',
)
);
@ -88,7 +94,8 @@ $services = array(
'mod_attendance_remove_session',
'mod_attendance_get_courses_with_today_sessions',
'mod_attendance_get_session',
'mod_attendance_update_user_status'
'mod_attendance_update_user_status',
'mod_attendance_get_sessions'
),
'restrictedusers' => 0,
'enabled' => 1,

61
externallib.php

@ -543,4 +543,65 @@ class mod_attendance_external extends external_api {
public static function update_user_status_returns() {
return new external_value(PARAM_TEXT, 'Http code');
}
/**
* Get sessions params.
*
* @return external_function_parameters
*/
public static function get_sessions_parameters() {
return new external_function_parameters(
array(
'attendanceid' => new external_value(PARAM_INT, 'Attendance id.', VALUE_REQUIRED),
)
);
}
/**
* Describes get_sessions return values.
*
* @return external_multiple_structure
*/
public static function get_sessions_returns() {
$statuses = array('id' => new external_value(PARAM_INT, 'Status id.'),
'attendanceid' => new external_value(PARAM_INT, 'Attendance id.'),
'acronym' => new external_value(PARAM_TEXT, 'Status acronym.'),
'description' => new external_value(PARAM_TEXT, 'Status description.'),
'grade' => new external_value(PARAM_FLOAT, 'Status grade.'),
'visible' => new external_value(PARAM_INT, 'Status visibility.'),
'deleted' => new external_value(PARAM_INT, 'informs if this session was deleted.'),
'setnumber' => new external_value(PARAM_INT, 'Set number.'));
$users = array('id' => new external_value(PARAM_INT, 'User id.'),
'firstname' => new external_value(PARAM_TEXT, 'User first name.'),
'lastname' => new external_value(PARAM_TEXT, 'User last name.'));
$attendancelog = array('studentid' => new external_value(PARAM_INT, 'Student id.'),
'statusid' => new external_value(PARAM_TEXT, 'Status id (last time).'),
'remarks' => new external_value(PARAM_TEXT, 'Last remark.'),
'id' => new external_value(PARAM_TEXT, 'log id.'));
$session = self::get_session_structure();
$session['courseid'] = new external_value(PARAM_INT, 'Course moodle id.');
$session['statuses'] = new external_multiple_structure(new external_single_structure($statuses));
$session['attendance_log'] = new external_multiple_structure(new external_single_structure($attendancelog));
$session['users'] = new external_multiple_structure(new external_single_structure($users));
return new external_multiple_structure(new external_single_structure(($session)));
}
/**
* Get sessions.
*
* @param int $attendanceid
*/
public static function get_sessions($attendanceid) {
global $DB;
$params = self::validate_parameters(self::get_sessions_parameters(), array(
'attendanceid' => $attendanceid,
));
return attendance_handler::get_sessions($params['attendanceid']);
}
}

Loading…
Cancel
Save