/**
  * Get ids of submissions from Turnitin
  *
  * @param object $part the part to get submissions for
  */
 public function get_submission_ids_from_tii($part)
 {
     // Initialise Comms Object.
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     try {
         $submission = new TiiSubmission();
         $submission->setAssignmentId($part->tiiassignid);
         // Only update submissions that have been modified since last update.
         if (!empty($_SESSION["TiiSubmissionsRefreshed"][$part->id])) {
             $submission->setDateFrom(gmdate("Y-m-d\\TH:i:s\\Z", $_SESSION["TiiSubmissionsRefreshed"][$part->id]));
         }
         $response = $turnitincall->findSubmissions($submission);
         $findsubmission = $response->getSubmission();
         $_SESSION["TiiSubmissions"][$part->id] = $findsubmission->getSubmissionIds();
     } catch (Exception $e) {
         $turnitincomms->handle_exceptions($e, 'tiisubmissionsgeterror', false);
     }
 }
Ejemplo n.º 2
0
 public function update_grades_from_tii($cm)
 {
     global $DB;
     $plagiarismvalues = $this->get_settings($cm->id);
     $submissionids = array();
     $return = true;
     // Initialise Comms Object.
     $turnitincomms = new turnitin_comms();
     $turnitincall = $turnitincomms->initialise_api();
     // Get the submission ids from Turnitin that have been updated.
     try {
         $submission = new TiiSubmission();
         $submission->setAssignmentId($plagiarismvalues["turnitin_assignid"]);
         // Only update submissions that have been modified since last update.
         if (!empty($plagiarismvalues["grades_last_synced"])) {
             $submission->setDateFrom(gmdate("Y-m-d\\TH:i:s\\Z", $plagiarismvalues["grades_last_synced"]));
         }
         $response = $turnitincall->findSubmissions($submission);
         $findsubmission = $response->getSubmission();
         $submissionids = $findsubmission->getSubmissionIds();
     } catch (Exception $e) {
         $turnitincomms->handle_exceptions($e, 'tiisubmissionsgeterror', false);
         $return = false;
     }
     // Refresh updated submissions.
     if (count($submissionids) > 0) {
         // Process submissions in batches, depending on the max. number of submissions the Turnitin API returns.
         $submissionbatches = array_chunk($submissionids, PLAGIARISM_TURNITIN_NUM_RECORDS_RETURN);
         foreach ($submissionbatches as $submissionsbatch) {
             try {
                 $submission = new TiiSubmission();
                 $submission->setSubmissionIds($submissionsbatch);
                 $response = $turnitincall->readSubmissions($submission);
                 $readsubmissions = $response->getSubmissions();
                 foreach ($readsubmissions as $readsubmission) {
                     $submissiondata = $DB->get_record('plagiarism_turnitin_files', array('externalid' => $readsubmission->getSubmissionId()), 'id');
                     $return = $this->update_submission($cm, $submissiondata->id, $readsubmission);
                 }
             } catch (Exception $e) {
                 $turnitincomms->handle_exceptions($e, 'tiisubmissiongeterror', false);
                 $return = false;
             }
         }
     }
     return $return;
 }