/**
  * Update class from Turnitin, mainly to get shared rubrics
  *
  * @return
  */
 public function read_class_from_tii()
 {
     // Initialise Comms Object.
     $turnitincomms = new turnitin_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', 'plagiarism_turnitin') . "]";
         }
         $this->sharedrubrics = $rubricarray;
     } catch (Exception $e) {
         $turnitincomms->handle_exceptions($e, 'coursegeterror', false);
     }
 }
 /**
  * Edit the course end date in Turnitin
  *
  * @global type $DB
  * @param int $tiicourseid The course id on Turnitin
  * @param int $tiicoursetitle The course title on Turnitin
  * @param date $courseenddate The new course end date to be set on Turnitin
  */
 public static function edit_tii_course_end_date($tiicourseid, $tiicoursetitle, $courseenddate)
 {
     global $DB;
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     $class = new TiiClass();
     $class->setTitle($tiicoursetitle);
     $class->setClassId($tiicourseid);
     $class->setEndDate(gmdate("Y-m-d\\TH:i:s\\Z", $courseenddate));
     try {
         $turnitincall->updateClass($class);
         return true;
     } catch (Exception $e) {
         $turnitincomms->handle_exceptions($e, 'classupdateerror');
     }
 }
 public function readClasses($class)
 {
     try {
         $soap = $this->readCourseSections(array('sourcedIdSet' => array('sourcedId' => $class->getClassIds())));
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription(), parent::getLogPath());
         } else {
             $classes = array();
             if (isset($soap->courseSectionRecordSet->courseSectionRecord)) {
                 if (!is_array($soap->courseSectionRecordSet->courseSectionRecord)) {
                     $soap->courseSectionRecordSet->courseSectionRecord = array($soap->courseSectionRecordSet->courseSectionRecord);
                 }
                 foreach ($soap->courseSectionRecordSet->courseSectionRecord as $record) {
                     $tiiClass = new TiiClass();
                     $tiiClass->setClassId($record->sourcedGUID->sourcedId);
                     $tiiClass->setTitle($record->courseSection->title->textString);
                     $tiiClass->setEndDate($record->courseSection->timeFrame->end);
                     foreach ($record->courseSection->extension->extensionField as $field) {
                         $name = $field->fieldName;
                         $method = 'set' . $name;
                         if (is_callable(array($tiiClass, $method))) {
                             $tiiClass->{$method}($field->fieldValue);
                         }
                     }
                     $classes[] = $tiiClass;
                 }
             }
             $response->setClasses($classes);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }