51 ?
int $a_node_id =
null,
52 ?
int $a_context = self::CONTEXT_REPOSITORY,
53 ?
int $a_obj_id =
null,
54 ?
object $a_access_handler =
null
58 $this->
ctrl = $DIC->ctrl();
59 $this->
lng = $DIC->language();
60 $ilAccess =
$DIC[
'ilAccess'];
63 $base_class =
$query->has(
'baseClass')
64 ?
$query->retrieve(
'baseClass',
$DIC->refinery()->to()->string())
68 if (strtolower($base_class) === strtolower(__CLASS__)) {
69 $this->node_id =
$query->has(
'node_id')
70 ?
$query->retrieve(
'node_id',
$DIC->refinery()->kindlyTo()->int())
72 $this->context =
$query->has(
'context')
73 ?
$query->retrieve(
'context',
$DIC->refinery()->kindlyTo()->int())
75 $a_obj_id =
$query->has(
'obj_id')
76 ?
$query->retrieve(
'obj_id',
$DIC->refinery()->kindlyTo()->int())
79 $this->node_id = $a_node_id;
80 $this->context = $a_context;
86 if ($a_access_handler ===
null) {
87 if ($this->context === self::CONTEXT_WORKSPACE) {
90 $a_access_handler = $ilAccess;
93 $this->access_handler = $a_access_handler;
96 if ($a_obj_id ===
null) {
97 if ($this->context === self::CONTEXT_WORKSPACE) {
98 $a_obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
103 $this->obj_id = $a_obj_id;
106 $this->preview =
new ilPreview($this->obj_id);
109 if (!$this->
ctrl->isAsynch()) {
120 $cmd = $this->
ctrl->getCmd(
"getPreviewHTML");
121 $next_class = $this->
ctrl->getNextClass($this);
123 switch ($next_class) {
125 return $this->$cmd();
137 $status = $this->preview->getRenderStatus();
145 return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
155 $tmpl =
new ilTemplate(
"tpl.preview.html",
true,
true,
"Services/Preview");
156 $tmpl->setVariable(
"PREVIEW_ID", $this->
getHtmlId());
159 $preview_status = $this->preview->getRenderStatus();
162 if ($this->access_handler->checkAccess(
"read",
"", $this->node_id)) {
164 $images = $this->preview->getImages();
165 if (count($images) > 0) {
168 foreach ($images as $image) {
169 $tmpl->setCurrentBlock(
"preview_item");
171 $tmpl->setVariable(
"WIDTH", $image[
"width"]);
172 $tmpl->setVariable(
"HEIGHT", $image[
"height"]);
173 $tmpl->setVariable(
"ALT_TEXT", sprintf(
174 $this->
lng->txt(
'preview_caption'),
178 $tmpl->parseCurrentBlock();
183 $tmpl->setCurrentBlock(
"no_preview");
184 switch ($preview_status) {
186 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->
lng->txt(
"preview_status_pending"));
190 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->
lng->txt(
"preview_status_failed"));
194 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->
lng->txt(
"preview_status_missing"));
197 $tmpl->parseCurrentBlock();
201 $tmpl->setVariable(
"TXT_NO_PREVIEW", $this->
lng->txt(
"no_access_item"));
205 if ($this->
ctrl->isAsynch()) {
211 header(
'Vary: Accept');
212 header(
'Content-type: text/plain');
213 echo json_encode(
$response, JSON_THROW_ON_ERROR);
228 $tmpl =
new ilTemplate(
"tpl.preview_inline.html",
true,
true,
"Services/Preview");
232 if ($this->access_handler->checkAccess(
"read",
"", $this->node_id)) {
237 "preview_status_creating",
243 if ($this->access_handler->checkAccess(
"write",
"", $this->node_id)) {
248 "preview_status_deleting",
264 private function renderCommand(
ilTemplate $tmpl,
string $a_cmd,
string $btn_topic,
string $loading_topic, array $a_display_status): void
267 $preview_status = $this->preview->getRenderStatus();
270 $link = $this->
buildUrl($a_cmd .
"Preview");
271 $script_args =
"event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
274 if (!in_array($preview_status, $a_display_status,
true)) {
275 $action_class =
"ilPreviewActionHidden";
279 $tmpl->
setVariable(
"CLICK_ACTION",
"il.Preview.$a_cmd($script_args);");
281 $tmpl->
setVariable(
"ACTION_ID",
"preview_{$a_cmd}_" . $preview_html_id);
293 if ($this->access_handler->checkAccess(
"read",
"", $this->node_id)) {
296 $this->preview->create($obj);
309 if ($this->access_handler->checkAccess(
"write",
"", $this->node_id)) {
310 $this->preview->delete();
331 private function buildUrl(
string $a_cmd =
"",
bool $a_async =
true): string
333 $link =
"ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}&obj_id={$this->obj_id}";
336 $link .=
"&cmdMode=asynch";
339 if (!empty($a_cmd)) {
340 $link .=
"&cmd=$a_cmd";
352 if (self::$initialized) {
364 $DIC->ui()->mainTemplate()->addJavaScript(
"./libs/bower/bower_components/jquery-mousewheel/jquery.mousewheel.js");
365 $DIC->ui()->mainTemplate()->addJavaScript(
"./Services/Preview/js/ilPreview.js");
368 $tmpl =
new ilTemplate(
"tpl.preview.html",
true,
true,
"Services/Preview");
369 $tmpl->setCurrentBlock(
"no_preview");
370 $tmpl->setVariable(
"TXT_NO_PREVIEW",
"%%0%%");
371 $tmpl->parseCurrentBlock();
373 $initialHtml = str_replace(array(
"\r\n",
"\r"),
"\n", $tmpl->get());
374 $lines = explode(
"\n", $initialHtml);
375 $new_lines = array();
376 foreach ($lines as
$i => $line) {
378 $new_lines[] = trim($line);
381 $initialHtml = implode($new_lines);
384 $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.texts.preview = \"" . self::jsonSafeString(
$DIC->language()->txt(
"preview")) .
"\";");
385 $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.texts.showPreview = \"" . self::jsonSafeString(
$DIC->language()->txt(
"preview_show"))
388 $DIC->language()->txt(
"close")
391 $DIC->ui()->mainTemplate()->addOnLoadCode(
392 "il.Preview.initialHtml = " . json_encode($initialHtml, JSON_THROW_ON_ERROR) .
";"
394 $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
395 $DIC->ui()->mainTemplate()->addOnLoadCode(
"il.Preview.init();");
397 self::$initialized =
true;
408 if (!is_string($text)) {
412 $text = htmlentities($text, ENT_COMPAT | ENT_HTML401,
"UTF-8");
413 $text = str_replace(
"'",
"'", $text);
setVariable($variable, $value='')
Sets a variable value.
Class ilCtrl provides processing control methods.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
getInlineHTML()
Gets the HTML that is used for displaying the preview inline.
renderPreview()
Renders the preview and returns the HTML code that displays the preview.
deletePreview()
Deletes the preview and returns the HTML code that displays the preview.
__construct(?int $a_node_id=null, ?int $a_context=self::CONTEXT_REPOSITORY, ?int $a_obj_id=null, ?object $a_access_handler=null)
Creates a new preview GUI.
getHtmlId()
Gets the HTML id for the preview.
getPreviewHTML()
Gets the HTML that displays the preview.
renderCommand(ilTemplate $tmpl, string $a_cmd, string $btn_topic, string $loading_topic, array $a_display_status)
Renders a command to the specified template.
executeCommand()
execute command
getJSCall(string $a_html_id)
Gets the JavaScript code to show the preview.
static initPreview()
Initializes the preview and loads the needed javascripts and styles.
static jsonSafeString(string $text)
Makes the specified string safe for JSON.
buildUrl(string $a_cmd="", bool $a_async=true)
Builds the URL to call the preview GUI.
static getImageSize()
Gets the size of the preview images in pixels.
const RENDER_STATUS_FAILED
const RENDER_STATUS_CREATED
const RENDER_STATUS_PENDING
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
static signFile(string $path_to_file)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
Interface ilCtrlBaseClassInterface describes ilCtrl base classes.