bump version.
[moodle-mod_attendance.git] / externallib.php
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16 /**
17 *
18 * @package local_attendance
19 * @copyright 2015 Caio Bressan Doneda
20 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
21 */
22
23 defined('MOODLE_INTERNAL') || die;
24
25 require_once("$CFG->libdir/externallib.php");
26 require_once(dirname(__FILE__).'/classes/attendance_webservices_handler.php');
27
28 class mod_wsattendance_external extends external_api {
29
30 public static function get_courses_with_today_sessions_parameters() {
31 return new external_function_parameters (
32 array('userid' => new external_value(PARAM_INT, 'User id.', VALUE_DEFAULT, 0)));
33 }
34
35 public static function get_courses_with_today_sessions($userid) {
36 return attendance_handler::get_courses_with_today_sessions($userid);
37 }
38
39 private static function get_session_structure() {
40 $session = array('id' => new external_value(PARAM_INT, 'Session id.'),
41 'attendanceid' => new external_value(PARAM_INT, 'Attendance id.'),
42 'groupid' => new external_value(PARAM_INT, 'Group id.'),
43 'sessdate' => new external_value(PARAM_INT, 'Session date.'),
44 'duration' => new external_value(PARAM_INT, 'Session duration.'),
45 'lasttaken' => new external_value(PARAM_INT, 'Session last taken time.'),
46 'lasttakenby' => new external_value(PARAM_INT, 'ID of the last user that took this session.'),
47 'timemodified' => new external_value(PARAM_INT, 'Time modified.'),
48 'description' => new external_value(PARAM_TEXT, 'Session description.'),
49 'descriptionformat' => new external_value(PARAM_INT, 'Session description format.'),
50 'studentscanmark' => new external_value(PARAM_INT, 'Students can mark their own presence.'),
51 'statusset' => new external_value(PARAM_INT, 'Session statusset.'));
52
53 return $session;
54 }
55
56 public static function get_courses_with_today_sessions_returns() {
57 $todaysessions = self::get_session_structure();
58
59 $attendanceinstances = array('name' => new external_value(PARAM_TEXT, 'Attendance name.'),
60 'today_sessions' => new external_multiple_structure(
61 new external_single_structure($todaysessions)));
62
63 $courses = array('shortname' => new external_value(PARAM_TEXT, 'short name of a moodle course.'),
64 'fullname' => new external_value(PARAM_TEXT, 'full name of a moodle course.'),
65 'attendance_instances' => new external_multiple_structure(
66 new external_single_structure($attendanceinstances)));
67
68 return new external_multiple_structure(new external_single_structure(($courses)));
69 }
70
71 public static function get_session_parameters() {
72 return new external_function_parameters (
73 array('sessionid' => new external_value(PARAM_INT, 'session id')));
74 }
75
76 public static function get_session($sessionid) {
77 return attendance_handler::get_session($sessionid);
78 }
79
80 public static function get_session_returns() {
81 $statuses = array('id' => new external_value(PARAM_INT, 'Status id.'),
82 'attendanceid' => new external_value(PARAM_INT, 'Attendance id.'),
83 'acronym' => new external_value(PARAM_TEXT, 'Status acronym.'),
84 'description' => new external_value(PARAM_TEXT, 'Status description.'),
85 'grade' => new external_value(PARAM_FLOAT, 'Status grade.'),
86 'visible' => new external_value(PARAM_INT, 'Status visibility.'),
87 'deleted' => new external_value(PARAM_INT, 'informs if this session was deleted.'),
88 'setnumber' => new external_value(PARAM_INT, 'Set number.'));
89
90 $users = array('id' => new external_value(PARAM_INT, 'User id.'),
91 'firstname' => new external_value(PARAM_TEXT, 'User first name.'),
92 'lastname' => new external_value(PARAM_TEXT, 'User last name.'));
93
94 $attendancelog = array('studentid' => new external_value(PARAM_INT, 'Student id.'),
95 'statusid' => new external_value(PARAM_TEXT, 'Status id (last time).'),
96 'remarks' => new external_value(PARAM_TEXT, 'Last remark.'),
97 'id' => new external_value(PARAM_TEXT, 'log id.'));
98
99 $session = self::get_session_structure();
100 $session['courseid'] = new external_value(PARAM_INT, 'Course moodle id.');
101 $session['statuses'] = new external_multiple_structure(new external_single_structure($statuses));
102 $session['attendance_log'] = new external_multiple_structure(new external_single_structure($attendancelog));
103 $session['users'] = new external_multiple_structure(new external_single_structure($users));
104
105 return new external_single_structure($session);
106 }
107
108 public static function update_user_status_parameters() {
109 return new external_function_parameters(
110 array('sessionid' => new external_value(PARAM_INT, 'Session id'),
111 'studentid' => new external_value(PARAM_INT, 'Student id'),
112 'takenbyid' => new external_value(PARAM_INT, 'Id of the user who took this session'),
113 'statusid' => new external_value(PARAM_INT, 'Status id'),
114 'statusset' => new external_value(PARAM_TEXT, 'Status set of session')));
115 }
116
117 public static function update_user_status($sessionid, $studentid, $takenbyid, $statusid, $statusset) {
118 return attendance_handler::update_user_status($sessionid, $studentid, $takenbyid, $statusid, $statusset);
119 }
120
121 public static function update_user_status_returns() {
122 return new external_value(PARAM_TEXT, 'Http code');
123 }
124 }