/**
  * Create a migrated turnitin assignment in Moodle
  *
  * @global type $DB
  * @global type $CFG
  * @param array $partids the ids of turnitin assignment to create as parts of new assignment
  * @param int $courseid
  * @param string $assignmentname
  * @return boolean false if failed
  */
 public static function create_migration_assignment($partids, $courseid, $assignmentname)
 {
     global $DB, $CFG, $OUTPUT;
     $config = turnitintooltwo_admin_config();
     $partids = (array) $partids;
     $tempassignment = new turnitintooltwo_assignment(0, '', 'M');
     $newassignment = $tempassignment->update_assignment_from_tii($partids);
     $newassignment["turnitintooltwo"]->course = $courseid;
     $newassignment["turnitintooltwo"]->name = $assignmentname;
     $newassignment["turnitintooltwo"]->numparts = count($partids);
     $newassignment["turnitintooltwo"]->gradedisplay = 1;
     $newassignment["turnitintooltwo"]->shownonsubmission = 1;
     $newassignment["turnitintooltwo"]->usegrademark = $config->usegrademark;
     // Get maximum grade.
     $newassignment["turnitintooltwo"]->grade = 0;
     foreach ($newassignment["parts"] as $part) {
         if ($newassignment["turnitintooltwo"]->grade < $part->maxmarks) {
             $newassignment["turnitintooltwo"]->grade = $part->maxmarks;
         }
     }
     $turnitintooltwoassignment = new turnitintooltwo_assignment(0, $newassignment["turnitintooltwo"]);
     if (!($toolid = $DB->insert_record("turnitintooltwo", $turnitintooltwoassignment->turnitintooltwo))) {
         turnitintooltwo_activitylog(get_string('migrationassignmentcreationerror', 'turnitintooltwo', $courseid), "REQUEST");
         return false;
     } else {
         turnitintooltwo_activitylog(get_string('migrationassignmentcreated', 'turnitintooltwo', $toolid), "REQUEST");
     }
     $module = $DB->get_record("modules", array("name" => "turnitintooltwo"));
     $coursemodule = new stdClass();
     $coursemodule->course = $courseid;
     $coursemodule->module = $module->id;
     $coursemodule->added = time();
     $coursemodule->instance = $toolid;
     $coursemodule->section = 0;
     include_once $CFG->dirroot . "/course/lib.php";
     // Add Course module and get course section.
     if (!($coursemodule->coursemodule = add_course_module($coursemodule))) {
         echo $OUTPUT->notification(get_string('migrationassignmenterror1', 'turnitintooltwo', $courseid));
         turnitintooltwo_activitylog(get_string('migrationassignmenterror1', 'turnitintooltwo', $courseid), "REQUEST");
         return false;
     }
     if (is_callable('course_add_cm_to_section')) {
         if (!($sectionid = course_add_cm_to_section($coursemodule->course, $coursemodule->coursemodule, $coursemodule->section))) {
             echo $OUTPUT->notification(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid));
             turnitintooltwo_activitylog(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid), "REQUEST");
             return false;
         }
     } else {
         if (!($sectionid = add_mod_to_section($coursemodule))) {
             echo $OUTPUT->notification(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid));
             turnitintooltwo_activitylog(get_string('migrationassignmenterror2', 'turnitintooltwo', $courseid), "REQUEST");
             return false;
         }
     }
     $DB->set_field("course_modules", "section", $sectionid, array("id" => $coursemodule->coursemodule));
     rebuild_course_cache($courseid);
     foreach ($newassignment["parts"] as $part) {
         $part->turnitintooltwoid = $toolid;
         $part->deleted = 0;
         $part->migrated = -1;
         if ($part->id = $DB->insert_record("turnitintooltwo_parts", $part)) {
             turnitintooltwo_activitylog(get_string('migrationassignmentpartcreated', 'turnitintooltwo', $part->id), "REQUEST");
         }
         if ($turnitintooltwoassignment->create_event($toolid, $part->partname, $part->dtdue)) {
             $part->migrated = 1;
             $DB->update_record("turnitintooltwo_parts", $part);
         } else {
             echo $OUTPUT->notification(get_string('migrationassignmenterror3', 'turnitintooltwo', $courseid));
             turnitintooltwo_activitylog(get_string('migrationassignmenterror3', 'turnitintooltwo', $courseid), "REQUEST");
         }
     }
 }
예제 #2
0
         echo 0;
     }
     break;
 case "refresh_peermark_assignments":
     if (!confirm_sesskey()) {
         throw new moodle_exception('invalidsesskey', 'error');
     }
     $assignmentid = required_param('assignment', PARAM_INT);
     $turnitintooltwoassignment = new turnitintooltwo_assignment($assignmentid);
     $cm = get_coursemodule_from_instance("turnitintooltwo", $assignmentid);
     if (has_capability('mod/turnitintooltwo:read', context_module::instance($cm->id))) {
         $partid = required_param('part', PARAM_INT);
         $refreshrequested = optional_param('refresh_requested', 0, PARAM_INT);
         $partdetails = $turnitintooltwoassignment->get_part_details($partid);
         if ($refreshrequested) {
             $turnitintooltwoassignment->update_assignment_from_tii(array($partdetails->tiiassignid));
             $partdetails = $turnitintooltwoassignment->get_part_details($partid);
         }
         $PAGE->set_context(context_module::instance($cm->id));
         $turnitintooltwoview = new turnitintooltwo_view();
         $peermarkdata['peermark_table'] = $turnitintooltwoview->show_peermark_assignment($partdetails->peermark_assignments);
         $peermarkdata['no_of_peermarks'] = count($partdetails->peermark_assignments);
         $peermarkdata['peermarks_active'] = false;
         foreach ($partdetails->peermark_assignments as $peermarkassignment) {
             if (time() > $peermarkassignment->dtstart) {
                 $peermarkdata['peermarks_active'] = true;
                 break;
             }
         }
         echo json_encode($peermarkdata);
     }
 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);
 }
예제 #4
0
/**
 * 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;
}
예제 #5
0
 public function definition()
 {
     global $CFG, $DB, $USER;
     $config = turnitintooltwo_admin_config();
     // Module string is useful for product support.
     if ($CFG->branch >= 26) {
         $pluginman = \core_plugin_manager::instance();
         $plugins = $pluginman->get_plugins();
         $module = $plugins['mod']['turnitintooltwo'];
     } else {
         $module = $DB->get_record('modules', array('name' => 'turnitintooltwo'));
     }
     $version = empty($module->version) ? $module->versiondisk : $module->version;
     $modulestring = '<!-- Turnitin Moodle Direct Version: ' . $version . ' - (';
     $this->numsubs = 0;
     $instructor = new turnitintooltwo_user($USER->id, 'Instructor');
     $instructor->set_user_values_from_tii();
     $instructorrubrics = $instructor->get_instructor_rubrics();
     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($instructorrubrics, $modulestring);
 }