ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilLTIConsumerContentGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2019 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5
15{
16 const CMD_LAUNCH = 'launch';
17 const CMD_SHOW_EMBEDDED = 'showEmbedded';
18
22 protected $object;
23
27 protected $cmixUser;
28
32 private $dic;
33
37 private $lng;
38
42 private $user;
47 {
48 global $DIC;
49 $this->dic = $DIC;
50 $this->lng = $DIC->language();
51 $this->user = $DIC->user();
52 $this->object = $object;
53 }
54
55 public function executeCommand()
56 {
57 global $DIC; /* @var \ILIAS\DI\Container $DIC */
58
59 if ($this->object->getProvider()->getAvailability() == ilLTIConsumeProvider::AVAILABILITY_NONE) {
60 throw new ilLtiConsumerException('access denied!');
61 }
62
63 $command = $DIC->ctrl()->getCmd(self::CMD_LAUNCH);
64
65 $this->{$command}();
66 }
67
68// protected function showPage()
69// {
70// global $DIC; /* @var \ILIAS\DI\Container $DIC */
71//
72// $tpl = new ilTemplate('tpl.lti_content.html', true, true, 'Modules/LTIConsumer');
73//
74// $tpl->setVariable("EMBEDDED_IFRAME_SRC", $DIC->ctrl()->getLinkTarget(
75// $this,
76// self::CMD_SHOW_EMBEDDED
77// ));
78//
79// $DIC->ui()->mainTemplate()->setContent($tpl->get());
80// }
81
86 protected function launch() : void
87 {
88 if ($this->dic->access()->checkAccess('read', '', $this->object->getRefId())) {
89 if ($this->object->isLaunchMethodEmbedded()) {
90 $tpl = new ilTemplate('tpl.lti_content.html', true, true, 'Modules/LTIConsumer');
91 $tpl->setVariable("EMBEDDED_IFRAME_SRC", $this->dic->ctrl()->getLinkTarget(
92 $this,
93 self::CMD_SHOW_EMBEDDED
94 ));
95 $this->dic->ui()->mainTemplate()->setContent($tpl->get());
96 } else {
97 $this->dic->toolbar()->addText($this->getStartButtonTxt11());
98 }
99 }
100 }
101
102 protected function getStartButtonTxt11() : string
103 {
104 if ($this->object->getOfflineStatus() ||
105 $this->object->isLaunchMethodEmbedded() ||
106 $this->object->getProvider()->getAvailability() == ilLTIConsumeProvider::AVAILABILITY_NONE) {
107 return "";
108 }
109
111 $this->object->getId(),
112 $this->user->getId(),
113 $this->object->getProvider()->getPrivacyIdent()
114 );
115 $user_ident = $cmixUser->getUsrIdent();
116 if ($user_ident == '' || $user_ident == null) {
117 $user_ident = ilCmiXapiUser::getIdent($this->object->getProvider()->getPrivacyIdent(), $this->dic->user());
118 $cmixUser->setUsrIdent($user_ident);
119 $cmixUser->save();
120 }
121 $ilLTIConsumerLaunch = new ilLTIConsumerLaunch($this->object->getRefId());
122 $context = $ilLTIConsumerLaunch->getContext();
123 $contextType = $ilLTIConsumerLaunch::getLTIContextType($context["type"]);
124 $contextId = $context["id"];
125 $contextTitle = $context["title"];
126
128 $this->dic->user()->getId(),
129 $this->object->getRefId(),
130 $this->object->getId()
131 );
132
133 $returnUrl = !$this->object->isLaunchMethodOwnWin() ? '' : str_replace(
134 '&amp;',
135 '&',
136 ILIAS_HTTP_PATH . "/" . $this->dic->ctrl()->getLinkTarget($this, "", "", false)
137 );
138
139 $launchParameters = $this->object->buildLaunchParameters(
140 $cmixUser,
141 $token,
142 $contextType,
143 $contextId,
144 $contextTitle,
145 $returnUrl
146 );
147
148 $target = $this->object->getLaunchMethod() == "newWin" ? "_blank" : "_self";
149 $button = '<input class="btn btn-default ilPre" type="button" onClick="ltilaunch()" value = "' . $this->lng->txt("show_content") . '" />';
150 $output = '<form id="lti_launch_form" name="lti_launch_form" action="' . $this->object->getProvider()->getProviderUrl() . '" method="post" target="' . $target . '" encType="application/x-www-form-urlencoded">';
151 foreach ($launchParameters as $field => $value) {
152 $output .= sprintf('<input type="hidden" name="%s" value="%s" />', $field, $value) . "\n";
153 }
154 $output .= $button;
155 $output .= '</form>';
156 $output .= '<span id ="lti_launched" style="display:none">' . $this->lng->txt("launched") . '</span>';
157 $output .= '<script type="text/javascript">
158 function ltilaunch() {
159 document.lti_launch_form.submit();
160 document.getElementById("lti_launch_form").style.display = "none";
161 document.getElementById("lti_launched").style.display = "inline";
162 }</script>';
163 return($output);
164 }
165 protected function showEmbedded()
166 {
167 $this->initCmixUser();
168
169 $tpl = new ilTemplate('tpl.lti_embedded.html', true, true, 'Modules/LTIConsumer');
170
171 foreach ($this->getLaunchParameters() as $field => $value) {
172 $tpl->setCurrentBlock('launch_parameter');
173 $tpl->setVariable('LAUNCH_PARAMETER', $field);
174 $tpl->setVariable('LAUNCH_PARAM_VALUE', $value);
175 $tpl->parseCurrentBlock();
176 }
177
178 $v = DEVMODE ? '?vers=' . time() : '?vers=' . ILIAS_VERSION_NUMERIC;
179 $tpl->setVariable("DELOS_CSS_HREF", 'templates/default/delos.css' . $v);
180 $tpl->setVariable("JQUERY_SRC", 'libs/bower/bower_components/jquery/dist/jquery.js' . $v);
181
182 $tpl->setVariable("LOADER_ICON_SRC", ilUtil::getImagePath("loader.svg"));
183 $tpl->setVariable('LAUNCH_URL', $this->object->getProvider()->getProviderUrl());
184
185 #$DIC->ui()->mainTemplate()->getStandardTemplate();
186 #$DIC->ui()->mainTemplate()->setContent($tpl->get());
187
188 echo $tpl->get();
189 exit;
190 }
191
192 protected function getLaunchParameters()
193 {
194 $ilLTIConsumerLaunch = new ilLTIConsumerLaunch($this->object->getRefId());
195 $launchContext = $ilLTIConsumerLaunch->getContext();
196
197 $launchContextType = ilLTIConsumerLaunch::getLTIContextType($launchContext["type"]);
198 $launchContextId = $launchContext["id"];
199 $launchContextTitle = $launchContext["title"];
200
202 $this->dic->user()->getId(),
203 $this->object->getRefId(),
204 $this->object->getId()
205 );
206
207 return $this->object->buildLaunchParameters(
208 $this->cmixUser,
209 $token,
210 $launchContextType,
211 $launchContextId,
212 $launchContextTitle
213 );
214 }
215
216 public static function isEmbeddedLaunchRequest() : bool
217 {
218 global $DIC; /* @var \ILIAS\DI\Container $DIC */
219
220 if ($DIC->ctrl()->getNextClass() != strtolower(self::class)) {
221 return false;
222 }
223
224 if ($DIC->ctrl()->getCmd() != self::CMD_SHOW_EMBEDDED) {
225 return false;
226 }
227
228 return true;
229 }
230
231 protected function initCmixUser()
232 {
233 global $DIC; /* @var \ILIAS\DI\Container $DIC */
234
235 $this->cmixUser = new ilCmiXapiUser($this->object->getId(), $DIC->user()->getId(), $this->object->getProvider()->getPrivacyIdent());
236 $user_ident = $this->cmixUser->getUsrIdent();
237 if ($user_ident == '' || $user_ident == null) {
238 $user_ident = ilCmiXapiUser::getIdent($this->object->getProvider()->getPrivacyIdent(), $DIC->user());
239 $this->cmixUser->setUsrIdent($user_ident);
240 $this->cmixUser->save();
241 }
242 }
243}
user()
Definition: user.php:4
An exception for terminatinating execution or to throw for unit testing.
static fillToken($usrId, $refId, $objId, $lrsTypeId=0)
static getIdent($userIdentMode, ilObjUser $user)
__construct(ilObjLTIConsumer $object)
special template class to simplify handling of ITX/PEAR
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
global $DIC
Definition: goto.php:24
const ILIAS_VERSION_NUMERIC
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
exit
Definition: login.php:29
$context
Definition: webdav.php:26
$token
Definition: xapitoken.php:52