public function definition() { global $CFG, $DB, $USER, $COURSE; $config = turnitintooltwo_admin_config(); // Module string is useful for product support. $modulestring = '<!-- Turnitin Moodle Direct Version: ' . turnitintooltwo_get_version() . ' - ('; // Get Moodle Course Object. $course = turnitintooltwo_assignment::get_course_data($COURSE->id); // Create or edit the class in Turnitin. if ($course->turnitin_cid == 0) { $tiicoursedata = turnitintooltwo_assignment::create_tii_course($course, $USER->id); $course->turnitin_cid = $tiicoursedata->turnitin_cid; $course->turnitin_ctl = $tiicoursedata->turnitin_ctl; } else { turnitintooltwo_assignment::edit_tii_course($course); $course->turnitin_ctl = $course->fullname . " (Moodle TT)"; } // Join this user to the class as an instructor and get their rubrics. $instructor = new turnitintooltwo_user($USER->id, 'Instructor'); $instructor->join_user_to_class($course->turnitin_cid); $instructor->set_user_values_from_tii(); $instructorrubrics = $instructor->get_instructor_rubrics(); // Get rubrics that are shared on the account. $turnitinclass = new turnitintooltwo_class($course->id); $turnitinclass->read_class_from_tii(); // Merge the arrays, prioitising instructor owned arrays. $rubrics = $instructorrubrics + $turnitinclass->sharedrubrics; $this->numsubs = 0; if (isset($this->_cm->id)) { $turnitintooltwoassignment = new turnitintooltwo_assignment($this->_cm->instance); $turnitintooltwoassignment->update_assignment_from_tii(); $this->turnitintooltwo = $DB->get_record("turnitintooltwo", array("id" => $this->_cm->instance)); $parts = $DB->get_records("turnitintooltwo_parts", array("turnitintooltwoid" => $this->_cm->instance, "deleted" => 0), 'id'); $i = 0; foreach ($parts as $part) { $i++; $attributes = array("id", "partname", "dtstart", "dtdue", "dtpost", "maxmarks"); foreach ($attributes as $att) { $attribute = $att . $i; $this->current->{$attribute} = $part->{$att}; } $attribute = "numsubs" . $i; $this->current->{$attribute} = $DB->count_records('turnitintooltwo_submissions', array('turnitintooltwoid' => $this->turnitintooltwo->id, 'submission_part' => $part->id)); $this->numsubs += $this->current->{$attribute}; $modulestring .= $modulestring != "(" ? " | " : ""; $modulestring .= $part->partname . ': ' . $part->tiiassignid; } $this->updating = true; } else { $this->updating = false; $instructordefaults = $instructor->get_instructor_defaults(); if (empty($instructordefaults)) { $instructordefaults = array(); } foreach ($instructordefaults as $k => $v) { $this->current->{$k} = $v; } } // Overwrite instructor default repository if admin is forcing repository setting switch ($config->repositoryoption) { case 2: // Force Standard Repository $this->current->submitpapersto = 1; break; case 3: // Force No Repository $this->current->submitpapersto = 0; break; } $modulestring .= ') -->'; $this->show_form($rubrics, $modulestring, $course->turnitin_cid); }
/** * 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); // Get rubrics that are shared on the account. $turnitinclass = new turnitintooltwo_class($courseid); $turnitinclass->read_class_from_tii(); $rubrics = $turnitinclass->sharedrubrics; $rubrics = $rubrics + $instructorrubrics; $rubric_id = !empty($turnitintooltwoassignment->turnitintooltwo->rubric) ? $turnitintooltwoassignment->turnitintooltwo->rubric : ''; $rubric_id = !empty($rubric_id) && array_key_exists($rubric_id, $rubrics) ? $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; }