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);
 }
 /**
  * Migrate course from previous version of plugin to this
  */
 public function migrate_previous_course($coursedata, $turnitincid, $workflowcontext = "site")
 {
     global $DB, $USER;
     $turnitincourse = new stdClass();
     $turnitincourse->courseid = $coursedata->id;
     $turnitincourse->ownerid = $USER->id;
     $turnitincourse->turnitin_cid = $turnitincid;
     $turnitincourse->turnitin_ctl = $coursedata->fullname . " (Moodle PP)";
     $turnitincourse->course_type = 'PP';
     if (empty($coursedata->tii_rel_id)) {
         $method = "insert_record";
     } else {
         $method = "update_record";
         $turnitincourse->id = $coursedata->tii_rel_id;
     }
     if (!($insertid = $DB->{$method}('turnitintooltwo_courses', $turnitincourse))) {
         if ($workflowcontext != "cron") {
             turnitintooltwo_print_error('classupdateerror', 'plagiarism_turnitin', null, null, __FILE__, __LINE__);
             exit;
         }
     }
     $turnitintooltwoassignment = new turnitintooltwo_assignment(0, '', 'PP');
     $turnitintooltwoassignment->edit_tii_course($coursedata, "PP");
     $coursedata->turnitin_cid = $turnitincid;
     $coursedata->turnitin_ctl = $turnitincourse->turnitin_ctl;
     return $coursedata;
 }