Skip to content

Commit 9299714

Browse files
authored
Merge pull request #281 from turnitin/develop
Develop to master for release
2 parents c1c779f + 32b74d4 commit 9299714

File tree

5 files changed

+308
-19
lines changed

5 files changed

+308
-19
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/*

CHANGELOG.md

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
### Date: 2017-November-23
2+
### Release: v2017112302
3+
4+
- Support for Moodle 3.4
5+
- Fixed errors due to incorrect configuration of the plugin
6+
- Added default activity completion settings
7+
- Fixed an issue preventing group submission grades from updating
8+
9+
**Support for Moodle 3.4** - After lots of tests against the release of Moodle 3.4, we're pleased to announce that Turnitin's Plagiarism Plugin now supports it.
10+
11+
**Fixed errors due to incorrect configuration of the plugin** - If the Plagiarism Plugin was not configured correctly and PeerMark was simultaneously enabled, this would cause an error in the assignment inbox. We've managed to resolve this!
12+
13+
**Added default activity completion settings** - We've added the default activity completion setting alongside the bulk edit activity completion. Default activity completion allows you to select one or more course activities or resources and change their default settings (usually 'manual') to a setting of your choice. Thanks to @tonyjbutler for his input!
14+
15+
**Fixed an issue preventing group submission grades from updating** - Moodle's group submissions allow one student to submit on behalf of their group. However, we ran into a breakdown in functionality where grades failed to apply to all group participants for a submission; only the student who physically made the submission would receive a grade. Now, all students in a group can view their grade in Turnitin Feedback Studio.
16+
17+
---
18+
119
### Date: 2017-August-10
220
### Release: v2017081001
321

lib.php

100644100755
+109-18
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ public function update_status($course, $cm) {
174174
return '';
175175
}
176176

177+
/**
178+
* Check if plugin has been configured with Turnitin account details.
179+
* @return boolean whether the plugin is configured for Turnitin.
180+
**/
181+
public function is_plugin_configured() {
182+
$config = turnitintooltwo_admin_config();
183+
if (empty($config->accountid) || empty($config->apiurl) || empty($config->secretkey)) {
184+
return false;
185+
}
186+
187+
return true;
188+
}
189+
177190
/**
178191
* Save the form data associated with the plugin
179192
*
@@ -229,9 +242,8 @@ public function get_form_elements_module($mform, $context, $modulename = "") {
229242
// Get Course module id and values.
230243
$cmid = optional_param('update', null, PARAM_INT);
231244

232-
// Check Turnitin is configured.
233-
$config = turnitintooltwo_admin_config();
234-
if (empty($config->accountid) || empty($config->apiurl) || empty($config->secretkey)) {
245+
// Return no form if the plugin isn't configured.
246+
if (!$this->is_plugin_configured()) {
235247
return;
236248
}
237249

@@ -265,11 +277,10 @@ public function get_form_elements_module($mform, $context, $modulename = "") {
265277
$turnitinpluginview = new turnitinplugin_view();
266278
$plagiarismvalues["plagiarism_rubric"] = ( !empty($plagiarismvalues["plagiarism_rubric"]) ) ? $plagiarismvalues["plagiarism_rubric"] : 0;
267279

268-
// Create/Edit course in Turnitin and join user to class.
269-
$course = $this->get_course_data($cmid, $COURSE->id);
270-
271280
// We don't require the settings form on Moodle 3.3's bulk completion feature.
272-
if ($PAGE->pagetype != 'course-editbulkcompletion') {
281+
if ($PAGE->pagetype != 'course-editbulkcompletion' && $PAGE->pagetype != 'course-editdefaultcompletion') {
282+
// Create/Edit course in Turnitin and join user to class.
283+
$course = $this->get_course_data($cmid, $COURSE->id);
273284
$turnitinpluginview->add_elements_to_settings_form($mform, $course, "activity", $cmid, $plagiarismvalues["plagiarism_rubric"]);
274285
}
275286

@@ -436,6 +447,11 @@ public function print_disclosure($cmid) {
436447
$output = $OUTPUT->box($contents, 'generalbox boxaligncenter', 'intro');
437448
}
438449

450+
// Exit here if the plugin is not configured for Turnitin.
451+
if (!$this->is_plugin_configured()) {
452+
return $output;
453+
}
454+
439455
// Show EULA if necessary and we have a connection to Turnitin.
440456
if (empty($tiiconnection)) {
441457
$tiiconnection = $this->test_turnitin_connection();
@@ -679,12 +695,22 @@ public function get_links($linkarray) {
679695
$linkarray['userid'] = $USER->id;
680696
}
681697

682-
// Get correct user id that submission is for rather than who submitted, this only affects file submissions
683-
// post Moodle 2.7 which is problematic as teachers can submit on behalf of students.
684-
$author = $linkarray['userid'];
685-
if ($itemid != 0) {
686-
$author = $moduleobject->get_author($itemid);
687-
$linkarray['userid'] = (!empty($author)) ? $author : $linkarray['userid'];
698+
/*
699+
The author will be incorrect if an instructor submits on behalf of a student who is in a group.
700+
To get around this, we get the group ID, get the group members and set the author as the first student in the group.
701+
*/
702+
$moodlesubmission = $DB->get_record('assign_submission', array('id' => $itemid), 'id, groupid');
703+
if ((!empty($moodlesubmission->groupid)) && ($cm->modname == "assign")) {
704+
$author = $this->get_first_group_author($cm->course, $moodlesubmission->groupid);
705+
$linkarray['userid'] = $author;
706+
} else {
707+
// Get correct user id that submission is for rather than who submitted, this only affects file submissions
708+
// post Moodle 2.7 which is problematic as teachers can submit on behalf of students.
709+
$author = $linkarray['userid'];
710+
if ($itemid != 0) {
711+
$author = $moduleobject->get_author($itemid);
712+
$linkarray['userid'] = (!empty($author)) ? $author : $linkarray['userid'];
713+
}
688714
}
689715

