Actualización
This commit is contained in:
61
plugin/lti_provider/tool/api/score.php
Normal file
61
plugin/lti_provider/tool/api/score.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../../../../main/inc/global.inc.php';
|
||||
require_once __DIR__.'/../../src/LtiProvider.php';
|
||||
|
||||
$launch = LtiProvider::create()->launch(true, $_REQUEST['launch_id']);
|
||||
|
||||
if (!$launch->hasAgs()) {
|
||||
throw new Exception("Don't have grades!");
|
||||
}
|
||||
|
||||
if (!isset($_REQUEST['lti_result_id'])) {
|
||||
throw new Exception("Any tool result");
|
||||
}
|
||||
|
||||
$launchData = $launch->getLaunchData();
|
||||
|
||||
$courseCode = $_REQUEST['cidReq'];
|
||||
$courseId = api_get_course_int_id($courseCode);
|
||||
$toolName = $_REQUEST['lti_tool'];
|
||||
|
||||
if (in_array($toolName, ['quiz', 'lp'])) {
|
||||
if ('quiz' == $toolName) {
|
||||
$objExercise = new Exercise($courseId);
|
||||
$trackInfo = $objExercise->get_stat_track_exercise_info_by_exe_id($_REQUEST['lti_result_id']);
|
||||
$score = $trackInfo['exe_result'];
|
||||
$weight = $trackInfo['exe_weighting'];
|
||||
$timestamp = date(DATE_ISO8601);
|
||||
} else {
|
||||
$lpId = (int) $_REQUEST['lti_result_id'];
|
||||
$lpProgress = learnpath::getProgress(
|
||||
$lpId,
|
||||
api_get_user_id(),
|
||||
api_get_course_int_id(),
|
||||
api_get_session_id()
|
||||
);
|
||||
$score = $lpProgress;
|
||||
$weight = 100;
|
||||
$timestamp = date(DATE_ISO8601);
|
||||
}
|
||||
|
||||
$grades = $launch->getAgs();
|
||||
$scoreGrade = Packback\Lti1p3\LtiGrade::new()
|
||||
->setScoreGiven($score)
|
||||
->setScoreMaximum($weight)
|
||||
->setTimestamp($timestamp)
|
||||
->setActivityProgress('Completed')
|
||||
->setGradingProgress('FullyGraded')
|
||||
->setUserId($launchData['sub']);
|
||||
$grades->putGrade($scoreGrade);
|
||||
|
||||
$plugin = LtiProviderPlugin::create();
|
||||
$values = [];
|
||||
$values['score'] = $score;
|
||||
$values['progress'] = 0;
|
||||
$values['duration'] = 0;
|
||||
$plugin->saveResult($values, $_REQUEST['launch_id']);
|
||||
|
||||
echo '{"success" : true}';
|
||||
}
|
||||
49
plugin/lti_provider/tool/jwks.php
Normal file
49
plugin/lti_provider/tool/jwks.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
/* For licensing terms, see /license.txt */
|
||||
|
||||
use Chamilo\PluginBundle\Entity\LtiProvider\PlatformKey;
|
||||
use Firebase\JWT\JWT;
|
||||
use phpseclib\Crypt\RSA;
|
||||
|
||||
$cidReset = true;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
|
||||
$plugin = LtiProviderPlugin::create();
|
||||
|
||||
if ('true' !== $plugin->get('enabled')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/** @var PlatformKey $platformKey */
|
||||
$platformKey = Database::getManager()
|
||||
->getRepository('ChamiloPluginBundle:LtiProvider\PlatformKey')
|
||||
->findOneBy([]);
|
||||
|
||||
if (!$platformKey) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$privateKey = $platformKey->getPrivateKey();
|
||||
|
||||
$jwks = [];
|
||||
|
||||
$key = new RSA();
|
||||
$key->setHash('sha256');
|
||||
$key->loadKey($platformKey->getPrivateKey());
|
||||
$key->setPublicKey(false, RSA::PUBLIC_FORMAT_PKCS8);
|
||||
|
||||
if ($key->publicExponent) {
|
||||
$jwks = [
|
||||
'kty' => 'RSA',
|
||||
'alg' => 'RS256',
|
||||
'use' => 'sig',
|
||||
'e' => JWT::urlsafeB64Encode($key->publicExponent->toBytes()),
|
||||
'n' => JWT::urlsafeB64Encode($key->modulus->toBytes()),
|
||||
'kid' => $platformKey->getKid(),
|
||||
];
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
echo json_encode(['keys' => [$jwks]]);
|
||||
7
plugin/lti_provider/tool/login.php
Normal file
7
plugin/lti_provider/tool/login.php
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
require_once __DIR__.'/../src/LtiProvider.php';
|
||||
|
||||
LtiProvider::create()->login($_REQUEST);
|
||||
10
plugin/lti_provider/tool/logout.php
Normal file
10
plugin/lti_provider/tool/logout.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
require_once __DIR__.'/../src/LtiProvider.php';
|
||||
require_once __DIR__.'/../LtiProviderPlugin.php';
|
||||
|
||||
LtiProvider::create()->logout();
|
||||
header('Location: '.api_get_path(WEB_PATH));
|
||||
exit;
|
||||
44
plugin/lti_provider/tool/start.php
Normal file
44
plugin/lti_provider/tool/start.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/* For license terms, see /license.txt */
|
||||
use ChamiloSession as Session;
|
||||
|
||||
require_once __DIR__.'/../../../main/inc/global.inc.php';
|
||||
require_once __DIR__.'/../src/LtiProvider.php';
|
||||
require_once __DIR__.'/../LtiProviderPlugin.php';
|
||||
|
||||
$launch = LtiProvider::create()->launch();
|
||||
if (!$launch->hasNrps()) {
|
||||
// throw new Exception("Don't have names and roles!");
|
||||
}
|
||||
|
||||
$launchData = $launch->getLaunchData();
|
||||
|
||||
$plugin = LtiProviderPlugin::create();
|
||||
$toolVars = $plugin->getToolProviderVars($launchData['aud']);
|
||||
|
||||
$login = LtiProvider::create()->validateUser($launchData, $toolVars['courseCode'], $toolVars['toolName']);
|
||||
$ltiSession = [];
|
||||
if ($login) {
|
||||
$values = [];
|
||||
$values['issuer'] = $launchData['iss'];
|
||||
$values['user_id'] = api_get_user_id();
|
||||
$values['client_uid'] = $launchData['sub'];
|
||||
$values['course_code'] = $toolVars['courseCode'];
|
||||
$values['tool_id'] = $toolVars['toolId'];
|
||||
$values['tool_name'] = $toolVars['toolName'];
|
||||
$values['lti_launch_id'] = $launch->getLaunchId();
|
||||
$plugin->saveResult($values);
|
||||
$ltiSession = $values;
|
||||
}
|
||||
|
||||
$cidReq = 'cidReq='.$toolVars['courseCode'].'&id_session=0&gidReq=0&gradebook=0';
|
||||
|
||||
if ('lp' == $toolVars['toolName']) {
|
||||
$launchUrl = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.$cidReq.'&action=view&lp_id='.$toolVars['toolId'].'&isStudentView=true<i_launch_id='.$launch->getLaunchId();
|
||||
} else {
|
||||
$launchUrl = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.$cidReq.'&origin=embeddable&exerciseId='.$toolVars['toolId'].'<i_launch_id='.$launch->getLaunchId();
|
||||
}
|
||||
$ltiSession['launch_url'] = $launchUrl;
|
||||
Session::write('_ltiProvider', $ltiSession);
|
||||
header('Location: '.$launchUrl);
|
||||
exit;
|
||||
Reference in New Issue
Block a user