Example #1
0
 public static function createMessage($code, $description = null)
 {
     if (is_null($description)) {
         $description = Response::getDescription($code);
     }
     return array("code" => $code, "description" => $description);
 }
 public function findClasses($class)
 {
     try {
         $queryObject = array('queryObject' => json_encode(array('coursesection_title' => $class->getTitle(), 'date_from' => $class->getDateFrom(), 'integration_id' => $class->getIntegrationId(), 'user_id' => $class->getUserId(), 'user_role' => $class->getUserRole())));
         $soap = $this->discoverCourseSectionIds($queryObject);
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription(), parent::getLogPath());
         } else {
             $tiiClass = new TiiClass();
             $classids = array();
             if (isset($soap->sourcedIdSet->sourcedId)) {
                 if (!is_array($soap->sourcedIdSet->sourcedId)) {
                     $soap->sourcedIdSet->sourcedId = array($soap->sourcedIdSet->sourcedId);
                 }
                 foreach ($soap->sourcedIdSet->sourcedId as $id) {
                     $classids[] = $id;
                 }
             }
             $tiiClass->setClassIds($classids);
             $response->setClass($tiiClass);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }
 /**
  *
  * @param TiiSubmission $submission
  */
 public function replaceSubmission($submission)
 {
     $params_merge = $this->getResubmissionFormHash($submission);
     if (is_null($submission->getSubmissionDataPath()) && is_null($submission->getSubmissionDataUrl())) {
         $params_merge['custom_submission_data'] = $submission->getSubmissionDataText();
     } else {
         if (is_null($submission->getSubmissionDataUrl())) {
             // CURL uploading with @ has been deprecated in PHP 5.5
             if (class_exists('CURLFile')) {
                 $finfo = new finfo(FILEINFO_MIME);
                 $mimetype = $finfo->file($submission->getSubmissionDataPath());
                 $params_merge['custom_submission_data'] = new CurlFile($submission->getSubmissionDataPath(), $mimetype);
             } else {
                 $params_merge['custom_submission_data'] = '@' . $submission->getSubmissionDataPath();
             }
         }
     }
     $transport = $this->transportData($params_merge);
     $response = new Response($this);
     if ($response->getStatusCode() == 'failure') {
         throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
     } else {
         $dom = $response->getDomObject();
         $tiiSubmission = new TiiSubmission();
         $tiiSubmission->setSubmissionId($dom->getElementsByTagName('lis_result_sourcedid')->item(0)->nodeValue);
         $tiiSubmission->setTextExtract(@$dom->getElementsByTagName('submission_data_extract')->item(0)->nodeValue);
         $response->setSubmission($tiiSubmission);
     }
     return $response;
 }
 public function findAssignments($assignment)
 {
     try {
         $soap = $this->readLineItemIdsForCourseSection(array('sectionSourcedId' => $assignment->getClassId()));
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
         } else {
             $tiiAssignment = new TiiAssignment();
             $assignmentids = array();
             if (isset($soap->sourcedIdSet->sourcedId)) {
                 if (!is_array($soap->sourcedIdSet->sourcedId)) {
                     $soap->sourcedIdSet->sourcedId = array($soap->sourcedIdSet->sourcedId);
                 }
                 foreach ($soap->sourcedIdSet->sourcedId as $id) {
                     $assignmentids[] = $id;
                 }
             }
             $tiiAssignment->setAssignmentIds($assignmentids);
             $response->setAssignment($tiiAssignment);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }
 public function findUser($user)
 {
     try {
         $request = array('queryObject' => $user->getEmail());
         $soap = $this->discoverPersonIds($request);
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
         } else {
             $tiiUser = new TiiUser();
             if (isset($soap->sourcedIdSet->sourcedId)) {
                 $tiiUser->setUserId($soap->sourcedIdSet->sourcedId);
             }
             $response->setUser($tiiUser);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }
 public function findMemberships($membership)
 {
     try {
         $soap = $this->readMembershipIdsForCollection(array('groupSourcedId' => $membership->getClassId(), 'collection' => 'courseSection'));
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
         } else {
             $tiiMembership = new TiiMembership();
             $membershipids = array();
             if (isset($soap->sourcedIdSet->sourcedId)) {
                 if (!is_array($soap->sourcedIdSet->sourcedId)) {
                     $soap->sourcedIdSet->sourcedId = array($soap->sourcedIdSet->sourcedId);
                 }
                 foreach ($soap->sourcedIdSet->sourcedId as $id) {
                     $membershipids[] = $id;
                 }
             }
             $tiiMembership->setMembershipIds($membershipids);
             $response->setMembership($tiiMembership);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }
 public function createSubmission($submission)
 {
     try {
         $request = array();
         $request['resultRecord']['sourcedGUID']['sourcedId'] = '';
         $request['resultRecord']['result']['personSourcedId'] = $submission->getAuthorUserId();
         $request['resultRecord']['result']['lineItemSourcedId'] = $submission->getAssignmentId();
         $request['resultRecord']['result']['extension']['extensionNameVocabulary'] = self::$extensionname_vocab;
         $request['resultRecord']['result']['extension']['extensionValueVocabulary'] = self::$extensionvalue_vocab;
         $request['resultRecord']['result']['extension']['extensionField'][0]['fieldName'] = 'Submitter';
         $request['resultRecord']['result']['extension']['extensionField'][0]['fieldType'] = 'Integer';
         $request['resultRecord']['result']['extension']['extensionField'][0]['fieldValue'] = $submission->getSubmitterUserId();
         $soap = $this->createByProxyResult($request);
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
         } else {
             $tiiSubmission = new TiiSubmission();
             $tiiSubmission->setSubmissionId($soap->sourcedId);
             $response->setSubmission($tiiSubmission);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }