Actualización

This commit is contained in:
Xes
2025-04-10 12:36:07 +02:00
parent 1da7c3f3b9
commit 4aff98e77b
3147 changed files with 320647 additions and 0 deletions

View 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}';
}

View 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]]);

View 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);

View 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;

View 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&lti_launch_id='.$launch->getLaunchId();
} else {
$launchUrl = api_get_path(WEB_CODE_PATH).'exercise/overview.php?'.$cidReq.'&origin=embeddable&exerciseId='.$toolVars['toolId'].'&lti_launch_id='.$launch->getLaunchId();
}
$ltiSession['launch_url'] = $launchUrl;
Session::write('_ltiProvider', $ltiSession);
header('Location: '.$launchUrl);
exit;