PageRenderTime 38ms CodeModel.GetById 9ms RepoModel.GetById 1ms app.codeStats 0ms

/sdk/submissionsoap.class.php

https://github.com/danmarsden/moodle-plagiarism_turnitin
PHP | 236 lines | 211 code | 17 blank | 8 comment | 35 complexity | 3d0fcec6b5fffcb3e0bc32e12179c6b4 MD5 | raw file
  1. <?php
  2. /* @ignore
  3. * To change this template, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. require_once( 'soap.class.php' );
  7. require_once( 'tiisubmission.class.php' );
  8. require_once( 'response.class.php' );
  9. require_once( 'sdkexception.class.php' );
  10. /**
  11. * @ignore
  12. */
  13. class SubmissionSoap extends Soap {
  14. public static $extensionname_vocab = 'http://www.turnitin.com/static/source/media/turnitinvocabularyv1p0.xml';
  15. public static $extensionvalue_vocab = 'http://www.imsglobal.org/vdex/lis/omsv1p0/extensionvocabularyv1p0.xml';
  16. public $ns;
  17. public function __construct( $wsdl, $options ) {
  18. $this->ns = 'http://www.imsglobal.org/services/lis/oms1p0/wsdl11/sync/imsoms_v1p0';
  19. parent::__construct( $wsdl, $options );
  20. }
  21. public function readSubmission( $submission ) {
  22. try {
  23. $soap = $this->readResult( array( 'sourcedId' => $submission->getSubmissionId() ) );
  24. $response = new Response( $this );
  25. if ( $response->getStatus() == 'error' ) {
  26. throw new TurnitinSDKException( $response->getStatusCode(), $response->getDescription() );
  27. } else {
  28. $tiiSubmission = new TiiSubmission();
  29. $tiiSubmission->setSubmissionId( $soap->resultRecord->sourcedGUID->sourcedId );
  30. $tiiSubmission->setTitle( $soap->resultRecord->result->resultValue->label );
  31. $tiiSubmission->setAssignmentId( $soap->resultRecord->result->lineItemSourcedId );
  32. $tiiSubmission->setAuthorUserId( $soap->resultRecord->result->personSourcedId );
  33. $tiiSubmission->setDate( $soap->resultRecord->result->date );
  34. $tiiSubmission->setOverallSimilarity( $soap->resultRecord->result->resultScore->textString );
  35. $soap->resultRecord->result->extension->extensionField = is_array( $soap->resultRecord->result->extension->extensionField )
  36. ? $soap->resultRecord->result->extension->extensionField
  37. : array( $soap->resultRecord->result->extension->extensionField );
  38. foreach ( $soap->resultRecord->result->extension->extensionField as $field ) {
  39. $name = $field->fieldName;
  40. $method = 'set'.$name;
  41. if ( is_callable( array( $tiiSubmission, $method ) ) ) $tiiSubmission->$method($field->fieldValue);
  42. }
  43. $response->setSubmission( $tiiSubmission );
  44. }
  45. return $response;
  46. } catch ( SoapFault $e ) {
  47. throw new TurnitinSDKException( $e->faultcode, $e->faultstring, parent::getLogPath() );
  48. }
  49. }
  50. public function readSubmissions( $submission ) {
  51. try {
  52. $soap = $this->readResults( array( 'sourcedIdSet' => array( 'sourcedId' => $submission->getSubmissionIds() ) ) );
  53. $response = new Response( $this );
  54. if ( $response->getStatus() == 'error' ) {
  55. throw new TurnitinSDKException( $response->getStatusCode(), $response->getDescription() );
  56. } else {
  57. $submissions = array();
  58. if ( isset( $soap->resultRecordSet->resultRecord ) ) {
  59. if ( !is_array( $soap->resultRecordSet->resultRecord ) ) $soap->resultRecordSet->resultRecord = array( $soap->resultRecordSet->resultRecord );
  60. foreach ( $soap->resultRecordSet->resultRecord as $submission ) {
  61. $tiiSubmission = new TiiSubmission();
  62. $tiiSubmission->setSubmissionId( $submission->sourcedGUID->sourcedId );
  63. $tiiSubmission->setTitle( $submission->result->resultValue->label );
  64. $tiiSubmission->setAssignmentId( $submission->result->lineItemSourcedId );
  65. $tiiSubmission->setAuthorUserId( $submission->result->personSourcedId );
  66. $tiiSubmission->setDate( $submission->result->date );
  67. $tiiSubmission->setOverallSimilarity( $submission->result->resultScore->textString );
  68. $submission->result->extension->extensionField = is_array( $submission->result->extension->extensionField )
  69. ? $submission->result->extension->extensionField
  70. : array( $submission->result->extension->extensionField );
  71. foreach ( $submission->result->extension->extensionField as $field ) {
  72. $name = $field->fieldName;
  73. $method = 'set'.$name;
  74. if ( is_callable( array( $tiiSubmission, $method ) ) ) $tiiSubmission->$method($field->fieldValue);
  75. }
  76. $submissions[] = $tiiSubmission;
  77. }
  78. }
  79. $response->setSubmissions( $submissions );
  80. }
  81. return $response;
  82. } catch ( SoapFault $e ) {
  83. throw new TurnitinSDKException( $e->faultcode, $e->faultstring, parent::getLogPath() );
  84. }
  85. }
  86. public function deleteSubmission( $submission ) {
  87. try {
  88. $this->deleteResult( array( 'sourcedId' => $submission->getSubmissionId() ) );
  89. $response = new Response( $this );
  90. if ( $response->getStatus() == 'error' ) {
  91. throw new TurnitinSDKException( $response->getStatusCode(), $response->getDescription() );
  92. } else {
  93. $tiiSubmission = new TiiSubmission();
  94. $response->setSubmission( $tiiSubmission );
  95. }
  96. return $response;
  97. } catch ( SoapFault $e ) {
  98. throw new TurnitinSDKException( $e->faultcode, $e->faultstring, parent::getLogPath() );
  99. }
  100. }
  101. public function findSubmissions( $submission ) {
  102. try {
  103. $soap = $this->readResultIdsForLineItem( array( 'lineItemSourcedid' => $submission->getAssignmentId() ) );
  104. $response = new Response( $this );
  105. if ( $response->getStatus() == 'error' ) {
  106. throw new TurnitinSDKException( $response->getStatusCode(), $response->getDescription() );
  107. } else {
  108. $tiiSubmission = new TiiSubmission();
  109. $submissionids = array();
  110. if ( isset( $soap->sourcedIdSet->sourcedId ) ) {
  111. if ( !is_array( $soap->sourcedIdSet->sourcedId ) ) $soap->sourcedIdSet->sourcedId = array( $soap->sourcedIdSet->sourcedId );
  112. foreach ( $soap->sourcedIdSet->sourcedId as $id ) {
  113. $submissionids[] = $id;
  114. }
  115. }
  116. $tiiSubmission->setSubmissionIds( $submissionids );
  117. $response->setSubmission( $tiiSubmission );
  118. }
  119. return $response;
  120. } catch ( SoapFault $e ) {
  121. throw new TurnitinSDKException( $e->faultcode, $e->faultstring, parent::getLogPath() );
  122. }
  123. }
  124. public function findRecentSubmissions( $submission ) {
  125. try {
  126. $query = json_encode( array( 'lineitem_sourcedid' => $submission->getAssignmentId(), 'date_from' => $submission->getDateFrom() ) );
  127. $soap = $this->discoverResultIds( array( 'queryObject' => $query ) );
  128. $response = new Response( $this );
  129. if ( $response->getStatus() == 'error' ) {
  130. throw new TurnitinSDKException( $response->getStatusCode(), $response->getDescription() );
  131. } else {
  132. $tiiSubmission = new TiiSubmission();
  133. $submissionids = array();
  134. if ( isset( $soap->sourcedIdSet->sourcedId ) ) {
  135. if ( !is_array( $soap->sourcedIdSet->sourcedId ) ) $soap->sourcedIdSet->sourcedId = array( $soap->sourcedIdSet->sourcedId );
  136. foreach ( $soap->sourcedIdSet->sourcedId as $id ) {
  137. $submissionids[] = $id;
  138. }
  139. }
  140. $tiiSubmission->setSubmissionIds( $submissionids );
  141. $response->setSubmission( $tiiSubmission );
  142. }
  143. return $response;
  144. } catch ( SoapFault $e ) {
  145. throw new TurnitinSDKException( $e->faultcode, $e->faultstring, parent::getLogPath() );
  146. }
  147. }
  148. public function updateSubmission( $submission ) {
  149. try {
  150. $request = $this->buildSubmissionRequest( $submission, true );
  151. $this->updateResult( $request );
  152. $response = new Response( $this );
  153. if ( $response->getStatus() == 'error' ) {
  154. throw new TurnitinSDKException( $response->getStatusCode(), $response->getDescription() );
  155. } else {
  156. $tiiSubmission = new TiiSubmission();
  157. $response->setSubmission( $tiiSubmission );
  158. }
  159. return $response;
  160. } catch ( SoapFault $e ) {
  161. throw new TurnitinSDKException( $e->faultcode, $e->faultstring, parent::getLogPath() );
  162. }
  163. }
  164. public function createSubmission( $submission ) {
  165. try {
  166. $request = array();
  167. $request['resultRecord']['sourcedGUID']['sourcedId'] = '';
  168. $request['resultRecord']['result']['personSourcedId'] = $submission->getAuthorUserId();
  169. $request['resultRecord']['result']['lineItemSourcedId'] = $submission->getAssignmentId();
  170. $request['resultRecord']['result']['extension']['extensionNameVocabulary'] = self::$extensionname_vocab;
  171. $request['resultRecord']['result']['extension']['extensionValueVocabulary'] = self::$extensionvalue_vocab;
  172. $request['resultRecord']['result']['extension']['extensionField'][0]['fieldName'] = 'Submitter';
  173. $request['resultRecord']['result']['extension']['extensionField'][0]['fieldType'] = 'Integer';
  174. $request['resultRecord']['result']['extension']['extensionField'][0]['fieldValue'] = $submission->getSubmitterUserId();
  175. $soap = $this->createByProxyResult( $request );
  176. $response = new Response( $this );
  177. if ( $response->getStatus() == 'error' ) {
  178. throw new TurnitinSDKException( $response->getStatusCode(), $response->getDescription() );
  179. } else {
  180. $tiiSubmission = new TiiSubmission();
  181. $tiiSubmission->setSubmissionId( $soap->sourcedId );
  182. $response->setSubmission( $tiiSubmission );
  183. }
  184. return $response;
  185. } catch ( SoapFault $e ) {
  186. throw new TurnitinSDKException( $e->faultcode, $e->faultstring, parent::getLogPath() );
  187. }
  188. }
  189. private function buildSubmissionRequest( $submission, $update = false ) {
  190. $request = array();
  191. if ( $update ) {
  192. $request['sourcedId'] = $submission->getSubmissionId();
  193. } else {
  194. $request['sourcedId'] = null;
  195. }
  196. $request['resultRecord']['sourcedGUID']['sourcedId'] = $submission->getSubmissionId();
  197. $request['resultRecord']['result']['resultValue']['label'] = $submission->getTitle();
  198. $request['resultRecord']['result']['lineItemSourcedId'] = $submission->getAssignmentId();
  199. $i = 0;
  200. foreach ($this->extensions as $name => $type) {
  201. $method = 'get'.$name;
  202. $value = null;
  203. if ( is_callable( array( $submission, $method ) ) ) $value = $submission->$method();
  204. $value = ( gettype( $value ) == 'boolean' ) ? (integer)$value : $value;
  205. if (!is_null($value)) {
  206. $request['resultRecord']['result']['extension']['extensionField'][$i]['fieldName'] = $name;
  207. $request['resultRecord']['result']['extension']['extensionField'][$i]['fieldType'] = $type;
  208. $request['resultRecord']['result']['extension']['extensionField'][$i]['fieldValue'] = $value;
  209. $i++;
  210. }
  211. }
  212. if ( $i > 0 ) {
  213. $request['resultRecord']['result']['extension']['extensionNameVocabulary'] = self::$extensionname_vocab;
  214. $request['resultRecord']['result']['extension']['extensionValueVocabulary'] = self::$extensionvalue_vocab;
  215. }
  216. return $request;
  217. }
  218. }
  219. //?>