/**
  * Update class from Turnitin, mainly to get shared rubrics
  *
  * @return
  */
 public function read_class_from_tii()
 {
     // Initialise Comms Object.
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     $tiiclass = new TiiClass();
     try {
         $tiiclass->setClassId($this->turnitinid);
         $response = $turnitincall->readClass($tiiclass);
         $readclass = $response->getClass();
         $rubrics = $readclass->getSharedRubrics();
         $rubricarray = array();
         foreach ($rubrics as $rubric) {
             $rubricarray[$rubric->getRubricId()] = $rubric->getRubricName() . " [" . get_string('sharedrubric', 'turnitintooltwo') . "]";
         }
         $this->sharedrubrics = $rubricarray;
     } catch (Exception $e) {
         $turnitincomms->handle_exceptions($e, 'coursegeterror', false);
     }
 }
 /**
  * Update assignment from Turnitin
  *
  * @global type $DB
  * @param array $assignmentids array of assignment ids, if 0 then array is created inside
  * @return object
  */
 public function update_assignment_from_tii($assignmentids = 0)
 {
     global $DB;
     // Initialise Comms Object.
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     if (!$assignmentids) {
         $parts = $this->get_parts();
         $assignments = array();
         foreach ($parts as $part) {
             $assignments[] = $part->tiiassignid;
             $partids[$part->tiiassignid] = $part->id;
         }
     } else {
         $assignments = $assignmentids;
     }
     $assignment = new TiiAssignment();
     try {
         if (count($assignments) == 1) {
             $assignment->setAssignmentId(current($assignments));
             $response = $turnitincall->readAssignment($assignment);
             $readassignments[0] = $response->getAssignment();
         } else {
             $assignment->setAssignmentIds($assignments);
             $response = $turnitincall->readAssignments($assignment);
             $readassignments = $response->getAssignments();
         }
         $assignmentdetails = "";
         $newparts = array();
         foreach ($readassignments as $readassignment) {
             $part = new stdClass();
             $part->dtstart = strtotime($readassignment->getStartDate());
             $part->dtdue = strtotime($readassignment->getDueDate());
             $part->dtpost = strtotime($readassignment->getFeedbackReleaseDate());
             $part->maxmarks = $readassignment->getMaxGrade();
             $part->tiiassignid = $readassignment->getAssignmentId();
             if ($assignmentids == 0) {
                 $part->id = $partids[$readassignment->getAssignmentId()];
                 if (!($dbpart = $DB->update_record('turnitintooltwo_parts', $part))) {
                     turnitintooltwo_activitylog(get_string('turnitintooltwoupdateerror', 'turnitintooltwo') . ' - ID: ' . $this->turnitintooltwo->id . ' - Part: ' . $part->id, 'API_ERROR');
                 }
             } else {
                 $part->partname = $readassignment->getTitle();
                 $newparts[] = $part;
             }
             // Update main turnitintooltwo details but only once.
             if (empty($assignmentdetails)) {
                 $assignmentdetails = new stdClass();
                 if ($assignmentids == 0) {
                     $assignmentdetails->id = $this->turnitintooltwo->id;
                 } else {
                     $assignmentdetails->timecreated = time();
                     $assignmentdetails->dateformat = "d/m/Y";
                     $assignmentdetails->autoupdates = 1;
                     $assignmentdetails->commentedittime = 1800;
                     $assignmentdetails->commentmaxsize = 800;
                     $assignmentdetails->autosubmission = 1;
                     $assignmentdetails->timemodified = time();
                     $assignmentdetails->intro = $readassignment->getInstructions();
                 }
                 $assignmentdetails->allowlate = $readassignment->getLateSubmissionsAllowed();
                 $assignmentdetails->reportgenspeed = $readassignment->getResubmissionRule();
                 $assignmentdetails->submitpapersto = $readassignment->getSubmitPapersTo();
                 $assignmentdetails->spapercheck = $readassignment->getSubmittedDocumentsCheck();
                 $assignmentdetails->internetcheck = $readassignment->getInternetCheck();
                 $assignmentdetails->journalcheck = $readassignment->getPublicationsCheck();
                 $assignmentdetails->studentreports = $readassignment->getAuthorOriginalityAccess();
                 $assignmentdetails->rubric = $readassignment->getRubricId();
                 $assignmentdetails->excludebiblio = $readassignment->getBibliographyExcluded();
                 $assignmentdetails->excludequoted = $readassignment->getQuotedExcluded();
                 $assignmentdetails->excludetype = $readassignment->getSmallMatchExclusionType();
                 $assignmentdetails->excludevalue = $readassignment->getSmallMatchExclusionThreshold();
                 $assignmentdetails->erater = $readassignment->getErater();
                 $assignmentdetails->erater_handbook = $readassignment->getEraterHandbook();
                 $assignmentdetails->erater_dictionary = $readassignment->getEraterSpellingDictionary();
                 $assignmentdetails->erater_spelling = (int) $readassignment->getEraterSpelling();
                 $assignmentdetails->erater_grammar = (int) $readassignment->getEraterGrammar();
                 $assignmentdetails->erater_usage = (int) $readassignment->getEraterUsage();
                 $assignmentdetails->erater_mechanics = (int) $readassignment->getEraterMechanics();
                 $assignmentdetails->erater_style = (int) $readassignment->getEraterStyle();
                 $assignmentdetails->transmatch = (int) $readassignment->getTranslatedMatching();
                 $assignmentdetails->allownonor = (int) $readassignment->getAllowNonOrSubmissions();
             }
             // Get Peermark Assignments.
             $peermarkassignments = $readassignment->getPeermarkAssignments();
             if (count($peermarkassignments)) {
                 $peermarkids = array();
                 foreach ($peermarkassignments as $peermarkassignment) {
                     $peermark = new stdClass();
                     $peermark->tiiassignid = $peermarkassignment->getAssignmentId();
                     $peermark->parent_tii_assign_id = $part->tiiassignid;
                     $peermark->dtstart = strtotime($peermarkassignment->getStartDate());
                     $peermark->dtdue = strtotime($peermarkassignment->getDueDate());
                     $peermark->dtpost = strtotime($peermarkassignment->getFeedbackReleaseDate());
                     $peermark->maxmarks = (int) $peermarkassignment->getMaxGrade();
                     $peermark->title = $peermarkassignment->getTitle();
                     $peermark->instructions = $peermarkassignment->getInstructions();
                     $peermark->distributed_reviews = (int) $peermarkassignment->getDistributedReviews();
                     $peermark->selected_reviews = (int) $peermarkassignment->getSelectedReviews();
                     $peermark->self_review = (int) $peermarkassignment->getSelfReviewRequired();
                     $peermark->non_submitters_review = (int) $peermarkassignment->getNonSubmittersToReview();
                     $currentpeermark = $DB->get_record('turnitintooltwo_peermarks', array('tiiassignid' => $peermark->tiiassignid));
                     if ($currentpeermark) {
                         $peermark->id = $currentpeermark->id;
                         $DB->update_record('turnitintooltwo_peermarks', $peermark);
                     } else {
                         $peermark->id = $DB->insert_record('turnitintooltwo_peermarks', $peermark);
                     }
                     $peermarkids[] = $peermark->id;
                 }
                 list($notinsql, $notinparams) = $DB->get_in_or_equal($peermarkids, SQL_PARAMS_QM, 'param', false);
                 $DB->delete_records_select('turnitintooltwo_peermarks', " parent_tii_assign_id = ? AND id " . $notinsql, array_merge(array($part->tiiassignid), $notinparams));
             } else {
                 $DB->delete_records('turnitintooltwo_peermarks', array('parent_tii_assign_id' => $part->tiiassignid));
             }
         }
         if ($assignmentids == 0) {
             if (!($update = $DB->update_record('turnitintooltwo', $assignmentdetails))) {
                 turnitintooltwo_activitylog(get_string('turnitintooltwoupdateerror', 'turnitintooltwo') . ' - ID: ' . $this->turnitintooltwo->id, 'API_ERROR');
             }
             $_SESSION["assignment_updated"][$this->turnitintooltwo->id] = time();
         } else {
             return array("turnitintooltwo" => $assignmentdetails, "parts" => $newparts);
         }
     } catch (Exception $e) {
         // We will use the locally stored assignment data if we can't connect to Turnitin.
         $turnitincomms->handle_exceptions($e, 'tiiassignmentgeterror', false);
     }
 }
 /**
  * Get whether the student has accepted the Turnitin User agreement
  *
  * @return boolean
  */
 public function get_accepted_user_agreement()
 {
     global $DB;
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     $user = new TiiUser();
     $user->setUserId($this->tii_user_id);
     try {
         $response = $turnitincall->readUser($user);
         $readuser = $response->getUser();
         if ($readuser->getAcceptedUserAgreement()) {
             $turnitintooltwouser = $DB->get_record('turnitintooltwo_users', array('userid' => $this->id));
             $tii_userinfo = new stdClass();
             $tii_userinfo->id = $turnitintooltwouser->id;
             $tii_userinfo->user_agreement_accepted = 1;
             $DB->update_record('turnitintooltwo_users', $tii_userinfo);
             return true;
         } else {
             return false;
         }
     } catch (Exception $e) {
         // User may not be joined to account so we'll join them and recall function
         $this->set_user_values_from_tii();
         $this->get_accepted_user_agreement();
         // $turnitincomms->handle_exceptions($e, 'tiiusergeterror');
     }
 }
 /**
  * Return the output for a form to launch the relevant LTi function
  * It is then submitted on load via Javascript
  *
  * @param string $userrole either Instructor or Learner
  * @param int $userid
  * @return output form
  */
 public static function output_lti_form_launch($type, $userrole, $partid = 0, $classid = 0)
 {
     global $USER, $CFG;
     // Initialise Comms Object.
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     $user = new turnitintooltwo_user($USER->id, $userrole);
     $lti = new TiiLTI();
     $lti->setUserId($user->tii_user_id);
     $lti->setRole($userrole);
     $lti->setFormTarget('');
     switch ($type) {
         case "messages_inbox":
             $ltifunction = "outputMessagesForm";
             break;
         case "rubric_manager":
             if ($classid != 0) {
                 $lti->setClassId($classid);
             }
             $ltifunction = "outputRubricManagerForm";
             break;
         case "rubric_view":
             $lti->setAssignmentId($partid);
             $ltifunction = "outputRubricViewForm";
             break;
         case "quickmark_manager":
             $ltifunction = "outputQuickmarkManagerForm";
             break;
         case "peermark_manager":
             $lti->setAssignmentId($partid);
             $ltifunction = "outputPeerMarkSetupForm";
             break;
         case "peermark_reviews":
             $lti->setAssignmentId($partid);
             $ltifunction = "outputPeerMarkReviewForm";
             break;
     }
     ob_start();
     $turnitincall->{$ltifunction}($lti);
     $rubricform = ob_get_contents();
     ob_end_clean();
     return $rubricform;
 }
