コード例 #1
0
 /**
  * Create the user on Turnitin
  *
  * @param object $user_details A data object for the user
  * @param var $role user role to create
  * @return var Turnitin user id
  */
 private function create_tii_user()
 {
     $config = turnitintooltwo_admin_config();
     $tiiuserid = null;
     $turnitincomms = new turnitintooltwo_comms();
     $turnitincall = $turnitincomms->initialise_api();
     // Convert the email, firstname and lastname to psuedos for students if the option is set in config
     // Unless the user is already logged as a tutor then use real details.
     if (!empty($config->enablepseudo) && $this->role == "Learner") {
         $user = new TiiPseudoUser($this->get_pseudo_domain());
         $user->setPseudoSalt($config->pseudosalt);
         $user->setFirstName($this->get_pseudo_firstname());
         $user->setLastName($this->get_pseudo_lastname());
     } else {
         $user = new TiiUser();
         $user->setFirstName($this->firstname);
         $user->setLastName($this->lastname);
     }
     $user->setEmail($this->email);
     $user->setDefaultRole($this->role);
     try {
         $response = $turnitincall->createUser($user);
         $newuser = $response->getUser();
         $tiiuserid = $newuser->getUserId();
         turnitintooltwo_activitylog("Turnitin User created: " . $this->id . " (" . $tiiuserid . ")", "REQUEST");
         return $tiiuserid;
     } catch (Exception $e) {
         $toscreen = $this->workflowcontext == "cron" ? false : true;
         $turnitincomms->handle_exceptions($e, 'usercreationerror', $toscreen);
     }
 }
コード例 #2
0
 public function readUser($user)
 {
     try {
         $soap = $this->readPerson(array('sourcedId' => $user->getUserId()));
         $response = new Response($this);
         if ($response->getStatus() == 'error') {
             throw new TurnitinSDKException($response->getStatusCode(), $response->getDescription());
         } else {
             $tiiUser = new TiiUser();
             $tiiUser->setUserId($soap->personRecord->sourcedGUID->sourcedId);
             $tiiUser->setDefaultRole($soap->personRecord->person->roles->institutionRole->institutionroletype->instanceValue->textString);
             $tiiUser->setEmail($soap->personRecord->person->contactinfo->contactinfoValue->textString);
             foreach ($soap->personRecord->person->name->partName as $partname) {
                 if ($partname->instanceName->textString == 'First') {
                     $tiiUser->setFirstname($partname->instanceValue->textString);
                 } else {
                     if ($partname->instanceName->textString == 'Last') {
                         $tiiUser->setLastname($partname->instanceValue->textString);
                     }
                 }
             }
             $soap->personRecord->person->extension->extensionField = is_array($soap->personRecord->person->extension->extensionField) ? $soap->personRecord->person->extension->extensionField : array($soap->personRecord->person->extension->extensionField);
             foreach ($soap->personRecord->person->extension->extensionField as $field) {
                 $name = $field->fieldName;
                 $method = 'set' . $name;
                 if (is_callable(array($tiiUser, $method))) {
                     $tiiUser->{$method}($field->fieldValue);
                 }
             }
             $response->setUser($tiiUser);
         }
         return $response;
     } catch (SoapFault $e) {
         throw new TurnitinSDKException($e->faultcode, $e->faultstring, parent::getLogPath());
     }
 }