public function readAssignments($assignment) { try { $soap = $this->readLineItems(array('sourcedIdSet' => array('sourcedId' => $assignment->getAssignmentIds()))); $response = new Response($this); if ($response->getStatus() == 'error') { throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription()); } else { $assignments = array(); if (isset($soap->lineItemRecordSet->lineItemRecord)) { if (!is_array($soap->lineItemRecordSet->lineItemRecord)) { $soap->lineItemRecordSet->lineItemRecord = array($soap->lineItemRecordSet->lineItemRecord); } foreach ($soap->lineItemRecordSet->lineItemRecord as $lineitem) { $tiiAssignment = new TiiAssignment(); $tiiAssignment->setAssignmentId($lineitem->sourcedGUID->sourcedId); $tiiAssignment->setTitle($lineitem->lineItem->label); $tiiAssignment->setClassId($lineitem->lineItem->context->contextIdentifier); foreach ($lineitem->lineItem->extension->extensionField as $field) { $name = $field->fieldName; $method = 'set' . $name; $value = $name == 'PeermarkAssignments' ? $this->peermarkJSONToObject($field->fieldValue) : $field->fieldValue; if (is_callable(array($tiiAssignment, $method))) { $tiiAssignment->{$method}($value); } } $assignments[] = $tiiAssignment; } } $response->setAssignments($assignments); } return $response; } catch (SoapFault $e) { throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath()); } }
/** * Edit the assignment in Moodle then on Turnitin * * @global type $USER * @global type $DB * @param boolean $createevent - setting to determine whether to create a calendar event. * @return boolean */ public function edit_moodle_assignment($createevent = true) { global $USER, $DB, $CFG; $config = turnitintooltwo_admin_config(); $this->turnitintooltwo->id = $this->id; $this->turnitintooltwo->timemodified = time(); // Get Moodle Course Object. $course = $this->get_course_data($this->turnitintooltwo->course); // Get the Turnitin owner of this this Course or make user the owner if none. $ownerid = $this->get_tii_owner($course->id); if (!empty($ownerid)) { $owner = new turnitintooltwo_user($ownerid, 'Instructor'); } else { $owner = new turnitintooltwo_user($USER->id, 'Instructor'); } // Edit course in Turnitin. $this->edit_tii_course($course); $course->turnitin_ctl = $course->fullname . " (Moodle TT)"; // Get Current Moodle Turnitin Tool data (Assignment). if (!($turnitintooltwonow = $DB->get_record("turnitintooltwo", array("id" => $this->id)))) { turnitintooltwo_print_error('turnitintooltwogeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } // Get Current Moodle Turnitin Tool Parts Object. if (!($parts = $DB->get_records_select("turnitintooltwo_parts", " turnitintooltwoid = ? ", array($this->id), 'id ASC'))) { turnitintooltwo_print_error('partgeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } $partids = array_keys($parts); // Update GradeMark setting depending on config setting. $this->turnitintooltwo->usegrademark = $config->usegrademark; // Set the checkbox settings for updates. $this->turnitintooltwo->erater_spelling = isset($this->turnitintooltwo->erater_spelling) ? $this->turnitintooltwo->erater_spelling : 0; $this->turnitintooltwo->erater_grammar = isset($this->turnitintooltwo->erater_grammar) ? $this->turnitintooltwo->erater_grammar : 0; $this->turnitintooltwo->erater_usage = isset($this->turnitintooltwo->erater_usage) ? $this->turnitintooltwo->erater_usage : 0; $this->turnitintooltwo->erater_mechanics = isset($this->turnitintooltwo->erater_mechanics) ? $this->turnitintooltwo->erater_mechanics : 0; $this->turnitintooltwo->erater_style = isset($this->turnitintooltwo->erater_style) ? $this->turnitintooltwo->erater_style : 0; $this->turnitintooltwo->transmatch = isset($this->turnitintooltwo->transmatch) ? $this->turnitintooltwo->transmatch : 0; $this->turnitintooltwo->institution_check = isset($this->turnitintooltwo->institution_check) ? $this->turnitintooltwo->institution_check : 0; // Update each individual part. for ($i = 1; $i <= $this->turnitintooltwo->numparts; $i++) { // Update Turnitin Assignment. $assignment = new TiiAssignment(); $assignment->setClassId($course->turnitin_cid); $assignment->setAuthorOriginalityAccess($this->turnitintooltwo->studentreports); $assignment->setRubricId(!empty($this->turnitintooltwo->rubric) ? $this->turnitintooltwo->rubric : ''); $assignment->setSubmitPapersTo($this->turnitintooltwo->submitpapersto); $assignment->setResubmissionRule($this->turnitintooltwo->reportgenspeed); $assignment->setBibliographyExcluded($this->turnitintooltwo->excludebiblio); $assignment->setQuotedExcluded($this->turnitintooltwo->excludequoted); $assignment->setSmallMatchExclusionType($this->turnitintooltwo->excludetype); $assignment->setSmallMatchExclusionThreshold((int) $this->turnitintooltwo->excludevalue); $assignment->setLateSubmissionsAllowed($this->turnitintooltwo->allowlate); if ($config->repositoryoption == 1) { $assignment->setInstitutionCheck(isset($this->turnitintooltwo->institution_check) ? $this->turnitintooltwo->institution_check : 0); } $attribute = "maxmarks" . $i; $assignment->setMaxGrade($this->turnitintooltwo->{$attribute}); $assignment->setSubmittedDocumentsCheck($this->turnitintooltwo->spapercheck); $assignment->setInternetCheck($this->turnitintooltwo->internetcheck); $assignment->setPublicationsCheck($this->turnitintooltwo->journalcheck); $assignment->setTranslatedMatching($this->turnitintooltwo->transmatch); $assignment->setAllowNonOrSubmissions($this->turnitintooltwo->allownonor); // Erater settings. $assignment->setErater(isset($this->turnitintooltwo->erater) ? $this->turnitintooltwo->erater : 0); $assignment->setEraterSpelling($this->turnitintooltwo->erater_spelling); $assignment->setEraterGrammar($this->turnitintooltwo->erater_grammar); $assignment->setEraterUsage($this->turnitintooltwo->erater_usage); $assignment->setEraterMechanics($this->turnitintooltwo->erater_mechanics); $assignment->setEraterStyle($this->turnitintooltwo->erater_style); $assignment->setEraterSpellingDictionary(isset($this->turnitintooltwo->erater_dictionary) ? $this->turnitintooltwo->erater_dictionary : 'en_US'); $assignment->setEraterHandbook(isset($this->turnitintooltwo->erater_handbook) ? $this->turnitintooltwo->erater_handbook : 0); $attribute = "dtstart" . $i; $assignment->setStartDate(gmdate("Y-m-d\\TH:i:s\\Z", $this->turnitintooltwo->{$attribute})); $attribute = "dtdue" . $i; $assignment->setDueDate(gmdate("Y-m-d\\TH:i:s\\Z", $this->turnitintooltwo->{$attribute})); $attribute = "dtpost" . $i; $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\\TH:i:s\\Z", $this->turnitintooltwo->{$attribute})); $attribute = "partname" . $i; $assignment->setTitle($this->turnitintooltwo->name . " " . $this->turnitintooltwo->{$attribute} . " (Moodle TT)"); // Initialise part. $part = new stdClass(); $part->turnitintooltwoid = $this->id; $part->partname = $this->turnitintooltwo->{$attribute}; $part->deleted = 0; $part->maxmarks = $assignment->getMaxGrade(); $part->dtstart = strtotime($assignment->getStartDate()); $part->dtdue = strtotime($assignment->getDueDate()); $part->dtpost = strtotime($assignment->getFeedbackReleaseDate()); $parttiiassignid = 0; if ($i <= count($partids) && !empty($partids[$i - 1])) { $partdetails = $this->get_part_details($partids[$i - 1]); $part->submitted = $partdetails->submitted; $part->unanon = $partdetails->unanon; // Set anonymous marking depending on whether part has been unanonymised. if ($config->useanon && $partdetails->unanon != 1) { $assignment->setAnonymousMarking($this->turnitintooltwo->anon); } $parttiiassignid = $partdetails->tiiassignid; } if ($parttiiassignid > 0) { $assignment->setAssignmentId($parttiiassignid); $this->edit_tii_assignment($assignment); } else { $parttiiassignid = $this->create_tii_assignment($assignment, $this->id, $i); $part->submitted = 0; } $part->tiiassignid = $parttiiassignid; // Unanonymise part if necessary. if ($part->dtpost < time() && $part->submitted == 1) { $part->unanon = 1; } $properties = new stdClass(); $properties->name = $this->turnitintooltwo->name . ' - ' . $part->partname; $properties->description = $this->turnitintooltwo->intro; $properties->courseid = $this->turnitintooltwo->course; $properties->groupid = 0; $properties->userid = 0; $properties->modulename = 'turnitintooltwo'; $properties->instance = $this->id; $properties->eventtype = 'due'; $properties->timestart = $part->dtdue; $properties->timeduration = 0; if ($i <= count($partids) && !empty($partdetails->id)) { $part->id = $partids[$i - 1]; // Get Current Moodle part data. if (!($partnow = $DB->get_record("turnitintooltwo_parts", array("id" => $part->id)))) { turnitintooltwo_print_error('partgeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } if (!($dbpart = $DB->update_record('turnitintooltwo_parts', $part))) { turnitintooltwo_print_error('partupdateerror', 'turnitintooltwo', null, $i, __FILE__, __LINE__); exit; } else { turnitintooltwo_activitylog("Moodle Assignment part updated (" . $part->id . ") - " . $part->partname, "REQUEST"); } // Delete existing events for this assignment part. $eventname = $turnitintooltwonow->name . " - " . $partnow->partname; $dbselect = " modulename = ? AND instance = ? AND name LIKE ? "; // Moodle pre 2.5 on SQL Server errors here as queries weren't allowed on ntext fields, the relevant fields // are nvarchar from 2.6 onwards so we have to cast the relevant fields in pre 2.5 SQL Server setups. if ($CFG->branch <= 25 && $CFG->dbtype == "sqlsrv") { $dbselect = " CAST(modulename AS nvarchar(max)) = ? AND instance = ? AND CAST(name AS nvarchar(max)) = ? "; } $DB->delete_records_select('event', $dbselect, array('turnitintooltwo', $this->id, $eventname)); } else { if (!($dbpart = $DB->insert_record('turnitintooltwo_parts', $part))) { turnitintooltwo_print_error('partdberror', 'turnitintooltwo', null, $i, __FILE__, __LINE__); exit; } } if ($createevent == true) { require_once $CFG->dirroot . '/calendar/lib.php'; $event = new calendar_event($properties); $event->update($properties, false); } } $this->turnitintooltwo->timemodified = time(); $update = $DB->update_record("turnitintooltwo", $this->turnitintooltwo); turnitintooltwo_activitylog("Turnitintool updated (" . $this->id . ") - " . $this->turnitintooltwo->name, "REQUEST"); // Define grade settings. if (!isset($_SESSION['tii_assignment_reset'])) { turnitintooltwo_grade_item_update($this->turnitintooltwo); } return $update; }
/** * Function called by course/reset.php when resetting moodle course, this is used to duplicate or reset a courses Turnitin * activities. If action specified is 'NEWCLASS' we are creating a new class on Turnitin. For both actions we create new * assignments on Turnitin and replace the turnitin ids for those parts in the database. * * @global object * @param var $courseid The course ID for the course to reset * @param string $action The action to use OLDCLASS or NEWCLASS * @return array The status array to pass to turnitintooltwo_reset_userdata */ function turnitintooltwo_duplicate_recycle($courseid, $action) { set_time_limit(0); global $DB, $USER; $config = turnitintooltwo_admin_config(); $partsarray = array(); $error = false; $turnitintooltwouser = new turnitintooltwo_user($USER->id, "Instructor"); $turnitintooltwouser->set_user_values_from_tii(); $instructorrubrics = $turnitintooltwouser->get_instructor_rubrics(); if (!($turnitintooltwos = $DB->get_records('turnitintooltwo', array('course' => $courseid)))) { turnitintooltwo_print_error('assigngeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } if (!($course = $DB->get_record('course', array('id' => $courseid)))) { turnitintooltwo_print_error('coursegeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } foreach ($turnitintooltwos as $turnitintooltwo) { if (!($parts = $DB->get_records('turnitintooltwo_parts', array('turnitintooltwoid' => $turnitintooltwo->id, 'deleted' => 0)))) { turnitintooltwo_print_error('partgeterror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } foreach ($parts as $part) { $partsarray[$courseid][$turnitintooltwo->id][$part->id]['tiiassignid'] = $part->tiiassignid; } } $currentcourse = turnitintooltwo_assignment::get_course_data($courseid); if ($action == "NEWCLASS") { // Delete Turnitin class link. if (!($delete = $DB->delete_records('turnitintooltwo_courses', array('courseid' => $courseid)))) { turnitintooltwo_print_error('coursedeleteerror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } $currentcourse->tii_rel_id = ''; // Create a new class to use with new parts. $tmpassignment = new turnitintooltwo_assignment(0, '', ''); $newcourse = $tmpassignment->create_tii_course($currentcourse, $USER->id); // Join Instructor to class. $turnitintooltwouser->join_user_to_class($newcourse->turnitin_cid); $currentcourse->turnitin_cid = $newcourse->turnitin_cid; $currentcourse->turnitin_ctl = $newcourse->turnitin_ctl; } // Create array of all the Turnitin assignment ids. $assignmentids = array(); foreach ($partsarray[$courseid] as $tiitoolid => $tiitool) { foreach ($tiitool as $partid => $data) { $assignmentids[] = $data['tiiassignid']; } } // Update all the assignments and parts from Turnitin. $turnitintooltwoassignment = new turnitintooltwo_assignment(0, '', ''); $turnitintooltwoassignment->update_assignment_from_tii($assignmentids); // Loop through Turnitintool instances and re-create assignment on Turnitin then swap over the stored Turnitin ids. foreach ($partsarray[$courseid] as $tiitoolid => $tiitool) { $turnitintooltwoassignment = new turnitintooltwo_assignment($tiitoolid); // Create new Assignment parts on Turnitin. $i = 0; foreach ($tiitool as $partid => $data) { $i++; $assignment = new TiiAssignment(); $assignment->setClassId($currentcourse->turnitin_cid); $assignment->setAuthorOriginalityAccess($turnitintooltwoassignment->turnitintooltwo->studentreports); $rubric_id = !empty($turnitintooltwoassignment->turnitintooltwo->rubric) ? $turnitintooltwoassignment->turnitintooltwo->rubric : ''; $rubric_id = !empty($rubric_id) && array_key_exists($rubric_id, $instructorrubrics) ? $rubric_id : ''; $assignment->setRubricId($rubric_id); $assignment->setSubmitPapersTo($turnitintooltwoassignment->turnitintooltwo->submitpapersto); $assignment->setResubmissionRule($turnitintooltwoassignment->turnitintooltwo->reportgenspeed); $assignment->setBibliographyExcluded($turnitintooltwoassignment->turnitintooltwo->excludebiblio); $assignment->setQuotedExcluded($turnitintooltwoassignment->turnitintooltwo->excludequoted); $assignment->setSmallMatchExclusionType($turnitintooltwoassignment->turnitintooltwo->excludetype); $assignment->setSmallMatchExclusionThreshold((int) $turnitintooltwoassignment->turnitintooltwo->excludevalue); if ($config->useanon) { $assignment->setAnonymousMarking($turnitintooltwoassignment->turnitintooltwo->anon); } $assignment->setLateSubmissionsAllowed($turnitintooltwoassignment->turnitintooltwo->allowlate); if ($config->repositoryoption == 1) { $assignment->setInstitutionCheck(isset($turnitintooltwoassignment->turnitintooltwo->institution_check) ? $turnitintooltwoassignment->turnitintooltwo->institution_check : 0); } $attribute = "maxmarks" . $i; $assignment->setMaxGrade($turnitintooltwoassignment->turnitintooltwo->{$attribute}); $assignment->setSubmittedDocumentsCheck($turnitintooltwoassignment->turnitintooltwo->spapercheck); $assignment->setInternetCheck($turnitintooltwoassignment->turnitintooltwo->internetcheck); $assignment->setPublicationsCheck($turnitintooltwoassignment->turnitintooltwo->journalcheck); $assignment->setTranslatedMatching($turnitintooltwoassignment->turnitintooltwo->transmatch); $assignment->setAllowNonOrSubmissions($turnitintooltwoassignment->turnitintooltwo->allownonor); // Erater settings. $assignment->setErater(isset($turnitintooltwoassignment->turnitintooltwo->erater) ? $turnitintooltwoassignment->turnitintooltwo->erater : 0); $assignment->setEraterSpelling($turnitintooltwoassignment->turnitintooltwo->erater_spelling); $assignment->setEraterGrammar($turnitintooltwoassignment->turnitintooltwo->erater_grammar); $assignment->setEraterUsage($turnitintooltwoassignment->turnitintooltwo->erater_usage); $assignment->setEraterMechanics($turnitintooltwoassignment->turnitintooltwo->erater_mechanics); $assignment->setEraterStyle($turnitintooltwoassignment->turnitintooltwo->erater_style); $assignment->setEraterSpellingDictionary(isset($turnitintooltwoassignment->turnitintooltwo->erater_dictionary) ? $turnitintooltwoassignment->turnitintooltwo->erater_dictionary : 'en_US'); $assignment->setEraterHandbook(isset($turnitintooltwoassignment->turnitintooltwo->erater_handbook) ? $turnitintooltwoassignment->turnitintooltwo->erater_handbook : 0); $attribute = "dtstart" . $i; $assignment->setStartDate(gmdate("Y-m-d\\TH:i:s\\Z", $turnitintooltwoassignment->turnitintooltwo->{$attribute})); $attribute = "dtdue" . $i; $assignment->setDueDate(gmdate("Y-m-d\\TH:i:s\\Z", $turnitintooltwoassignment->turnitintooltwo->{$attribute})); $attribute = "dtpost" . $i; $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\\TH:i:s\\Z", $turnitintooltwoassignment->turnitintooltwo->{$attribute})); $attribute = "partname" . $i; $assignment->setTitle($turnitintooltwoassignment->turnitintooltwo->name . " " . $turnitintooltwoassignment->turnitintooltwo->{$attribute} . " (Moodle TT)"); $partassignid = $turnitintooltwoassignment->create_tii_assignment($assignment, $turnitintooltwoassignment->turnitintooltwo->id, $i); if (empty($partassignid)) { turnitintooltwo_activitylog("Moodle Assignment could not be created (" . $turnitintooltwoassignment->id . ") - " . $turnitintooltwoassignment->turnitintooltwo->name, "REQUEST"); $error = true; } $part = new stdClass(); $part->id = $partid; $part->tiiassignid = $partassignid; $part->turnitintooltwoid = $turnitintooltwoassignment->turnitintooltwo->id; $part->partname = $turnitintooltwoassignment->turnitintooltwo->{$attribute}; $part->deleted = 0; $part->maxmarks = $assignment->getMaxGrade(); $part->dtstart = strtotime($assignment->getStartDate()); $part->dtdue = strtotime($assignment->getDueDate()); $part->dtpost = strtotime($assignment->getFeedbackReleaseDate()); if (!($dbpart = $DB->update_record('turnitintooltwo_parts', $part))) { turnitintooltwo_print_error('partupdateerror', 'turnitintooltwo', null, $i, __FILE__, __LINE__); exit; } else { turnitintooltwo_activitylog("Moodle Assignment part updated (" . $part->id . ")", "REQUEST"); } if (!($delete = $DB->delete_records('turnitintooltwo_submissions', array('submission_part' => $partid)))) { turnitintooltwo_print_error('submissiondeleteerror', 'turnitintooltwo', null, null, __FILE__, __LINE__); exit; } } } $item = $action == "NEWCLASS" ? get_string('copyassigndata', 'turnitintooltwo') : get_string('replaceassigndata', 'turnitintooltwo'); $status[] = array('component' => get_string('modulenameplural', 'turnitintooltwo'), 'item' => $item, 'error' => $error); return $status; }
/** * Create the module as an assignment within Turnitin if it does not exist, * if we have a Turnitin id for the module then edit it */ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site", $submittoturnitin = false) { global $DB, $CFG; $config = turnitintooltwo_admin_config(); $modulepluginsettings = $this->get_settings($cm->id); $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); // Configure assignment object to send to Turnitin. $assignment = new TiiAssignment(); $assignment->setClassId($coursetiiid); // We need to truncate the moodle assignment title to be compatible with a Turnitin // assignment title (max length 99) and account for non English multibyte strings. $title = ""; if (mb_strlen($moduledata->name, 'UTF-8') > 80) { $title .= mb_substr($moduledata->name, 0, 80, 'UTF-8') . "..."; } else { $title .= $moduledata->name; } $title .= " (Moodle PP)"; $assignment->setTitle($title); $assignment->setSubmitPapersTo(isset($modulepluginsettings["plagiarism_submitpapersto"]) ? $modulepluginsettings["plagiarism_submitpapersto"] : 1); $assignment->setSubmittedDocumentsCheck($modulepluginsettings["plagiarism_compare_student_papers"]); $assignment->setInternetCheck($modulepluginsettings["plagiarism_compare_internet"]); $assignment->setPublicationsCheck($modulepluginsettings["plagiarism_compare_journals"]); if ($config->repositoryoption == 1) { $institutioncheck = isset($modulepluginsettings["plagiarism_compare_institution"]) ? $modulepluginsettings["plagiarism_compare_institution"] : 0; $assignment->setInstitutionCheck($institutioncheck); } $assignment->setAuthorOriginalityAccess($modulepluginsettings["plagiarism_show_student_report"]); $assignment->setResubmissionRule((int) $modulepluginsettings["plagiarism_report_gen"]); $assignment->setBibliographyExcluded($modulepluginsettings["plagiarism_exclude_biblio"]); $assignment->setQuotedExcluded($modulepluginsettings["plagiarism_exclude_quoted"]); $assignment->setSmallMatchExclusionType($modulepluginsettings["plagiarism_exclude_matches"]); $modulepluginsettings["plagiarism_exclude_matches_value"] = !empty($modulepluginsettings["plagiarism_exclude_matches_value"]) ? $modulepluginsettings["plagiarism_exclude_matches_value"] : 0; $assignment->setSmallMatchExclusionThreshold($modulepluginsettings["plagiarism_exclude_matches_value"]); // Don't set anonymous marking if there have been submissions. $previoussubmissions = $DB->record_exists('plagiarism_turnitin_files', array('cm' => $cm->id, 'statuscode' => 'success')); // Use Moodle's blind marking setting for anonymous marking. if ($config->useanon && !$previoussubmissions) { $anonmarking = !empty($moduledata->blindmarking) ? 1 : 0; $assignment->setAnonymousMarking($anonmarking); } $assignment->setAllowNonOrSubmissions(!empty($modulepluginsettings["plagiarism_allow_non_or_submissions"]) ? 1 : 0); $assignment->setTranslatedMatching(!empty($modulepluginsettings["plagiarism_transmatch"]) ? 1 : 0); // Moodle handles submissions and whether they are allowed so this should always be true. // Otherwise, the Turnitin setting is incompatible with Moodle due to multiple files and resubmission rules. $assignment->setLateSubmissionsAllowed(1); $assignment->setMaxGrade(0); $assignment->setRubricId(!empty($modulepluginsettings["plagiarism_rubric"]) ? $modulepluginsettings["plagiarism_rubric"] : ''); if (!empty($moduledata->grade)) { $assignment->setMaxGrade($moduledata->grade < 0 ? 100 : (int) $moduledata->grade); } if (!empty($moduledata->allowsubmissionsfromdate)) { $dtstart = $moduledata->allowsubmissionsfromdate; } else { if (!empty($moduledata->timeavailable)) { $dtstart = $moduledata->timeavailable; } else { $dtstart = $cm->added; } } $dtstart = $dtstart <= strtotime('-1 year') ? strtotime('-11 months') : $dtstart; $assignment->setStartDate(gmdate("Y-m-d\\TH:i:s\\Z", $dtstart)); // Set post date. If "hidden until" has been set in gradebook then we will use that value, otherwise we will // use start date. If the grades are to be completely hidden then we will set post date in the future. // From 2.6, if grading markflow is enabled and no grades have been released, we will use due date +4 weeks. $dtpost = 0; if ($cm->modname != "forum") { if ($gradeitem = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course, 'itemnumber' => 0))) { switch ($gradeitem->hidden) { case 1: $dtpost = strtotime('+6 months'); break; case 0: $dtpost = $dtstart; // If any grades have been released early via marking workflow, set post date to current time. if ($cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists('assign_user_flags', array('assignment' => $cm->instance, 'workflowstate' => 'released')); $dtpost = $gradesreleased ? time() : strtotime('+1 month'); } break; default: $dtpost = $gradeitem->hidden; break; } } } // If blind marking is being used and identities have not been revealed then push out post date. if ($cm->modname == 'assign' && !empty($moduledata->blindmarking) && empty($moduledata->revealidentities)) { $dtpost = strtotime('+6 months'); } // If blind marking is being used for coursework then push out post date. if ($cm->modname == 'coursework' && !empty($moduledata->blindmarking)) { $dtpost = strtotime('+6 months'); } // Ensure post date can't be before start date if ($dtpost < $dtstart) { $dtpost = $dtstart; } // Set due date, dependent on various things. $dtdue = !empty($moduledata->duedate) ? $moduledata->duedate : 0; // If the due date has been set more than a year ahead then restrict it to 1 year from now. if ($dtdue > strtotime('+1 year')) { $dtdue = strtotime('+1 year'); } // Ensure due date can't be before start date if ($dtdue <= $dtstart) { $dtdue = strtotime('+1 month', $dtstart); } // Ensure due date is always in the future for submissions. if ($dtdue <= time() && $submittoturnitin) { $dtdue = strtotime('+1 day'); } $assignment->setDueDate(gmdate("Y-m-d\\TH:i:s\\Z", $dtdue)); // If the duedate is in the future then set any submission duedate_report_refresh flags that are 2 to 1 to make sure they are re-examined in the next cron run if ($dtdue > time()) { $DB->set_field('plagiarism_turnitin_files', 'duedate_report_refresh', 1, array('cm' => $cm->id, 'duedate_report_refresh' => 2)); } $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\\TH:i:s\\Z", $dtpost)); // Erater settings. $assignment->setErater(isset($modulepluginsettings["plagiarism_erater"]) ? $modulepluginsettings["plagiarism_erater"] : 0); $assignment->setEraterSpelling(isset($modulepluginsettings["plagiarism_erater_spelling"]) ? $modulepluginsettings["plagiarism_erater_spelling"] : 0); $assignment->setEraterGrammar(isset($modulepluginsettings["plagiarism_erater_grammar"]) ? $modulepluginsettings["plagiarism_erater_grammar"] : 0); $assignment->setEraterUsage(isset($modulepluginsettings["plagiarism_erater_usage"]) ? $modulepluginsettings["plagiarism_erater_usage"] : 0); $assignment->setEraterMechanics(isset($modulepluginsettings["plagiarism_erater_mechanics"]) ? $modulepluginsettings["plagiarism_erater_mechanics"] : 0); $assignment->setEraterStyle(isset($modulepluginsettings["plagiarism_erater_style"]) ? $modulepluginsettings["plagiarism_erater_style"] : 0); $assignment->setEraterSpellingDictionary(isset($modulepluginsettings["plagiarism_erater_dictionary"]) ? $modulepluginsettings["plagiarism_erater_dictionary"] : 'en_US'); $assignment->setEraterHandbook(isset($modulepluginsettings["plagiarism_erater_handbook"]) ? $modulepluginsettings["plagiarism_erater_handbook"] : 0); // If we have a turnitin id then edit the assignment otherwise create it. if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid'), 'value')) { $assignment->setAssignmentId($tiiassignment->value); $turnitintooltwoassignment = new turnitintooltwo_assignment(0, '', 'PP'); $return = $turnitintooltwoassignment->edit_tii_assignment($assignment, $workflowcontext); $return['errorcode'] = $return['success'] ? 0 : 6; return $return; } else { $turnitintooltwoassignment = new turnitintooltwo_assignment(0, '', 'PP'); $turnitinassignid = $turnitintooltwoassignment->create_tii_assignment($assignment, 0, 0, 'plagiarism_plugin', $workflowcontext); if (!$turnitinassignid) { $return = array('success' => false, 'tiiassignmentid' => '', 'errorcode' => 5); } else { $moduleconfigvalue = new stdClass(); $moduleconfigvalue->cm = $cm->id; $moduleconfigvalue->name = 'turnitin_assignid'; $moduleconfigvalue->value = $turnitinassignid; $DB->insert_record('plagiarism_turnitin_config', $moduleconfigvalue); $return = array('success' => true, 'tiiassignmentid' => $assignment->getAssignmentId()); } return $return; } }
/** * Create the module as an assignment within Turnitin if it does not exist, * if we have a Turnitin id for the module then edit it */ public function sync_tii_assignment($cm, $coursetiiid, $workflowcontext = "site") { global $DB, $CFG; $config = turnitintooltwo_admin_config(); $modulepluginsettings = $this->get_settings($cm->id); $moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance)); // Configure assignment object to send to Turnitin. $assignment = new TiiAssignment(); $assignment->setClassId($coursetiiid); // Need to truncate the moodle assignment title to be compatible with a Turnitin class (max length 99) $assignment->setTitle(mb_strlen($moduledata->name) > 80 ? mb_substr($moduledata->name, 0, 80) . "... (Moodle PP)" : $moduledata->name . " (Moodle PP)"); $assignment->setSubmitPapersTo(isset($modulepluginsettings["plagiarism_submitpapersto"]) ? $modulepluginsettings["plagiarism_submitpapersto"] : 1); $assignment->setSubmittedDocumentsCheck($modulepluginsettings["plagiarism_compare_student_papers"]); $assignment->setInternetCheck($modulepluginsettings["plagiarism_compare_internet"]); $assignment->setPublicationsCheck($modulepluginsettings["plagiarism_compare_journals"]); if ($config->repositoryoption == 1) { $institutioncheck = isset($modulepluginsettings["plagiarism_compare_institution"]) ? $modulepluginsettings["plagiarism_compare_institution"] : 0; $assignment->setInstitutionCheck($institutioncheck); } $assignment->setAuthorOriginalityAccess($modulepluginsettings["plagiarism_show_student_report"]); $assignment->setResubmissionRule($modulepluginsettings["plagiarism_report_gen"]); $assignment->setBibliographyExcluded($modulepluginsettings["plagiarism_exclude_biblio"]); $assignment->setQuotedExcluded($modulepluginsettings["plagiarism_exclude_quoted"]); $assignment->setSmallMatchExclusionType($modulepluginsettings["plagiarism_exclude_matches"]); $modulepluginsettings["plagiarism_exclude_matches_value"] = !empty($modulepluginsettings["plagiarism_exclude_matches_value"]) ? $modulepluginsettings["plagiarism_exclude_matches_value"] : 0; $assignment->setSmallMatchExclusionThreshold($modulepluginsettings["plagiarism_exclude_matches_value"]); if ($config->useanon) { $assignment->setAnonymousMarking($modulepluginsettings["plagiarism_anonymity"]); } $assignment->setAllowNonOrSubmissions(!empty($modulepluginsettings["plagiarism_allow_non_or_submissions"]) ? 1 : 0); $assignment->setTranslatedMatching(!empty($modulepluginsettings["plagiarism_transmatch"]) ? 1 : 0); // Moodle handles submissions and whether they are allowed so this should always be true. // Otherwise, the Turnitin setting is incompatible with Moodle due to multiple files and resubmission rules. $assignment->setLateSubmissionsAllowed(1); $assignment->setMaxGrade(0); $assignment->setRubricId(!empty($modulepluginsettings["plagiarism_rubric"]) ? $modulepluginsettings["plagiarism_rubric"] : ''); if (!empty($moduledata->grade)) { $assignment->setMaxGrade($moduledata->grade < 0 ? 100 : (int) $moduledata->grade); } if (!empty($moduledata->allowsubmissionsfromdate)) { $dtstart = $moduledata->allowsubmissionsfromdate; } else { if (!empty($moduledata->timeavailable)) { $dtstart = $moduledata->timeavailable; } else { $dtstart = $cm->added; } } $dtstart = $dtstart <= strtotime('-1 year') ? strtotime('-11 months') : $dtstart; $assignment->setStartDate(gmdate("Y-m-d\\TH:i:s\\Z", $dtstart)); $dtdue = 0; if (!empty($moduledata->duedate)) { $dtdue = $moduledata->duedate; } else { if (!empty($moduledata->timedue)) { $dtdue = $moduledata->timedue; } } // If the due date has been set more than a year ahead then restrict the // due date in Turnitin to 1 year from now. $nextyear = strtotime('+1 year'); if ($dtdue > $nextyear) { $dtdue = $nextyear; } // Set post date. If "hidden until" has been set in gradebook then we will use that value, otherwise we will // use start date. If the grades are to be completely hidden then we will set post date in the future. // From 2.6, if grading markflow is enabled and no grades have been released, we will use due date +4 weeks. $dtpost = 0; if ($cm->modname != "forum") { if ($gradeitem = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $cm->modname, 'courseid' => $cm->course))) { switch ($gradeitem->hidden) { case 1: $dtpost = strtotime('+6 months'); break; case 0: $dtpost = $dtstart; // If any grades have been released early via marking workflow, set post date to current time. if ($CFG->branch >= 26 && $cm->modname == 'assign' && !empty($moduledata->markingworkflow)) { $gradesreleased = $DB->record_exists('assign_user_flags', array('assignment' => $cm->instance, 'workflowstate' => 'released')); if ($gradesreleased) { $dtpost = time(); } else { $dtpost = strtotime('+4 weeks', $dtdue); } } break; default: $dtpost = $gradeitem->hidden; break; } } } // If a cut-off date has been set, use that as the Turnitin due date. if (!empty($moduledata->cutoffdate)) { $dtdue = $moduledata->cutoffdate; } // Ensure due date can't be before start date if ($dtdue <= $dtstart) { $dtdue = strtotime('+1 month', $dtstart); } // Ensure post date can't be before start date if ($dtpost < $dtstart) { $dtpost = $dtstart; } $assignment->setDueDate(gmdate("Y-m-d\\TH:i:s\\Z", $dtdue)); $assignment->setFeedbackReleaseDate(gmdate("Y-m-d\\TH:i:s\\Z", $dtpost)); // Erater settings. $assignment->setErater(isset($modulepluginsettings["plagiarism_erater"]) ? $modulepluginsettings["plagiarism_erater"] : 0); $assignment->setEraterSpelling(isset($modulepluginsettings["plagiarism_erater_spelling"]) ? $modulepluginsettings["plagiarism_erater_spelling"] : 0); $assignment->setEraterGrammar(isset($modulepluginsettings["plagiarism_erater_grammar"]) ? $modulepluginsettings["plagiarism_erater_grammar"] : 0); $assignment->setEraterUsage(isset($modulepluginsettings["plagiarism_erater_usage"]) ? $modulepluginsettings["plagiarism_erater_usage"] : 0); $assignment->setEraterMechanics(isset($modulepluginsettings["plagiarism_erater_mechanics"]) ? $modulepluginsettings["plagiarism_erater_mechanics"] : 0); $assignment->setEraterStyle(isset($modulepluginsettings["plagiarism_erater_style"]) ? $modulepluginsettings["plagiarism_erater_style"] : 0); $assignment->setEraterSpellingDictionary(isset($modulepluginsettings["plagiarism_erater_dictionary"]) ? $modulepluginsettings["plagiarism_erater_dictionary"] : 'en_US'); $assignment->setEraterHandbook(isset($modulepluginsettings["plagiarism_erater_handbook"]) ? $modulepluginsettings["plagiarism_erater_handbook"] : 0); // If we have a turnitin id then edit the assignment otherwise create it. if ($tiiassignment = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'turnitin_assignid'), 'value')) { $assignment->setAssignmentId($tiiassignment->value); $turnitintooltwoassignment = new turnitintooltwo_assignment(0, '', 'PP'); $turnitintooltwoassignment->edit_tii_assignment($assignment, $workflowcontext); $turnitinassignid = $tiiassignment->value; } else { $turnitintooltwoassignment = new turnitintooltwo_assignment(0, '', 'PP'); $turnitinassignid = $turnitintooltwoassignment->create_tii_assignment($assignment, 0, 0, 'plagiarism_plugin', $workflowcontext); $moduleconfigvalue = new stdClass(); $moduleconfigvalue->cm = $cm->id; $moduleconfigvalue->name = 'turnitin_assignid'; $moduleconfigvalue->value = $turnitinassignid; $DB->insert_record('plagiarism_turnitin_config', $moduleconfigvalue); } // Save the post date we have stored in Turnitin $moduleconfigvalue = new stdClass(); $moduleconfigvalue->cm = $cm->id; $moduleconfigvalue->name = 'plagiarism_post_date'; $moduleconfigvalue->value = $dtpost; if ($plagiarism_post_date = $DB->get_record('plagiarism_turnitin_config', array('cm' => $cm->id, 'name' => 'plagiarism_post_date'), 'id')) { $moduleconfigvalue->id = $plagiarism_post_date->id; $DB->update_record('plagiarism_turnitin_config', $moduleconfigvalue); } else { $DB->insert_record('plagiarism_turnitin_config', $moduleconfigvalue); } return $turnitinassignid; }