690716
// Show the EULA for a student if necessary.
@@ -1239,10 +1265,18 @@ private function update_submission($cm, $submissionid, $tiisubmission) {
12391265
if ($file = $fs->get_file_by_hash($submissiondata->identifier)) {
12401266
$itemid = $file->get_itemid();
12411267

1242-
$submission = $DB->get_records('assign_submission', array('assignment' => $cm->instance,
1243-
'userid' => $submissiondata->userid), 'id DESC', 'id, attemptnumber', '0', '1');
1244-
$item = current($submission);
1268+
$assignmentdata = array("assignment" => $cm->instance);
1269+
1270+
// Check whether submission is a group submission.
1271+
$groupid = $this->check_group_submission($cm, $submissiondata->userid);
1272+
if ($groupid) {
1273+
$assignmentdata['groupid'] = $groupid;
1274+
} else {
1275+
$assignmentdata['userid'] = $submissiondata->userid;
1276+
}
1277+
$submission = $DB->get_records('assign_submission', $assignmentdata, 'id DESC', 'id, attemptnumber', '0', '1');
12451278

1279+
$item = current($submission);
12461280
if ($item->id != $itemid) {
12471281
$gbupdaterequired = false;
12481282
}
@@ -1443,6 +1477,48 @@ private function update_grade($cm, $submission, $userid, $type = 'submission') {
14431477
return $return;
14441478
}
14451479

1480+
/**
1481+
* Check if this is a group submission.
1482+
*/
1483+
public function check_group_submission($cm, $userid) {
1484+
global $CFG, $DB;
1485+
1486+
$moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance));
1487+
if (!empty($moduledata->teamsubmission)) {
1488+
require_once($CFG->dirroot . '/mod/assign/locallib.php');
1489+
$context = context_course::instance($cm->course);
1490+
1491+
$assignment = new assign($context, $cm, null);
1492+
$group = $assignment->get_submission_group($userid);
1493+
1494+
return $group->id;
1495+
}
1496+
1497+
return false;
1498+
}
1499+
1500+
/*
1501+
* Related user ID will be NULL if an instructor submits on behalf of a student who is in a group.
1502+
* To get around this, we get the group ID, get the group members and set the author as the first student in the group.
1503+
1504+
* @param int $cmid - The course ID.
1505+
* @param int $groupid - The ID of the Moodle group that we're getting from.
1506+
* @return int $author The Moodle user ID that we'll be using for the author.
1507+
*/
1508+
private function get_first_group_author($cmid, $groupid) {
1509+
static $context;
1510+
if (empty($context)) {
1511+
$context = context_course::instance($cmid);
1512+
}
1513+
1514+
$groupmembers = groups_get_members($groupid, "u.id");
1515+
foreach ($groupmembers as $author) {
1516+
if (!has_capability('mod/assign:grade', $context, $author->id)) {
1517+
return $author->id;
1518+
}
1519+
}
1520+
}
1521+
14461522
/**
14471523
* Create a course within Turnitin
14481524
*/
@@ -1491,6 +1567,11 @@ public function create_tii_course($cmid, $modname, $coursedata, $workflowcontext
14911567
public function refresh_peermark_assignments($cm, $tiiassignmentid) {
14921568
global $DB;
14931569

1570+
// Return here if the plugin is not configured for Turnitin.
1571+
if (!$this->is_plugin_configured()) {
1572+
return;
1573+
}
1574+
14941575
// Initialise Comms Object.
14951576
$turnitincomms = new turnitin_comms();
14961577
$turnitincall = $turnitincomms->initialise_api();
@@ -2223,12 +2304,22 @@ public function event_handler($eventdata) {
22232304
$submitter = $eventdata['userid'];
22242305
$author = (!empty($eventdata['relateduserid'])) ? $eventdata['relateduserid'] : $eventdata['userid'];
22252306

2307+
/*
2308+
Related user ID will be NULL if an instructor submits on behalf of a student who is in a group.
2309+
To get around this, we get the group ID, get the group members and set the author as the first student in the group.
2310+
*/
2311+
if ((empty($eventdata['relateduserid'])) && ($eventdata['other']['modulename'] == 'assign')) {
2312+
$moodlesubmission = $DB->get_record('assign_submission', array('id' => $eventdata['objectid']), 'id, groupid');
2313+
if (!empty($moodlesubmission->groupid)) {
2314+
$author = $this->get_first_group_author($cm->course, $moodlesubmission->groupid);
2315+
}
2316+
}
2317+
22262318
// Get actual text content and files to be submitted for draft submissions.
22272319
// As this won't be present in eventdata for certain event types.
22282320
if ($eventdata['other']['modulename'] == 'assign' && $eventdata['eventtype'] == "assessable_submitted") {
22292321
// Get content.
2230-
$moodlesubmission = $DB->get_record('assign_submission', array('assignment' => $cm->instance,
2231-
'userid' => $author, 'id' => $eventdata['objectid']), 'id');
2322+
$moodlesubmission = $DB->get_record('assign_submission', array('id' => $eventdata['objectid']), 'id');
22322323
if ($moodletextsubmission = $DB->get_record('assignsubmission_onlinetext',
22332324
array('submission' => $moodlesubmission->id), 'onlinetext')) {
22342325
$eventdata['other']['content'] = $moodletextsubmission->onlinetext;

0 commit comments

Comments
 (0)