Exemple #5
0
     echo json_encode($data);
     break;
 case "test_connection":
     if (!confirm_sesskey()) {
         throw new moodle_exception('invalidsesskey', 'error');
     }
     $data = array("connection_status" => "fail", "msg" => get_string('connecttestcommerror', 'turnitintooltwo'));
     if (is_siteadmin()) {
         // Initialise API connection.
         $account_id = required_param('account_id', PARAM_RAW);
         $account_shared = required_param('account_shared', PARAM_RAW);
         $url = required_param('url', PARAM_RAW);
         $turnitincomms = new turnitintooltwo_comms($account_id, $account_shared, $url);
         $istestingconnection = true;
         // Provided by Androgogic to override offline mode for testing connection.
         $tiiapi = $turnitincomms->initialise_api($istestingconnection);
         $class = new TiiClass();
         $class->setTitle('Test finding a class to see if connection works');
         try {
             $response = $tiiapi->findClasses($class);
             $data["connection_status"] = "success";
             $data["msg"] = get_string('connecttestsuccess', 'turnitintooltwo');
         } catch (Exception $e) {
             $turnitincomms->handle_exceptions($e, 'connecttesterror', false);
         }
     }
     echo json_encode($data);
     break;
 case "submit_nothing":
     if (!confirm_sesskey()) {
         throw new moodle_exception('invalidsesskey', 'error');
 /**
  * Edit the submission in Turnitin so a tutor can see the identity of the student
  *
  * @param string $reason
  * @return boolean
  */
 public function unanonymise_submission($reason)
 {
     // Get user and part details.
     $turnitintooltwoassignment = new turnitintooltwo_assignment($this->turnitintooltwoid);
     $partdetails = $turnitintooltwoassignment->get_part_details($this->submission_part);
     $user = new turnitintooltwo_user($this->userid);
     // Initialise Comms Object.
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     $submission = new TiiSubmission();
     $submission->setSubmissionId($this->submission_objectid);
     $submission->setAssignmentId($partdetails->tiiassignid);
     if (strlen($reason) < 5) {
         $reason = "No specified reason: " . $reason;
     }
     $submission->setAnonymousRevealReason($reason);
     $submission->setAnonymousRevealUser($user->tii_user_id);
     $submission->setAnonymousRevealDateTime(date("c"));
     try {
         $turnitincall->updateSubmission($submission);
         return true;
     } catch (Exception $e) {
         $turnitincomms->handle_exceptions($e, "unanonymiseerror", false);
         return false;
     }
 }
Exemple #7
0
/**
 * Gets the courses for this account from Turnitin.
 *
 * @param array $tiiintegrationids the integration ids we want courses from
 * @return array of data in a datatables readable format
 */
function turnitintooltwo_get_courses_from_tii($tiiintegrationids, $coursetitle, $courseintegration, $courseenddate = null, $requestsource = "mod")
{
    global $CFG, $DB, $OUTPUT, $USER;
    set_time_limit(0);
    $_SESSION["stored_tii_courses"] = array();
    $return = array();
    $return["aaData"] = array();
    $secho = optional_param('sEcho', 0, PARAM_INT);
    $ssortdir = optional_param('sSortDir_0', 'desc', PARAM_ALPHA);
    $isortcol = optional_param('iSortCol_0', '6', PARAM_INT);
    $turnitincomms = new turnitintooltwo_comms();
    $turnitincall = $turnitincomms->initialise_api();
    $class = new TiiClass();
    $class->setTitle($coursetitle);
    if ($courseenddate != null) {
        $class->setDateFrom(gmdate("Y-m-d", strtotime($courseenddate)) . 'T00:00:00Z');
    }
    if (array_key_exists($courseintegration, $tiiintegrationids)) {
        $class->setIntegrationId($courseintegration);
    }
    if (!is_siteadmin()) {
        $turnitintooltwouser = new turnitintooltwo_user($USER->id, 'Instructor');
        $tiiinstructorid = $turnitintooltwouser->tii_user_id;
        $class->setUserId($tiiinstructorid);
        $class->setUserRole('Instructor');
    }
    try {
        $response = $turnitincall->findClasses($class);
        $findclass = $response->getClass();
        $classids = $findclass->getClassIds();
    } catch (Exception $e) {
        turnitintooltwo_activitylog(get_string('migrationcoursegeterror', 'turnitintooltwo'), "REQUEST");
        $classids = array();
    }
    // Get currently linked courses.
    $currentcourses = array();
    if (!empty($classids)) {
        list($insql, $inparams) = $DB->get_in_or_equal($classids);
        $currentcourses["PP"] = $DB->get_records_sql("SELECT tc.turnitin_cid FROM {turnitintooltwo_courses} tc " . "RIGHT JOIN {course} c ON c.id = tc.courseid " . "WHERE tc.course_type = 'PP' AND tc.turnitin_cid " . $insql, $inparams);
        $currentcourses["TT"] = $DB->get_records_sql("SELECT tc.turnitin_cid FROM {turnitintooltwo_courses} tc " . "RIGHT JOIN {course} c ON c.id = tc.courseid " . "WHERE tc.course_type = 'TT' AND tc.turnitin_cid " . $insql, $inparams);
    }
    $class = new TiiClass();
    $class->setClassIds($classids);
    $tiicourses = array();
    $i = 0;
    if (!empty($classids)) {
        try {
            $response = $turnitincall->readClasses($class);
            $readclasses = $response->getClasses();
            foreach ($readclasses as $readclass) {
                if (array_key_exists($readclass->getIntegrationId(), $tiiintegrationids)) {
                    $_SESSION["stored_tii_courses"][$readclass->getClassId()] = $readclass->getTitle();
                    // If we're coming from block we don't need any information, just the number of records
                    if ($requestsource == "mod") {
                        $linkpage = is_siteadmin() ? "settings_extras.php" : "extras.php";
                        $titlecell = html_writer::link($CFG->wwwroot . '/mod/turnitintooltwo/' . $linkpage . '?cmd=class_recreation&id=' . $readclass->getClassId() . '&view_context=box&sesskey=' . sesskey(), $readclass->getTitle(), array("class" => "course_recreate", "id" => "course_" . $readclass->getClassId()));
                        $datecell = html_writer::link('.edit_course_end_date_form', html_writer::tag('span', userdate(strtotime($readclass->getEndDate()), get_string('strftimedate', 'langconfig')), array("id" => $readclass->getClassId() . "_" . gmdate("j", strtotime($readclass->getEndDate())) . "_" . gmdate("n", strtotime($readclass->getEndDate())) . "_" . gmdate("Y", strtotime($readclass->getEndDate())))) . " " . $OUTPUT->pix_icon('edit', get_string('edit'), 'mod_turnitintooltwo'), array("class" => "edit_course_end_link", "id" => "course_date_" . $readclass->getClassId()));
                        $checkbox = '';
                        $class = '';
                        if (empty($currentcourses["PP"][$readclass->getClassId()]) && empty($currentcourses["TT"][$readclass->getClassId()])) {
                            $class = 'hidden_class';
                            $checkbox = html_writer::checkbox('check_' . $readclass->getClassId(), $readclass->getClassId(), false, '', array("class" => "browser_checkbox"));
                        }
                        $moodlecell = $OUTPUT->pix_icon('tick', get_string('moodlelinked', 'turnitintooltwo'), 'mod_turnitintooltwo', array('class' => $class, 'id' => 'tick_' . $readclass->getClassId()));
                        $tiicourses[$i] = array($checkbox, $titlecell, $tiiintegrationids[$readclass->getIntegrationId()], $datecell, $readclass->getClassId(), $moodlecell, $readclass->getTitle(), userdate(strtotime($readclass->getEndDate()), get_string('strftimedate', 'langconfig')));
                    }
                    $i++;
                    // Keep course names in case of course recreation.
                    $_SESSION['tii_classes'][$readclass->getClassId()] = $readclass->getTitle();
                }
            }
            if (count($tiicourses) > 0 && $requestsource == "mod") {
                turnitintooltwo_sort_array($tiicourses, $isortcol, $ssortdir);
                $j = 0;
                foreach ($tiicourses as $class) {
                    $return["aaData"][$j] = $class;
                    $j++;
                }
            }
        } catch (Exception $e) {
            $turnitincomms->handle_exceptions($e, 'coursegettiierror');
        }
    }
    $return["iTotalRecords"] = $i;
    $return["iTotalDisplayRecords"] = $i;
    $return["sEcho"] = $secho;
    $return["blockHTML"] = $i == 0 ? '' : get_string('coursestomigrate', 'mod_turnitintooltwo', $i);
    return $return;
}
Exemple #8
0
 /**
  * Delete a submission from Turnitin
  */
 private function delete_tii_submission($submissionid)
 {
     // Initialise Comms Object.
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     $submission = new TiiSubmission();
     $submission->setSubmissionId($submissionid);
     try {
         $response = $turnitincall->deleteSubmission($submission);
     } catch (Exception $e) {
         $turnitincomms->handle_exceptions($e, 'turnitindeletionerror');
     }
 }