Browse Source

WIP Teacher submission form.

MOODLE_36_STABLE
Dan Marsden 6 years ago
parent
commit
d6236c255d
  1. 110
      classes/output/mobile.php
  2. 1
      classes/structure.php
  3. 8
      db/mobile.php
  4. 4
      mobilestyles.css
  5. 74
      templates/mobile_teacher_form.mustache
  6. 4
      templates/mobile_user_form.mustache

110
classes/output/mobile.php

@ -43,12 +43,11 @@ class mobile {
require_once($CFG->dirroot.'/mod/attendance/locallib.php'); require_once($CFG->dirroot.'/mod/attendance/locallib.php');
$args = (object) $args; $cmid = $args['cmid'];
$cmid = $args->cmid; $courseid = $args['courseid'];
$courseid = $args->courseid; $takenstatus = empty($args['status']) ? '' : $args['status'];
$takenstatus = empty($args->status) ? '' : $args->status; $sessid = empty($args['sessid']) ? '' : $args['sessid'];
$sessid = empty($args->sessid) ? '' : $args->sessid; $password = empty($args['studentpass']) ? '' : $args['studentpass'];
$password = empty($args->studentpass) ? '' : $args->studentpass;
// Capabilities check. // Capabilities check.
$cm = get_coursemodule_from_id('attendance', $cmid); $cm = get_coursemodule_from_id('attendance', $cmid);
@ -70,7 +69,7 @@ class mobile {
$isteacher = false; $isteacher = false;
if (has_capability('mod/attendance:takeattendances', $context)) { if (has_capability('mod/attendance:takeattendances', $context)) {
$isteacher = true; $isteacher = true;
$data['attendancefunction'] = 'mobile_take_attendance_all'; $data['attendancefunction'] = 'mobile_teacher_form';
} }
// Add stats for this use to output. // Add stats for this use to output.
@ -84,18 +83,30 @@ class mobile {
$att = new \mod_attendance_structure($attendance, $cm, $course, $context, $pageparams); $att = new \mod_attendance_structure($attendance, $cm, $course, $context, $pageparams);
if ($isteacher) {
$keys = array_keys($args);
$userkeys = preg_grep("/status\d+/", $keys);
if (!empty($userkeys)) { // If this is a post from the teacher form.
// Build data to pass to take_from_form_data.
foreach ($userkeys as $uk) {
$userid = str_replace('status', '', $uk);
$status = $args[$uk];
}
// Call take_from_form_data function.
// $att->take_from_form_data($formdata);
}
}
// Get list of sessions within the next 24hrs and in last 6hrs. // Get list of sessions within the next 24hrs and in last 6hrs.
// TODO: provide way of adjusting which sessions to show in app. // TODO: provide way of adjusting which sessions to show in app.
$time = time() - (6 * 60 * 60); $time = time() - (6 * 60 * 60);
$data['sessions'] = array(); $data['sessions'] = array();
if ($isteacher) { $sessions = $DB->get_records_select('attendance_sessions',
$sessions = array(); // Support for teacher marking not implemented yet. 'attendanceid = ? AND sessdate > ? ORDER BY sessdate', array($attendance->id, $time));
} else {
$sessions = $DB->get_records_select('attendance_sessions',
'attendanceid = ? AND sessdate > ? ORDER BY sessdate', array($attendance->id, $time));
}
if (!empty($sessions)) { if (!empty($sessions)) {
$userdata = new \attendance_user_data($att, $USER->id, true); $userdata = new \attendance_user_data($att, $USER->id, true);
@ -205,6 +216,7 @@ class mobile {
'otherdata' => '' 'otherdata' => ''
]; ];
} }
/** /**
* Returns the form to take attendance for the mobile app. * Returns the form to take attendance for the mobile app.
* *
@ -305,4 +317,76 @@ class mobile {
'otherdata' => '' 'otherdata' => ''
]; ];
} }
/**
* Returns the form to take attendance for the mobile app.
*
* @param array $args Arguments from tool_mobile_get_content WS
* @return array HTML, javascript and other data
*/
public static function mobile_teacher_form($args) {
global $OUTPUT, $DB, $CFG;
require_once($CFG->dirroot.'/mod/attendance/locallib.php');
$args = (object) $args;
$cmid = $args->cmid;
$courseid = $args->courseid;
$sessid = $args->sessid;
// Capabilities check.
$cm = get_coursemodule_from_id('attendance', $cmid);
require_login($courseid, false , $cm, true, true);
$context = \context_module::instance($cm->id);
require_capability('mod/attendance:takeattendances', $context);
$attendance = $DB->get_record('attendance', array('id' => $cm->instance), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$pageparams = new \mod_attendance_sessions_page_params();
$pageparams->sessionid = $sessid;
$att = new \mod_attendance_structure($attendance, $cm, $course, $context, $pageparams);
$data = array(); // Data to pass to renderer.
$data['attendance'] = $attendance;
$data['cmid'] = $cmid;
$data['courseid'] = $courseid;
$data['sessid'] = $sessid;
$data['messages'] = array();
$data['showmessage'] = false;
$data['statuses'] = array();
$data['args'] = ''; // Stores list of userid status args that should be added to form post.
$statuses = $att->get_statuses();
foreach ($statuses as $status) {
$data['statuses'][] = array('stid' => $status->id, 'acronym' => $status->acronym,
'description' => $status->description);
}
// TODO: Add support for group marking (non-editing teachers etc).
$data['users'] = array();
$users = $att->get_users(0, 0);
foreach ($users as $user) {
$data['users'][] = array('userid' => $user->id, 'fullname' => $user->fullname);
$data['args'] .= ', status'. $user->id. ': status'. $user->id;
}
if (!empty($data['messages'])) {
$data['showmessage'] = true;
}
return [
'templates' => [
[
'id' => 'main',
'html' => $OUTPUT->render_from_template('mod_attendance/mobile_teacher_form', $data),
'cache-view' => false
],
],
'javascript' => '',
'otherdata' => ''
];
}
} }

1
classes/structure.php

@ -843,6 +843,7 @@ class mod_attendance_structure {
$enrolments = $DB->get_records_sql($sql, $params); $enrolments = $DB->get_records_sql($sql, $params);
foreach ($users as $user) { foreach ($users as $user) {
$users[$user->id]->fullname = fullname($user);
$users[$user->id]->enrolmentstatus = $enrolments[$user->id]->status; $users[$user->id]->enrolmentstatus = $enrolments[$user->id]->status;
$users[$user->id]->enrolmentstart = $enrolments[$user->id]->mintime; $users[$user->id]->enrolmentstart = $enrolments[$user->id]->mintime;
$users[$user->id]->enrolmentend = $enrolments[$user->id]->maxtime; $users[$user->id]->enrolmentend = $enrolments[$user->id]->maxtime;

8
db/mobile.php

@ -33,7 +33,11 @@ $addons = [
'class' => '', 'class' => '',
], ],
'delegate' => 'CoreCourseModuleDelegate', 'delegate' => 'CoreCourseModuleDelegate',
'method' => 'mobile_view_activity' 'method' => 'mobile_view_activity',
'styles' => [
'url' => '/mod/attendance/mobilestyles.css',
'version' => 7
]
] ]
], ],
'lang' => [ // Language strings that are used in all the handlers. 'lang' => [ // Language strings that are used in all the handlers.
@ -59,6 +63,6 @@ $addons = [
['subnetwrong', 'attendance'], ['subnetwrong', 'attendance'],
['enterpassword', 'attendance'], ['enterpassword', 'attendance'],
['incorrectpasswordshort', 'attendance'] ['incorrectpasswordshort', 'attendance']
] ],
] ]
]; ];

4
mobilestyles.css

@ -0,0 +1,4 @@
.attendance_teacher_form .item-radio {
display: inline-block;
width: 70px;
}

74
templates/mobile_teacher_form.mustache

@ -0,0 +1,74 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template mod_attendance/mobile_user_form
The page to take attendance
Classes required for JS:
* None
Data attibutes required for JS:
* All data attributes are required
Context variables required for this template:
* attendance
* summary
* cmid
Example context (json):
{
"attendance": {
"id": "1",
"course": "2",
"name": "Class Attendance",
"intro": "Intro"
},
"cmid": "25",
"courseid": "4",
"sessid": "43"
}
}}
{{=<% %>=}}
<div class="attendance_teacher_form">
<core-course-module-description description="<% attendance.intro %>" component="mod_attendance" componentId="<% cmid %>"></core-course-module-description>
<%#showmessage%>
<%#messages%>
<ion-item>
{{ 'plugin.mod_attendance.<% string %>' | translate }}
</ion-item>
<%/messages%>
<%/showmessage%>
<%#users%>
<ion-item>
<h2><% fullname %></h2>
</ion-item>
<ion-list radio-group [(ngModel)]="status<% userid %>">
<%#statuses%>
<ion-item>
<ion-label><% acronym %></ion-label>
<ion-radio value="<% stid %>"></ion-radio>
</ion-item>
<%/statuses%>
</ion-list>
<%/users%>
<button ion-button core-site-plugins-new-content component="mod_attendance" method="mobile_view_activity" [args]="{cmid: <% cmid %>, courseid: <% courseid %>, sessid: <% sessid %> <% args %>}">
{{ 'plugin.mod_attendance.submitattendance' | translate }}
</button>
</div>

4
templates/mobile_user_form.mustache

@ -38,7 +38,9 @@
"name": "Class Attendance", "name": "Class Attendance",
"intro": "Intro" "intro": "Intro"
}, },
"cmid": "25" "cmid": "25",
"courseid": "4",
"sessid": "43"
} }
}} }}
{{=<% %>=}} {{=<% %>=}}

Loading…
Cancel
Save