19declare(strict_types=1);
24use Psr\Http\Message\ServerRequestInterface;
25use Random\RandomException;
40 "platform_id" =>
"lti_13_platform_id",
41 "client_id" =>
"lti_13_client_id",
42 "deployment_id" =>
"lti_13_deployment_id",
43 "keyset_url" =>
"lti_13_keyset_url",
44 "token_url" =>
"lti_13_token_url",
45 "authentication_url" =>
"lti_13_authentication_url",
51 private readonly
Factory $ui_factory,
54 private readonly
int $platform_id,
65 public function getForm(
string $action): Form
67 $field = $this->ui_factory->input()->field();
68 $values = $this->platform_id > 0 ? $this->
read() : [
"active" =>
false,
"types" => []];
73 "title" => $field->text($this->
lng->txt(
"title"))->withRequired(
true)->withValue($values[
"title"] ??
""),
74 "description" => $field->text($this->
lng->txt(
"description"))->withValue($values[
"description"] ??
""),
75 "prefix" => $field->text($this->
lng->txt(
"prefix"))->withRequired(
true)->withValue($values[
"prefix"] ??
""),
76 "language" => $field->select($this->
lng->txt(
"language"), $this->getLanguageOptions())->withRequired(
true),
77 "types" => $field->multiSelect($this->
lng->txt(
"act_lti_for_obj_type"), $type_options)
78 ->withValue(array_values(array_intersect($values[
"types"], array_keys($type_options)))),
79 "role" => $field->select($this->
lng->txt(
"gbl_roles_to_users"), $role_options)->withRequired(
true),
80 "active" => $field->checkbox($this->
lng->txt(
"active"))->withValue($values[
"active"]),
83 $inputs[
"names_roles"] = $field->checkbox(
84 $this->
lng->txt(
"lti_con_names_roles"),
85 $this->lng->txt(
"lti_platform_names_roles_info")
86 )->withValue($values[
"names_roles"] ??
false);
89 $inputs[
"language"] =
$inputs[
"language"]->withValue($values[
"language"]);
91 if (isset($values[
"role"], $role_options[$values[
"role"]])) {
96 "general" => $field->section(
98 $this->
lng->txt($this->platform_id > 0 ?
"lti_edit_consumer" :
"lti_create_consumer")
104 foreach (self::REGISTRATION_FIELDS as $key => $txt) {
105 $inputs[$key] = $field->text($this->
lng->txt($txt))->withValue($registration[$key]);
108 $sections[
"registration"] = $field->section(
$inputs + [
109 "dynamic_registration_url" => $field->text(
110 $this->lng->txt(
"lti_dyn_reg_tool_url"),
111 $this->lng->txt($this->platform_id > 0 ?
"lti_dyn_reg_tool_url_info" :
"lti_dyn_reg_tool_url_after_save")
112 )->withValue($this->platform_id > 0 ? $this->getDynamicRegistrationUrl() :
"")->withDisabled(
true),
115 "launch_url" => $field->text($this->lng->txt(
"lti_launch_url"))
117 "deep_linking_url" => $field->text($this->lng->txt(
"lti_deep_linking_url"))
119 "ilias_keyset_url" => $field->text($this->lng->txt(
"lti_con_key_type_jwk"))
121 ], $this->lng->txt(
"lti_platform_registration"), $this->lng->txt(
"lti_platform_registration_info"))
122 ->withAdditionalTransformation($this->
refinery->custom()->constraint(
123 static fn(array
$data):
bool => count(array_unique(array_map(
124 static fn(
string $key):
bool => trim((
string)
$data[$key]) ===
"",
125 array_keys(self::REGISTRATION_FIELDS)
127 $this->
lng->txt(
"lti_platform_registration_incomplete")
129 ->withAdditionalTransformation($this->
refinery->custom()->transformation(
130 static fn(array
$data): array => array_map(
132 array_intersect_key(
$data, self::REGISTRATION_FIELDS)
136 ->withAdditionalTransformation($this->
refinery->custom()->constraint(
137 fn(array
$data):
bool =>
$data[
"platform_id"] ===
"" || in_array(
139 [0, $this->platform_id],
142 $this->
lng->txt(
"lti_platform_registration_taken")
146 return $this->ui_factory->input()->container()->form()->standard($action, $sections);
152 public function save(
string $action, ServerRequestInterface
$request): ?Form
155 $data = $form->getData();
156 if (
$data ===
null) {
159 $registration =
$data[
"registration"] ??
null;
163 "title" => [
"text",
$data[
"title"]],
164 "description" => [
"text",
$data[
"description"]],
165 "prefix" => [
"text",
$data[
"prefix"]],
166 "user_language" => [
"text",
$data[
"language"]],
167 "role" => [
"integer", (
int)
$data[
"role"]],
168 "active" => [
"integer", (
int)
$data[
"active"]],
169 "names_roles" => [
"integer", (
int) (
$data[
"names_roles"] ??
false)],
171 $platform_id = $this->platform_id;
172 if ($platform_id > 0) {
173 $this->db->update(
"lti_ext_consumer", $fields, [
"id" => [
"integer", $platform_id]]);
175 $platform_id = $this->db->nextId(
"lti_ext_consumer");
176 $this->db->insert(
"lti_ext_consumer", $fields + [
"id" => [
"integer", $platform_id]]);
179 $this->db->manipulate(
"DELETE FROM lti_ext_consumer_otype WHERE consumer_id = " . $this->db->quote($platform_id,
"integer"));
180 foreach ((array)
$data[
"types"] as $type) {
181 $this->db->insert(
"lti_ext_consumer_otype", [
182 "consumer_id" => [
"integer", $platform_id],
183 "object_type" => [
"text", $type],
187 if ($registration !==
null) {
209 $DIC->logger()->forComponent(
'lti')->error(
$e->getMessage());
220 $this->db->setLimit(1);
221 $row = $this->platform_id > 0 ? $this->db->fetchAssoc($this->db->query(
222 "SELECT platform_id, client_id, deployment_id, settings FROM lti2_consumer WHERE lti_version = "
224 . $this->db->quote($this->platform_id,
"integer") .
" ORDER BY ref_id"
226 $settings = json_decode((
string) ($row[
"settings"] ??
""),
true);
230 "platform_id" => (string) ($row[
"platform_id"] ??
""),
231 "client_id" => (string) ($row[
"client_id"] ??
""),
232 "deployment_id" => (string) ($row[
"deployment_id"] ??
""),
233 "keyset_url" => (string) (
$settings[
"_jku"] ??
""),
234 "token_url" => (string) (
$settings[
"_oauth2_access_token_url"] ??
""),
235 "authentication_url" => (string) (
$settings[
"_authentication_request_url"] ??
""),
248 "title" => (string) ($row[
"title"] ??
""),
249 "description" => (string) ($row[
"description"] ??
""),
250 "prefix" => (string) ($row[
"prefix"] ??
""),
251 "language" => (string) ($row[
"user_language"] ??
""),
252 "role" => (string) ($row[
"role"] ??
""),
253 "active" => (bool) ($row[
"active"] ??
false),
254 "names_roles" => (bool) ($row[
"names_roles"] ??
false),
265 foreach ($this->
lng->getInstalledLanguages() as $lang_key) {
278 foreach ($this->obj_definition->getLTIProviderTypes() as $type) {
279 $options[$type] = $this->
lng->txt(
"objs_" . $type);
290 $this->
lng->loadLanguageModule(
"rbac");
Builds a Color from either hex- or rgb values.
Base class for ILIAS Exception handling.
static getUrl(string $script, string $suffix='')
The URL of an entry point, with the query or path that follows it.
static _lookupEntry(string $a_lang_key, string $a_mod, string $a_id)
static _getTranslation(string $a_role_title)
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupTitle(int $obj_id)
class ilRbacReview Contains Review functions of core Rbac.
This is how the factory for UI elements looks.
$request
@ilCtrl_Calls ilObjLearningSequenceContentGUI: ilObjLearningSequenceConditionsGUI