Skip to content

Commit 01abe72

Browse files
committed
Implement adhoc submissions
1 parent a7aa16b commit 01abe72

14 files changed

+634
-7
lines changed

amd/build/submissionqueued.min.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/submissionqueued.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This file is part of Moodle - http://moodle.org/
2+
//
3+
// Moodle is free software: you can redistribute it and/or modify
4+
// it under the terms of the GNU General Public License as published by
5+
// the Free Software Foundation, either version 3 of the License, or
6+
// (at your option) any later version.
7+
//
8+
// Moodle is distributed in the hope that it will be useful,
9+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
// GNU General Public License for more details.
12+
//
13+
// You should have received a copy of the GNU General Public License
14+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
15+
16+
/*
17+
* @package mod_turnitintooltwo
18+
* @author Skylar Kelty <[email protected]>
19+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
20+
*/
21+
22+
/**
23+
* @module mod_turnitintooltwo/submissionqueued
24+
*/
25+
define(['jquery', 'core/ajax'], function($, ajax) {
26+
var submissionid;
27+
var timer;
28+
29+
function check_status() {
30+
var ajaxpromises = ajax.call([{
31+
methodname: 'mod_turnitintooltwo_get_submission_status',
32+
args: {
33+
submissionid: submissionid
34+
}
35+
}]);
36+
37+
ajaxpromises[0].done(function(data) {
38+
if (data.status == 'queued') {
39+
return;
40+
}
41+
42+
$("#tiisubstatus").html(data.message);
43+
44+
window.clearInterval(timer);
45+
});
46+
47+
ajaxpromises[0].fail(function(ex) {
48+
console.log(ex);
49+
window.clearInterval(timer);
50+
});
51+
}
52+
53+
return {
54+
init: function(id) {
55+
submissionid = id;
56+
timer = window.setInterval(check_status, 1000);
57+
}
58+
};
59+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
namespace mod_turnitintooltwo\event;
18+
19+
/*
20+
* Log event when paper fails to submit
21+
*/
22+
23+
defined('MOODLE_INTERNAL') || die();
24+
25+
class errored_submission extends \core\event\base {
26+
protected function init() {
27+
$this->data['crud'] = 'u'; // c(reate), r(ead), u(pdate), d(elete)
28+
$this->data['level'] = self::LEVEL_PARTICIPATING; // For 2.6, this appears to have been renamed to 'edulevel' in 2.7
29+
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
30+
$this->data['objecttable'] = 'turnitintooltwo';
31+
}
32+
33+
public static function get_name() {
34+
return 'Submission error';
35+
}
36+
37+
public function get_description() {
38+
return $this->other['desc'];
39+
}
40+
41+
public function get_url() {
42+
return new \moodle_url('/mod/turnitintooltwo/view.php', array('id' => $this->objectid));
43+
}
44+
45+
/**
46+
* Custom validation.
47+
*
48+
* @throws \coding_exception
49+
* @return void
50+
*/
51+
protected function validate_data() {
52+
parent::validate_data();
53+
54+
if (!isset($this->other['desc'])) {
55+
throw new \coding_exception('The \'desc\' value must be set in other.');
56+
}
57+
58+
if ($this->contextlevel != CONTEXT_MODULE) {
59+
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
60+
}
61+
}
62+
}

classes/event/queue_submission.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
namespace mod_turnitintooltwo\event;
18+
19+
/*
20+
* Log event when paper is queued for submission either by student or instructor on behalf of student
21+
*/
22+
23+
defined('MOODLE_INTERNAL') || die();
24+
25+
class queue_submission extends \core\event\base {
26+
protected function init() {
27+
$this->data['crud'] = 'c'; // c(reate), r(ead), u(pdate), d(elete)
28+
$this->data['level'] = self::LEVEL_PARTICIPATING; // For 2.6, this appears to have been renamed to 'edulevel' in 2.7
29+
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
30+
$this->data['objecttable'] = 'turnitintooltwo';
31+
}
32+
33+
public static function get_name() {
34+
return 'Submission queued';
35+
}
36+
37+
public function get_description() {
38+
return $this->other['desc'];
39+
}
40+
41+
public function get_url() {
42+
return new \moodle_url('/mod/turnitintooltwo/view.php', array('id' => $this->objectid));
43+
}
44+
45+
/**
46+
* Custom validation.
47+
*
48+
* @throws \coding_exception
49+
* @return void
50+
*/
51+
protected function validate_data() {
52+
parent::validate_data();
53+
if (!isset($this->other['desc'])) {
54+
throw new \coding_exception('The \'desc\' value must be set in other.');
55+
}
56+
57+
if ($this->contextlevel != CONTEXT_MODULE) {
58+
throw new \coding_exception('Context level must be CONTEXT_MODULE.');
59+
}
60+
}
61+
}

classes/external.php

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
* Turnitintwo services.
19+
*
20+
* @package mod_turnitintooltwo
21+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22+
*/
23+
24+
namespace mod_turnitintooltwo;
25+
26+
defined('MOODLE_INTERNAL') || die();
27+
28+
require_once($CFG->libdir . '/externallib.php');
29+
require_once($CFG->dirroot . '/course/lib.php');
30+
require_once($CFG->dirroot . "/mod/turnitintooltwo/turnitintooltwo_view.class.php");
31+
32+
use external_api;
33+
use external_value;
34+
use external_single_structure;
35+
use external_function_parameters;
36+
37+
/**
38+
* Turnitintwo services.
39+
*/
40+
class external extends external_api
41+
{
42+
/**
43+
* Returns description of method parameters
44+
* @return external_function_parameters
45+
*/
46+
public static function get_submission_status_parameters() {
47+
return new external_function_parameters(array(
48+
'submissionid' => new external_value(
49+
PARAM_INT,
50+
'The submission ID',
51+
VALUE_REQUIRED
52+
)
53+
));
54+
}
55+
56+
/**
57+
* Search a list of modules.
58+
*
59+
* @param $modulecode
60+
* @return array [string]
61+
* @throws \invalid_parameter_exception
62+
*/
63+
public static function get_submission_status($submissionid) {
64+
global $DB, $USER, $PAGE;
65+
66+
$params = self::validate_parameters(self::get_submission_status_parameters(), array(
67+
'submissionid' => $submissionid
68+
));
69+
$submissionid = $params['submissionid'];
70+
71+
$submission = $DB->get_record('turnitintooltwo_submissions', array(
72+
'id' => $submissionid
73+
));
74+
if (!$submission) {
75+
return array('status' => 'error', 'message' => 'Could not find submission.');
76+
}
77+
78+
// Grab more data.
79+
$turnitintooltwo = $DB->get_record('turnitintooltwo', array('id' => $submission->turnitintooltwoid));
80+
list($course, $cm) = get_course_and_cm_from_instance($turnitintooltwo, 'turnitintooltwo');
81+
82+
// Check this is our submission.
83+
if ($USER->id !== $submission->userid && !has_capability('mod/turnitintooltwo:grade', \context_module::instance($cm->id))) {
84+
return array('status' => 'nopermission', 'message' => 'You do not have permission to view that.');
85+
}
86+
87+
// What is the status?
88+
$status = $DB->get_record('turnitintooltwo_sub_status', array(
89+
'submissionid' => $submissionid
90+
));
91+
if (!$status || !$status->status) {
92+
return array('status' => 'queued', 'message' => '');
93+
}
94+
95+
// Decode the receipt.
96+
$digitalreceipt = (array)json_decode($status->receipt);
97+
98+
// Woo!
99+
if ($status->status == \mod_turnitintooltwo\task\submit_assignment::STATUS_SUCCESS) {
100+
$turnitintooltwoview = new \turnitintooltwo_view();
101+
102+
$PAGE->set_context(\context_module::instance($cm->id));
103+
$digitalreceipt = $turnitintooltwoview->show_digital_receipt($digitalreceipt);
104+
$digitalreceipt = \html_writer::tag("div", $digitalreceipt, array("id" => "box_receipt"));
105+
106+
return array(
107+
'status' => 'success',
108+
'message' => $digitalreceipt
109+
);
110+
}
111+
112+
return array(
113+
'status' => 'failed',
114+
'message' => \html_writer::tag("div", $digitalreceipt["message"], array("class" => "alert alert-danger"))
115+
);
116+
}
117+
118+
/**
119+
* Returns description of get_submission_status() result value.
120+
*
121+
* @return external_description
122+
*/
123+
public static function get_submission_status_returns() {
124+
return new external_single_structure(
125+
array(
126+
'status' => new external_value(PARAM_TEXT, 'status codes'),
127+
'message' => new external_value(PARAM_RAW, 'digital receipt')
128+
)
129+
);
130+
}
131+
}

0 commit comments

Comments
 (0)