Skip to content

Commit

Permalink
Merge pull request #74 from turnitin/develop
Browse files Browse the repository at this point in the history
Release v2020092301
  • Loading branch information
dwinn authored Sep 23, 2020
2 parents a3c9b6e + 15a573f commit dbdc427
Show file tree
Hide file tree
Showing 18 changed files with 930 additions and 52 deletions.
45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
### Date: 2020-September-23
### Release: v2020092301

#### :zap: What's new

---

#### Support for Moodle Quizzes

Turnitin will be usable as a part of a Moodle quiz when Moodle releases the feature. When enabled for your account, simply add an essay question as one of the quiz questions. A similarity report will be generated when the student submits the quiz. Track this release on the [Moodle Tracker](https://tracker.moodle.org/browse/MDL-32226).

#### Privacy API declartion now includes the submission’s contents

The [Moodle Privacy API](https://docs.moodle.org/dev/Privacy_API) helps plugins report what user data a plugin uses so they cna make informed decisions about their personal information. As a part of the Privacy API declartion, we will now includethe contents of the submission to fully support the Privacy APIs goals.

Thanks to [thepurpleblob](https://github.com/turnitin/moodle-mod_turnitintooltwo/issues/464) for the catch!

#### Permission to use the Turnitin Integrity plugin can be limited to individual instructors

Two new permission settings can now be configured that will allow you to specify certain users who have access to the Turnitin Integrity plugin. This can be used to limit use to certain departments or schools within your organization.

You are now able to choose if a user is able to Enable Turnitin Integrity for an assignment, and choose if they are able to view any generated similarity reports.

You can take advantage of this new setting by navigation to Site Administration > Users > Permissions > Check system permissions for the user your wish to give access to.

#### Support for Korean, Japanese, Chinese (Traditional), and Chinese (Simplified)

Our interface has been fully localized into four new languages. Check out our help site for full step-by-step guides in these languages too

#### :wrench: Fixes and enhancements

---

#### EULA screen is now not blank after accepting the Turnitin EULA

Rather than seeing a blank screen, we’ll now show you a simple message confirming that you have accepted our EULA when navigating to <Your Moodle Instance’s URL>/plagiarism/turnitinsim/eula.php?cmd=displayeula

#### Turnitin will only show on activity types we support

Turnitin only supports Moodle assignments, forums, and workshops (and quizzes once released by Moodle!). However, it was possible that the option to enable Turnitin would show on the settings page for activity types we don't support.

To help clear up any confusion, the option to enable Turnitin will now only show on activity types we support.

---

### Date: 2020-July-21
### Release: v2020072101

Expand Down
2 changes: 2 additions & 0 deletions ajax/eula_response.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@
$data->id = $submission->id;
$data->status = TURNITINSIM_SUBMISSION_STATUS_QUEUED;
$data->cm = $context->instanceid;
$data->tiiattempts = 0;
$data->tiiretrytime = 0;

$DB->update_record('plagiarism_turnitinsim_sub', $data);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function after_restore_module() {
$params->moduleid = $cm->instance;
$params->userid = $data->userid;
$params->onlinetext = $onlinetext;
$data->itemid = $moduleobject->get_itemid($cm->instance, $data->userid);
$data->itemid = $moduleobject->get_itemid($params);
}

$DB->insert_record('plagiarism_turnitinsim_sub', $data);
Expand Down
11 changes: 11 additions & 0 deletions classes/observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class plagiarism_turnitinsim_observer {
public static function build_event_data($event, $eventtype, $module = '') {
$eventdata = $event->get_data();
$eventdata['eventtype'] = $eventtype;

if ($module != '') {
$eventdata['other']['modulename'] = $module;
}
Expand Down Expand Up @@ -99,6 +100,16 @@ public static function workshop_assessable_uploaded(
$plugin->submission_handler(self::build_event_data($event, 'assessable_submitted', 'workshop'));
}

/**
* Observer function to handle the quiz_submitted event in mod_quiz.
* @param \mod_quiz\event\attempt_submitted $event
*/
public static function quiz_submitted(
\mod_quiz\event\attempt_submitted $event) {
$plugin = new plagiarism_plugin_turnitinsim();
$plugin->submission_handler(self::build_event_data($event, 'quiz_submitted', 'quiz'));
}

/**
* Handle the course_module_updated event.
* @param \core\event\course_module_updated $event
Expand Down
164 changes: 164 additions & 0 deletions classes/quiz.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
<?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/>.

/**
* Helper class for plagiarism_turnitinsim component in quizzes.
*
* @package plagiarism_turnitinsim
* @copyright 2020 Turnitin
* @author David Winn <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Helper class for plagiarism_turnitinsim component in quizzes.
*/
class plagiarism_turnitinsim_quiz {

/**
* Get the text from the database for the submission.
*
* @param String $itemid The itemid for this submission.
* @return mixed The text of the submission.
* @throws dml_exception
*/
public function get_onlinetext($itemid) {
global $DB;

$moodletextsubmission = $DB->get_record('question_attempts', array('id' => $itemid), 'responsesummary');

if (isset($moodletextsubmission->responsesummary)) {
return $moodletextsubmission->responsesummary;
}
}

/**
* Get the item id from the database for this submission.
*
* @param object $params The params to call the DB with.
* @return int The itemid.
* @throws dml_exception
*/
public function get_itemid($params) {
global $DB;

$item = $DB->get_record_sql('SELECT DISTINCT(q.id) FROM {question_attempt_steps} s
RIGHT JOIN {question_attempts} a
ON s.questionattemptid = a.id
RIGHT JOIN {quiz_attempts} q
ON a.questionusageid = q.uniqueid
WHERE q.quiz = ?
AND s.userid = ?
AND a.responsesummary = ?
AND q.state = ?',
array($params->moduleid, $params->userid, $params->onlinetext, 'finished')
);

return ($item) ? $item->id : 0;
}

/**
* Get the actual author of the submission.
*
* @param int $userid The userid as given by Moodle.
* @param int $relateduserid The relateduserid as given by Moodle.
* @return int The authorid.
*/
public function get_author($userid, $relateduserid) {
return (!empty($relateduserid)) ? $relateduserid : $userid;
}

/**
* Get the group id that a submission belongs to. - (N/A in quizzes).
*
* @param string $itemid The itemid for the submission.
* @return int The group id.
*/
public function get_groupid($itemid) {
return null;
}

/**
* Return whether the submission is a draft. Never the case with a quiz submission.
*
* @param string $itemid The itemid for the submission.
* @return bool If the submission is a draft.
*/
public function is_submission_draft($itemid) {
return false;
}

/**
* Return the due date so we can work out report generation time. Not applicable to quizzes.
*
* @param int $id The forum ID we want the due date for.
* @return int The due date for the assignment.
*/
public function get_due_date($id) {
return 0;
}

/**
* Determines whether the OR links in other posts should be seen. This is not applicable for quizzes.
*
* @param int $courseid The ID for this course.
* @param int $userid The userid.
* @return bool true if showing other posts links.
*/
public function show_other_posts_links($courseid, $userid) {
return true;
}

/**
* Create the submission event data needed to queue a submission if Turnitin is enabled after a submission.
*
* @param array $linkarray Data passed by Moodle that belongs to a submission.
* @return array Event data.
* @throws coding_exception
* @throws dml_exception
*/
public function create_submission_event_data($linkarray) {
global $USER;

$cm = get_coursemodule_from_id('', $linkarray['cmid']);

$eventdata = array();
$eventdata['contextinstanceid'] = $linkarray['cmid'];

$eventdata['eventtype'] = 'quiz_submitted';
$eventdata['userid'] = $USER->id;
$eventdata['objectid'] = $linkarray['area'];

if (isset($linkarray['file'])) {
$eventdata['other']['pathnamehashes'] = array($linkarray['file']->get_pathnamehash());
} else {
$params = new stdClass();
$params->moduleid = $cm->instance;

$params->userid = $linkarray['userid'];
$params->onlinetext = $linkarray['content'];
}
if (isset($linkarray['userid'])) {
$eventdata['relateduserid'] = $linkarray['userid'];
}

$eventdata['other']['modulename'] = $cm->modname;

return $eventdata;
}
}
21 changes: 20 additions & 1 deletion classes/request.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,32 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g
curl_setopt($ch, CURLOPT_PROXYUSERPWD, sprintf('%s:%s', $CFG->proxyuser, $CFG->proxypassword));
}

// Set the default for whether a response was found.
$responsefound = true;

$result = curl_exec($ch);
if ($result === false) {
$responsefound = false;
if ($this->logger) {
$this->logger->error('Curl error: ' . curl_error($ch));
}
}

// Add httpstatus to $result.
$httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);

if (empty($result)) {
$result = new stdClass();
} else {
$originaljson = $result;
$result = json_decode($result);

// If Json is not valid set httpstatus 400.
if (json_last_error() !== JSON_ERROR_NONE) {
if ($this->logger) {
$this->logger->error('The JSON returned was not valid. Returned JSON: '. $originaljson);
}

$result = new stdClass();
$httpstatus = 400;
}
Expand All @@ -208,7 +223,11 @@ public function send_request($endpoint, $requestbody, $method, $requesttype = 'g
curl_close($ch);

if ($this->logger) {
$this->logger->info('Response: ', array($result));
if ($responsefound) {
$this->logger->info('Response: ', array($result));
} else {
$this->logger->info('Response: There was no response from this request.');
}
}

return $result;
Expand Down
12 changes: 11 additions & 1 deletion classes/settings.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,13 @@ public function __construct(plagiarism_turnitinsim_request $tsrequest = null ) {
* Add Turnitin settings to module form.
*
* @param object $mform The Moodle form object.
* @param boolean $canconfigureplugin If this user has permission to configure the plugin.
* @param string $context The context, eg module or course.
* @param string $modulename The name of the module.
* @return mixed Moodle form with settings.
* @throws coding_exception
*/
public function add_settings_to_module($mform, $context = 'module', $modulename = '') {
public function add_settings_to_module($mform, $canconfigureplugin = false, $context = 'module', $modulename = '') {
global $PAGE;

if ($context == 'module') {
Expand Down Expand Up @@ -146,6 +147,15 @@ public function add_settings_to_module($mform, $context = 'module', $modulename
);
$mform->addElement('html', html_writer::tag('div', $link));

if (!$canconfigureplugin) {
$mform->freeze('turnitinenabled');
$mform->freeze('excludeoptions');
$mform->freeze('indexoptions');
$mform->freeze('reportgenoptions');
$mform->freeze('accessoptions');
$mform->freeze('queuedrafts');
}

return $mform;
}

Expand Down
Loading

0 comments on commit dbdc427

Please sign in to comment.