-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewattempt.php
245 lines (198 loc) · 8.92 KB
/
viewattempt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?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/>.
/**
* crucible module main user interface
*
* @package mod_crucible
* @copyright 2020 Carnegie Mellon University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
Crucible Plugin for Moodle
Copyright 2020 Carnegie Mellon University.
NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a GNU GPL 3.0-style license, please see license.txt or contact permission@sei.cmu.edu for full terms.
[DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution.
This Software includes and/or makes use of the following Third-Party Software subject to its own license:
1. Moodle (https://docs.moodle.org/dev/License) Copyright 1999 Martin Dougiamas.
DM20-0196
*/
use \mod_crucible\crucible;
//require('../../config.php');
require_once(dirname(dirname(dirname(__FILE__))).'/config.php');
require_once("$CFG->dirroot/mod/crucible/lib.php");
require_once("$CFG->dirroot/mod/crucible/locallib.php");
$a = optional_param('a', '', PARAM_INT); // attempt ID
$action = optional_param('action', 'list', PARAM_TEXT);
$actionitem = optional_param('id', 0, PARAM_INT);
if (!$a) {
$a = required_param('attemptid', PARAM_INT); // attempt ID
}
try {
$attempt = $DB->get_record('crucible_attempts', array('id' => $a), '*', MUST_EXIST);
$crucible = $DB->get_record('crucible', array('id' => $attempt->crucibleid), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $crucible->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('crucible', $crucible->id, $course->id, false, MUST_EXIST);
} catch (Exception $e) {
print_error("invalid attempt id passed");
}
require_course_login($course, true, $cm);
$context = context_module::instance($cm->id);
// TODO create review attempt capability
require_capability('mod/crucible:view', $context);
// TODO log event attempt views
if ($_SERVER['REQUEST_METHOD'] == "GET") {
// Completion and trigger events.
//crucible_view($crucible, $course, $cm, $context);
}
// Print the page header.
$url = new moodle_url ( '/mod/crucible/viewattempt.php', array ( 'a' => $a ) );
$PAGE->set_url($url);
$PAGE->set_context($context);
$PAGE->set_title(format_string($crucible->name));
$PAGE->set_heading($course->fullname);
// new crucible class
$pageurl = null;
$pagevars = array();
$object = new \mod_crucible\crucible($cm, $course, $crucible, $pageurl, $pagevars);
// get eventtemplate info
$object->eventtemplate = get_eventtemplate($object->userauth, $crucible->eventtemplateid);
// Update the database.
if ($object->eventtemplate) {
$scenariotemplateid = $object->eventtemplate->scenarioTemplateId;
// Update the database.
$crucible->name = $object->eventtemplate->name;
$crucible->intro = $object->eventtemplate->description;
$DB->update_record('crucible', $crucible);
// this generates lots of hvp module errors
//rebuild_course_cache($crucible->course);
} else {
$scenariotemplateid = "";
}
//TODO send instructor to a different page where manual grading can occur
$eventid = null;
$viewid = null;
$scenarioid = null;
$startime = null;
$endtime = null;
$grader = new \mod_crucible\utils\grade($object);
$gradepass = $grader->get_grade_item_passing_grade();
debugging("grade pass is $gradepass", DEBUG_DEVELOPER);
// show grade only if a passing grade is set
if ((int)$gradepass >0) {
$showgrade = true;
} else {
$showgrade = false;
}
$renderer = $PAGE->get_renderer('mod_crucible');
echo $renderer->header();
$renderer->display_detail($crucible, $object->eventtemplate->durationHours);
$isinstructor = has_capability('mod/crucible:manage', $context);
if ($isinstructor) {
// TODO display attempt user with formatting
$user = $DB->get_record('user', array("id" => $attempt->userid));
echo "Username: " . fullname($user);
}
$renderer->display_form($url, $object->crucible->eventtemplateid);
global $DB;
$system = setup_system();
$scenario = get_scenario($system, $attempt->scenarioid);
$tasks = get_scenariotasks($system, $attempt->scenarioid);
$tasks = $object->filter_scenario_tasks($tasks, $visible = 1);
//get tasks from db
if ($isinstructor) {
if ($showgrade) {
$renderer->display_grade($crucible, $attempt->userid);
$renderer->display_scenario_score($scenario);
}
echo "<br>Instructor view: displaying all gradable tasks";
if ($tasks) {
$renderer->display_results($tasks, $review = true);
}
// if ($showgrade) {
// $renderer->display_grade($crucible, $attempt->userid);
// $renderer->display_score($attempt->id);
// }
// // Get the editgrade form.
// $mform = new \mod_crucible\crucible_editgrade_form();
// // If the cancel button was pressed, we are out of here.
// if ($mform->is_cancelled()) {
// redirect($PAGE->url, get_string('cancelled'), 2);
// exit;
// }
// // If we have data, then our job here is to save it and return.
// if ($data = $mform->get_data()) {
// $data->vmname = "SUMMARY";
// debugging("updating crucible_task_results", DEBUG_DEVELOPER);
// $DB->update_record('crucible_task_results', $data);
// $attempt = $object->get_attempt($a);
// $score = $grader->calculate_attempt_grade($attempt);
// $response['score'] = get_string("attemptscore", "crucible") . $score;
// debugging("grade " . $score, DEBUG_DEVELOPER);
// redirect($PAGE->url, get_string('updated', 'core', 'grade item; new grade ' . $score), 2);
// }
// // If the action is specified as "edit" then we show the edit form.
// if ($action == "edit") {
// // Create some data for our form and set it to the form.
// $data = new stdClass();
// // get task from db table
// $data = $DB->get_record_sql('SELECT * from {crucible_task_results} WHERE '
// . 'taskid = ' . $actionitem . ' AND '
// . 'attemptid = ' . $a . ' AND '
// . $DB->sql_compare_text('vmname') . ' = '
// . $DB->sql_compare_text(':vmname'), ['vmname' => 'SUMMARY']);
// if (!$data) { // In case there isn't any data in your chosen table.
// print_error("this should not happen");
// }
// $mform->set_data($data);
// // Header for the page.
// echo $renderer->heading('Edit Task Grade', 3);
// // Output page and form.
// $mform->display();
// }
// echo "<br>Instructor view: displaying all gradable tasks";
// $tasks = $DB->get_records('crucible_tasks', array("crucibleid" => $crucible->id, "gradable" => "1"));
// $details = array();
// foreach ($tasks as $task) {
// $task_results = array();
// $results = $DB->get_records('crucible_task_results', array("attemptid" => $a, "taskid" => $task->id), "timemodified ASC");
// foreach ($results as $result) {
// $newtask = clone $task;
// $newtask->vmname = $result->vmname;
// $newtask->score = $result->score;
// $newtask->result = $result->status;
// if (isset($result->comment)) {
// $newtask->comment = $result->comment;
// }
// if ($newtask->vmname === 'SUMMARY') {
// array_unshift($task_results, $newtask);
// } else {
// $task_results[] = $newtask;
// }
// }
// $details = array_merge($details, $task_results);
// }
// $renderer->display_results_detail($a, $details);
} else {
if ($showgrade) {
$renderer->display_grade($crucible);
$renderer->display_scenario_score($scenario);
}
echo "<br>Student view: displaying all visible and gradable tasks";
if ($tasks) {
$renderer->display_results($tasks, $review = true);
}
}