Dan Marsden
11 years ago
18 changed files with 649 additions and 60 deletions
@ -0,0 +1,84 @@ |
|||
<?php |
|||
// 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/>. |
|||
|
|||
/** |
|||
* Prints attendance info for particular user |
|||
* |
|||
* @package mod |
|||
* @subpackage attendance |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
|
|||
require_once(dirname(__FILE__).'/../../config.php'); |
|||
require_once(dirname(__FILE__).'/locallib.php'); |
|||
require_once(dirname(__FILE__).'/student_attenance_form.php'); |
|||
|
|||
$pageparams = new att_sessions_page_params(); |
|||
|
|||
// Check that the required parameters are present. |
|||
$id = required_param('sessid', PARAM_INT); |
|||
$attendance_session_id = required_param('sessid', PARAM_INT); |
|||
|
|||
|
|||
$attforsession = $DB->get_record('attendance_sessions', array('id' => $id), '*', MUST_EXIST); |
|||
$attendance = $DB->get_record('attendance', array('id' => $attforsession->attendanceid), '*', MUST_EXIST); |
|||
$cm = get_coursemodule_from_instance('attendance', $attendance->id, 0, false, MUST_EXIST); |
|||
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); |
|||
|
|||
// Require the user is logged in. |
|||
require_login($course, true, $cm); |
|||
|
|||
$pageparams->sessionid = $id; |
|||
$att = new attendance($attendance, $cm, $course, $PAGE->context, $pageparams); |
|||
|
|||
// Require that a session key is passed to this page. |
|||
require_sesskey(); |
|||
|
|||
// Create the form. |
|||
$mform = new mod_attendance_student_attendance_form(null, |
|||
array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context, 'session' => $attforsession, 'attendance' => $att)); |
|||
|
|||
if ($mform->is_cancelled()) { |
|||
// The user cancelled the form, so redirect them to the view page. |
|||
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); |
|||
redirect($url); |
|||
} else if ($fromform = $mform->get_data()) { |
|||
if (!empty($fromform->status)) { |
|||
$success = $att->take_from_student($fromform); |
|||
|
|||
$url = new moodle_url('/mod/attendance/view.php', array('id' => $cm->id)); |
|||
if ($success) { |
|||
// Redirect back to the view page for the block. |
|||
redirect($url); |
|||
} else { |
|||
print_error ('attendance_already_submitted', 'mod_attendance', $url); |
|||
} |
|||
} |
|||
|
|||
// The form did not validate correctly so we will set it to display the data they submitted. |
|||
$mform->set_data($fromform); |
|||
} |
|||
|
|||
$PAGE->set_url($att->url_sessions()); |
|||
$PAGE->set_title($course->shortname. ": ".$att->name); |
|||
$PAGE->set_heading($course->fullname); |
|||
$PAGE->set_cacheable(true); |
|||
$PAGE->navbar->add($att->name); |
|||
|
|||
$output = $PAGE->get_renderer('mod_attendance'); |
|||
echo $output->header(); |
|||
$mform->display(); |
|||
echo $output->footer(); |
@ -0,0 +1,63 @@ |
|||
<?php |
|||
// 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/>. |
|||
|
|||
require_once($CFG->libdir.'/formslib.php'); |
|||
|
|||
class mod_attendance_student_attendance_form extends moodleform { |
|||
public function definition() { |
|||
global $CFG, $USER; |
|||
|
|||
$mform =& $this->_form; |
|||
|
|||
$course = $this->_customdata['course']; |
|||
$cm = $this->_customdata['cm']; |
|||
$modcontext = $this->_customdata['modcontext']; |
|||
$attforsession = $this->_customdata['session']; |
|||
$attblock = $this->_customdata['attendance']; |
|||
|
|||
$statuses = $attblock->get_statuses(); |
|||
|
|||
$mform->addElement('hidden', 'sessid', null); |
|||
$mform->setType('sessid', PARAM_INT); |
|||
$mform->setConstant('sessid', $attforsession->id); |
|||
|
|||
$mform->addElement('hidden', 'sesskey', null); |
|||
$mform->setType('sesskey', PARAM_INT); |
|||
$mform->setConstant('sesskey', sesskey()); |
|||
|
|||
// Set a title as the date and time of the session. |
|||
$sesstiontitle = userdate($attforsession->sessdate, get_string('strftimedate')).' ' |
|||
.userdate($attforsession->sessdate, get_string('strftimehm', 'mod_attendance')); |
|||
|
|||
$mform->addElement('header', 'session', $sesstiontitle); |
|||
|
|||
// If a session description is set display it. |
|||
if (!empty($attforsession->description)) { |
|||
$mform->addElement('html', $attforsession->description); |
|||
} |
|||
|
|||
// Create radio buttons for setting the attendance status. |
|||
$radioarray = array(); |
|||
foreach ($statuses as $status) { |
|||
$radioarray[] =& $mform->createElement('radio', 'status', '', $status->description, $status->id, array()); |
|||
} |
|||
// Add the radio buttons as a control with the user's name in front. |
|||
$mform->addGroup($radioarray, 'statusarray', $USER->firstname.' '.$USER->lastname.':', array(''), false); |
|||
$mform->addRule('statusarray', get_string('attendancenotset', 'attendance'), 'required', '', 'client', false, false); |
|||
|
|||
$this->add_action_buttons(); |
|||
} |
|||
} |
@ -0,0 +1,105 @@ |
|||
@mod @uon @mod_attendance |
|||
Feature: Teachers and Students can record session attendance |
|||
In order to record session attendance |
|||
As a student |
|||
I need to be able to mark my own attendance to a session |
|||
And as a teacher |
|||
I need to be able to mark any students attendance to a session |
|||
In order to report on session attendance |
|||
As a teacher |
|||
I need to be able to export session attendance and run reports |
|||
In order to contact students with poor attendance |
|||
As a teacher |
|||
I need the ability to message a group of students with low attendance |
|||
|
|||
Background: |
|||
Given the following "courses" exist: |
|||
| fullname | shortname | summary | category | |
|||
| Course 1 | C101 | Prove the attendance activity works | 0 | |
|||
And the following "users" exist: |
|||
| username | firstname | lastname | email | idnumber | department | institution | |
|||
| student1 | Sam | Student | student1@asd.com | 1234 | computer science | University of Nottingham | |
|||
| teacher1 | Teacher | One | teacher1@asd.com | 5678 | computer science | University of Nottingham | |
|||
And the following "course enrolments" exist: |
|||
| user | course | role | |
|||
| student1 | C101 | student | |
|||
| teacher1 | C101 | editingteacher | |
|||
And I log in as "teacher1" |
|||
And I follow "Course 1" |
|||
And I turn editing mode on |
|||
And I add a "Attendance" to section "1" |
|||
And I press "Save and display" |
|||
And I log out |
|||
|
|||
Scenario: Students can mark their own attendance |
|||
When I log in as "teacher1" |
|||
And I follow "Course 1" |
|||
And I follow "Attendance" |
|||
And I follow "Add" |
|||
And I check "Allow students to record own attendance" |
|||
And I set the following fields to these values: |
|||
| id_sessiondate_hour | 23 | |
|||
And I click on "id_submitbutton" "button" |
|||
And I follow "Continue" |
|||
And I log out |
|||
When I log in as "student1" |
|||
And I follow "Course 1" |
|||
And I follow "Attendance" |
|||
And I follow "Submit attendance" |
|||
And I check "Present" |
|||
And I press "Save changes" |
|||
Then I should see "Self-recorded" |
|||
And I log out |
|||
When I log in as "teacher1" |
|||
And I follow "Course 1" |
|||
And I expand "Reports" node |
|||
And I follow "Logs" |
|||
And I click on "Get these logs" "button" |
|||
Then "attendance taken by student" "link" should exist |
|||
|
|||
Scenario: Teachers can view low grade report and send a message |
|||
When I log in as "teacher1" |
|||
And I follow "Course 1" |
|||
And I follow "Attendance" |
|||
And I follow "Add" |
|||
And I set the following fields to these values: |
|||
| id_sessiondate_hour | 01 | |
|||
And I click on "id_submitbutton" "button" |
|||
And I follow "Continue" |
|||
And I follow "Report" |
|||
And I follow "Low grade" |
|||
And I check "user3" |
|||
And I click on "Send a message" "button" |
|||
Then I should see "Message body" |
|||
And I should see "student1@asd.com" |
|||
And I expand "Reports" node |
|||
And I follow "Logs" |
|||
And I click on "Get these logs" "button" |
|||
Then "attendance report viewed" "link" should exist |
|||
|
|||
# Dependency - selenium running with firefox profile with auto saving of txt files to $CFG->behat_download. |
|||
@javascript @_file_download |
|||
Scenario: Export report includes id number, department and institution |
|||
When I log in as "teacher1" |
|||
And I follow "Course 1" |
|||
And I follow "Attendance" |
|||
And I follow "Add" |
|||
And I set the following fields to these values: |
|||
| id_sessiondate_hour | 01 | |
|||
And I click on "id_submitbutton" "button" |
|||
And I follow "Continue" |
|||
And I follow "Export" |
|||
Then the "id_ident_idnumber" checkbox should not be checked |
|||
And the "id_ident_institution" checkbox should not be checked |
|||
And the "id_ident_department" checkbox should not be checked |
|||
And I check "id_ident_idnumber" |
|||
And I check "id_ident_institution" |
|||
And I check "id_ident_department" |
|||
And I set the following fields to these values: |
|||
| format | Download in text format | |
|||
And I click on "OK" "button" |
|||
Then attendance export file is ok |
|||
And I should see "ID number" as "1234" in the file |
|||
And I should see "Department" as "computer science" in the file |
|||
And I should see "Institution" as "University of Nottingham" in the file |
|||
|
@ -0,0 +1,116 @@ |
|||
<?php |
|||
// 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/>. |
|||
|
|||
|
|||
// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. |
|||
|
|||
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); |
|||
|
|||
use Behat\Mink\Exception\ExpectationException as ExpectationException, |
|||
Behat\Behat\Exception\PendingException as PendingException; |
|||
|
|||
/** |
|||
* Attendance steps definitions. |
|||
* |
|||
* @package mod |
|||
* @subpackage attendance |
|||
* @category test |
|||
* @copyright 2014 University of Nottingham |
|||
* @author Joseph Baxter (joseph.baxter@nottingham.ac.uk) |
|||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
|||
*/ |
|||
class behat_mod_attendance extends behat_base { |
|||
|
|||
protected $file_contents; |
|||
|
|||
/** |
|||
* @Then /^attendance export file is ok$/ |
|||
*/ |
|||
public function attendance_export_file_is_ok() { |
|||
|
|||
global $CFG; |
|||
|
|||
$check = true; |
|||
|
|||
// Location selenium will download to. |
|||
$dir = $CFG->behat_download; |
|||
$files = scandir($dir, 1); |
|||
$filename = $files[0]; |
|||
$file = fopen($dir . $filename, "r"); |
|||
|
|||
$count = 0; |
|||
$header = null; |
|||
|
|||
// The file is tab seperated but not exactly a tsv. |
|||
while (($row = fgetcsv($file, 0, "\t")) !== FALSE) { |
|||
|
|||
// Ignore unwanted information at the start of the file. |
|||
if ($count < 3) { |
|||
$count++; |
|||
continue; |
|||
} |
|||
|
|||
if (!$header) { |
|||
$header = $row; |
|||
} else { |
|||
$this->file_contents = array_combine($header, $row); |
|||
} |
|||
|
|||
$count++; |
|||
} |
|||
|
|||
fclose($file); |
|||
unlink($dir . $filename); |
|||
|
|||
// Check if data rows exist. |
|||
if ($count < 2) { |
|||
$check = false; |
|||
} |
|||
|
|||
if ($check) { |
|||
|
|||
return true; |
|||
|
|||
} else { |
|||
|
|||
throw new ExpectationException('Attendance export file not ok', $this->getSession()); |
|||
} |
|||
|
|||
} |
|||
|
|||
/** |
|||
* @Given /^I should see "([^"]*)" as "([^"]*)" in the file$/ |
|||
*/ |
|||
public function i_should_see_as_in_the_file($field, $value) { |
|||
|
|||
foreach ($this->file_contents as $array_field => $array_value) { |
|||
|
|||
if ($field == $array_field) { |
|||
|
|||
if ($value == $array_value) { |
|||
|
|||
return true; |
|||
|
|||
} else { |
|||
|
|||
throw new PendingException(); |
|||
|
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue