コード例 #1
0
 /**
  * Get common user uri associated to Lti user id
  *
  * @param $id string Identifier of LTI user
  * @param $key string Oauth LTI consumer key
  * @return array|null
  * @throws \common_Exception
  * @throws \tao_models_classes_oauth_Exception
  */
 public function getUserId($id, $key)
 {
     $class = new \core_kernel_classes_Class(CLASS_LTI_USER);
     $dataStore = new \tao_models_classes_oauth_DataStore();
     try {
         /** @var \core_kernel_classes_Resource $consumerResource */
         $consumerResource = $dataStore->findOauthConsumerResource($key);
     } catch (\tao_models_classes_oauth_Exception $e) {
         throw new \common_exception_NotFound($e->getMessage());
     }
     $instances = $class->searchInstances(array(PROPERTY_USER_LTIKEY => $id, PROPERTY_USER_LTICONSUMER => $consumerResource), array('like' => false));
     if (count($instances) > 1) {
         throw new \common_Exception('Multiple user accounts found for user key: ' . $id);
     }
     /** @var \core_kernel_classes_Resource $ltiUser */
     $ltiUser = count($instances) == 1 ? current($instances) : null;
     if (!$ltiUser) {
         return null;
     }
     return array('id' => $ltiUser->getUri());
 }
コード例 #2
0
 /**
  * Returns the LTI Consumer resource associated to this lti session
  *
  * @access public
  * @author Joel Bout, <*****@*****.**>
  * @return core_kernel_classes_Resource resource of LtiConsumer
  * @throws tao_models_classes_oauth_Exception thrown if no Consumer found for key
  */
 public function getLtiConsumerResource($launchData)
 {
     $dataStore = new tao_models_classes_oauth_DataStore();
     return $dataStore->findOauthConsumerResource($launchData->getOauthKey());
 }