ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPreviewGUI Class Reference
+ Inheritance diagram for ilPreviewGUI:
+ Collaboration diagram for ilPreviewGUI:

Public Member Functions

 __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. More...
 
 executeCommand ()
 execute command More...
 
 getJSCall (string $a_html_id)
 Gets the JavaScript code to show the preview. More...
 
 getPreviewHTML ()
 Gets the HTML that displays the preview. More...
 
 getInlineHTML ()
 Gets the HTML that is used for displaying the preview inline. More...
 
 renderPreview ()
 Renders the preview and returns the HTML code that displays the preview. More...
 
 deletePreview ()
 Deletes the preview and returns the HTML code that displays the preview. More...
 

Static Public Member Functions

static initPreview ()
 Initializes the preview and loads the needed javascripts and styles. More...
 

Data Fields

const CONTEXT_REPOSITORY = 1
 
const CONTEXT_WORKSPACE = 2
 

Private Member Functions

 renderCommand (ilTemplate $tmpl, string $a_cmd, string $btn_topic, string $loading_topic, array $a_display_status)
 Renders a command to the specified template. More...
 
 getHtmlId ()
 Gets the HTML id for the preview. More...
 
 buildUrl (string $a_cmd="", bool $a_async=true)
 Builds the URL to call the preview GUI. More...
 

Static Private Member Functions

static jsonSafeString (string $text)
 Makes the specified string safe for JSON. More...
 

Private Attributes

int $node_id = null
 
int $obj_id = null
 
ilPreview $preview = null
 
object $access_handler = null
 
int $context = null
 
ilCtrl $ctrl = null
 
ilLanguage $lng = null
 

Static Private Attributes

static bool $initialized = false
 

Detailed Description

Definition at line 26 of file class.ilPreviewGUI.php.

Constructor & Destructor Documentation

◆ __construct()

ilPreviewGUI::__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.

Parameters
int$a_node_idThe node id.
int$a_contextThe context of the preview.
int$a_obj_idThe object id.
ilWorkspaceAccessHandler | ilAccessHandler | null$a_access_handlerThe access handler to use.

Definition at line 50 of file class.ilPreviewGUI.php.

References $DIC, $query, ilObject\_lookupObjId(), ILIAS\Repository\ctrl(), and ILIAS\Repository\lng().

55  {
56  global $DIC;
57  // assign values
58  $this->ctrl = $DIC->ctrl();
59  $this->lng = $DIC->language();
60  $ilAccess = $DIC['ilAccess'];
61 
62  $query = $DIC->http()->wrapper()->query();
63  $base_class = $query->has('baseClass')
64  ? $query->retrieve('baseClass', $DIC->refinery()->to()->string())
65  : null;
66 
67  // if we are the base class, get the id's from the query 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())
71  : 0;
72  $this->context = $query->has('context')
73  ? $query->retrieve('context', $DIC->refinery()->kindlyTo()->int())
74  : self::CONTEXT_REPOSITORY;
75  $a_obj_id = $query->has('obj_id')
76  ? $query->retrieve('obj_id', $DIC->refinery()->kindlyTo()->int())
77  : null;
78  } else {
79  $this->node_id = $a_node_id;
80  $this->context = $a_context;
81  }
82 
83 
84 
85  // access handler NOT provided?
86  if ($a_access_handler === null) {
87  if ($this->context === self::CONTEXT_WORKSPACE) {
88  $a_access_handler = new ilWorkspaceAccessHandler();
89  } else {
90  $a_access_handler = $ilAccess;
91  }
92  }
93  $this->access_handler = $a_access_handler;
94 
95  // object id NOT provided?
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);
99  } else {
100  $a_obj_id = ilObject::_lookupObjId($this->node_id);
101  }
102  }
103  $this->obj_id = $a_obj_id;
104 
105  // create preview object
106  $this->preview = new ilPreview($this->obj_id);
107 
108  // if the call is NOT async initialize our stuff
109  if (!$this->ctrl->isAsynch()) {
110  self::initPreview();
111  }
112  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
$query
+ Here is the call graph for this function:

Member Function Documentation

◆ buildUrl()

ilPreviewGUI::buildUrl ( string  $a_cmd = "",
bool  $a_async = true 
)
private

Builds the URL to call the preview GUI.

Parameters
$a_cmdstring The command to call.
$a_asyncbool true, to create a URL to call asynchronous; otherwise, false.
Returns
string The created URL.

Definition at line 331 of file class.ilPreviewGUI.php.

Referenced by getJSCall(), and renderCommand().

331  : string
332  {
333  $link = "ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}&obj_id={$this->obj_id}";
334 
335  if ($a_async) {
336  $link .= "&cmdMode=asynch";
337  }
338 
339  if (!empty($a_cmd)) {
340  $link .= "&cmd=$a_cmd";
341  }
342 
343  return $link;
344  }
+ Here is the caller graph for this function:

◆ deletePreview()

ilPreviewGUI::deletePreview ( )

Deletes the preview and returns the HTML code that displays the preview.

Returns
string The HTML code that displays the preview.

Definition at line 306 of file class.ilPreviewGUI.php.

References getPreviewHTML().

306  : string
307  {
308  // has read access?
309  if ($this->access_handler->checkAccess("write", "", $this->node_id)) {
310  $this->preview->delete();
311  }
312 
313  return $this->getPreviewHTML();
314  }
getPreviewHTML()
Gets the HTML that displays the preview.
+ Here is the call graph for this function:

◆ executeCommand()

ilPreviewGUI::executeCommand ( )

execute command

Definition at line 118 of file class.ilPreviewGUI.php.

References ILIAS\Repository\ctrl().

119  {
120  $cmd = $this->ctrl->getCmd("getPreviewHTML");
121  $next_class = $this->ctrl->getNextClass($this);
122 
123  switch ($next_class) {
124  default:
125  return $this->$cmd();
126  break;
127  }
128  }
+ Here is the call graph for this function:

◆ getHtmlId()

ilPreviewGUI::getHtmlId ( )
private

Gets the HTML id for the preview.

Returns
string The HTML id to use for the preview.

Definition at line 320 of file class.ilPreviewGUI.php.

References $node_id.

Referenced by getPreviewHTML(), and renderCommand().

320  : string
321  {
322  return "preview_" . $this->node_id;
323  }
+ Here is the caller graph for this function:

◆ getInlineHTML()

ilPreviewGUI::getInlineHTML ( )

Gets the HTML that is used for displaying the preview inline.

Returns
string The HTML that is used for displaying the preview inline.

Definition at line 226 of file class.ilPreviewGUI.php.

References getPreviewHTML(), ilPreview\RENDER_STATUS_CREATED, ilPreview\RENDER_STATUS_FAILED, ilPreview\RENDER_STATUS_NONE, and renderCommand().

226  : string
227  {
228  $tmpl = new ilTemplate("tpl.preview_inline.html", true, true, "Services/Preview");
229  $tmpl->setVariable("PREVIEW", $this->getPreviewHTML());
230 
231  // rendering allowed?
232  if ($this->access_handler->checkAccess("read", "", $this->node_id)) {
233  $this->renderCommand(
234  $tmpl,
235  "render",
236  "preview_create",
237  "preview_status_creating",
239  );
240  }
241 
242  // delete allowed?
243  if ($this->access_handler->checkAccess("write", "", $this->node_id)) {
244  $this->renderCommand(
245  $tmpl,
246  "delete",
247  "preview_delete",
248  "preview_status_deleting",
250  );
251  }
252 
253  return $tmpl->get();
254  }
const RENDER_STATUS_FAILED
renderCommand(ilTemplate $tmpl, string $a_cmd, string $btn_topic, string $loading_topic, array $a_display_status)
Renders a command to the specified template.
const RENDER_STATUS_NONE
getPreviewHTML()
Gets the HTML that displays the preview.
const RENDER_STATUS_CREATED
+ Here is the call graph for this function:

◆ getJSCall()

ilPreviewGUI::getJSCall ( string  $a_html_id)

Gets the JavaScript code to show the preview.

Parameters
$a_html_idstring The id of the HTML element that contains the preview.
Returns
string The JavaScript code to show the preview.

Definition at line 135 of file class.ilPreviewGUI.php.

References buildUrl(), ILIAS\Repository\lng(), and ilPreview\RENDER_STATUS_NONE.

135  : string
136  {
137  $status = $this->preview->getRenderStatus();
138  $command = $status === ilPreview::RENDER_STATUS_NONE ? "renderPreview" : "";
139  $loading_text = self::jsonSafeString(
140  $this->lng->txt($status === ilPreview::RENDER_STATUS_NONE ? "preview_status_creating" : "preview_loading")
141  );
142 
143  // build the url
144  $link = $this->buildUrl($command);
145  return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
146  }
const RENDER_STATUS_NONE
buildUrl(string $a_cmd="", bool $a_async=true)
Builds the URL to call the preview GUI.
+ Here is the call graph for this function:

◆ getPreviewHTML()

ilPreviewGUI::getPreviewHTML ( )

Gets the HTML that displays the preview.

Returns
string The HTML that displays the preview.

Definition at line 152 of file class.ilPreviewGUI.php.

References $index, $response, ilObject\_lookupTitle(), ILIAS\Repository\ctrl(), exit, getHtmlId(), ILIAS\Repository\lng(), ilPreview\RENDER_STATUS_FAILED, ilPreview\RENDER_STATUS_PENDING, and ilWACSignedPath\signFile().

Referenced by deletePreview(), getInlineHTML(), and renderPreview().

152  : string
153  {
154  // load the template
155  $tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
156  $tmpl->setVariable("PREVIEW_ID", $this->getHtmlId());
157 
158  // check for read access and get object id
159  $preview_status = $this->preview->getRenderStatus();
160 
161  // has read access?
162  if ($this->access_handler->checkAccess("read", "", $this->node_id)) {
163  // preview images available?
164  $images = $this->preview->getImages();
165  if (count($images) > 0) {
166  $title = ilObject2::_lookupTitle($this->obj_id);
167  $index = 1;
168  foreach ($images as $image) {
169  $tmpl->setCurrentBlock("preview_item");
170  $tmpl->setVariable("IMG_URL", ilWACSignedPath::signFile($image["url"]));
171  $tmpl->setVariable("WIDTH", $image["width"]);
172  $tmpl->setVariable("HEIGHT", $image["height"]);
173  $tmpl->setVariable("ALT_TEXT", sprintf(
174  $this->lng->txt('preview_caption'),
175  (string) $index . ' ',
176  $title
177  ));
178  $tmpl->parseCurrentBlock();
179  $index++;
180  }
181  } else {
182  // set text depending on the status
183  $tmpl->setCurrentBlock("no_preview");
184  switch ($preview_status) {
186  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_pending"));
187  break;
188 
190  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_failed"));
191  break;
192 
193  default:
194  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_missing"));
195  break;
196  }
197  $tmpl->parseCurrentBlock();
198  }
199  } else {
200  // display error message
201  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("no_access_item"));
202  }
203 
204  // output
205  if ($this->ctrl->isAsynch()) {
206  $response = new stdClass();
207  $response->html = $tmpl->get();
208  $response->status = $preview_status;
209 
210  // send response object (don't use 'application/json' as IE wants to download it!)
211  header('Vary: Accept');
212  header('Content-type: text/plain');
213  echo json_encode($response, JSON_THROW_ON_ERROR);
214 
215  // no further processing!
216  exit;
217  }
218 
219  return $tmpl->get();
220  }
exit
Definition: login.php:28
const RENDER_STATUS_FAILED
const RENDER_STATUS_PENDING
$index
Definition: metadata.php:145
static _lookupTitle(int $obj_id)
static signFile(string $path_to_file)
getHtmlId()
Gets the HTML id for the preview.
$response
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initPreview()

static ilPreviewGUI::initPreview ( )
static

Initializes the preview and loads the needed javascripts and styles.

Definition at line 350 of file class.ilPreviewGUI.php.

References $DIC, $i, ilPreviewSettings\getImageSize(), ilTooltipGUI\init(), iljQueryUtil\initjQuery(), and ilLegacyFormElementsUtil\prepareFormOutput().

Referenced by ilObjCategoryGUI\addHeaderAction().

350  : void
351  {
352  if (self::$initialized) {
353  return;
354  }
355 
356  global $DIC;
357  // jquery
359 
360  // load qtip
362 
363  // needed scripts & styles
364  $DIC->ui()->mainTemplate()->addJavaScript("./libs/bower/bower_components/jquery-mousewheel/jquery.mousewheel.js");
365  $DIC->ui()->mainTemplate()->addJavaScript("./Services/Preview/js/ilPreview.js");
366 
367  // create loading template
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();
372 
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) {
377  if (!empty($line)) {
378  $new_lines[] = trim($line);
379  }
380  }
381  $initialHtml = implode($new_lines);
382 
383  // add default texts and values
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"))
386  . "\";");
387  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.texts.close = \"" . ilLegacyFormElementsUtil::prepareFormOutput(
388  $DIC->language()->txt("close")
389  ) . "\";");
390  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.previewSize = " . ilPreviewSettings::getImageSize() . ";");
391  $DIC->ui()->mainTemplate()->addOnLoadCode(
392  "il.Preview.initialHtml = " . json_encode($initialHtml, JSON_THROW_ON_ERROR) . ";"
393  );
394  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
395  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.init();");
396 
397  self::$initialized = true;
398  }
static init()
Initializes the needed tooltip libraries.
static prepareFormOutput($a_str, bool $a_strip=false)
global $DIC
Definition: feed.php:28
static getImageSize()
Gets the size of the preview images in pixels.
static initjQuery(ilGlobalTemplateInterface $a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
$i
Definition: metadata.php:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jsonSafeString()

static ilPreviewGUI::jsonSafeString ( string  $text)
staticprivate

Makes the specified string safe for JSON.

Parameters
string$textThe text to make JSON safe.
Returns
string The JSON safe text.

Definition at line 406 of file class.ilPreviewGUI.php.

406  : string
407  {
408  if (!is_string($text)) {
409  return $text;
410  }
411 
412  $text = htmlentities($text, ENT_COMPAT | ENT_HTML401, "UTF-8");
413  $text = str_replace("'", "'", $text);
414  return $text;
415  }

◆ renderCommand()

ilPreviewGUI::renderCommand ( ilTemplate  $tmpl,
string  $a_cmd,
string  $btn_topic,
string  $loading_topic,
array  $a_display_status 
)
private

Renders a command to the specified template.

Parameters
$tmplobject The template.
$a_cmdstring The command to create.
$btn_topicstring The topic to get the button text.
$loading_topicstring The topic to get the loading text.
$a_display_statusstring[] An array containing the statuses when the command should be visible.

Definition at line 264 of file class.ilPreviewGUI.php.

References buildUrl(), getHtmlId(), ILIAS\Repository\lng(), ilTemplate\parseCurrentBlock(), ilTemplate\setCurrentBlock(), and HTML_Template_IT\setVariable().

Referenced by getInlineHTML().

264  : void
265  {
266  $preview_html_id = $this->getHtmlId();
267  $preview_status = $this->preview->getRenderStatus();
268  $loading_text = self::jsonSafeString($this->lng->txt($loading_topic));
269 
270  $link = $this->buildUrl($a_cmd . "Preview");
271  $script_args = "event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
272 
273  $action_class = "";
274  if (!in_array($preview_status, $a_display_status, true)) {
275  $action_class = "ilPreviewActionHidden";
276  }
277 
278  $tmpl->setCurrentBlock("preview_action");
279  $tmpl->setVariable("CLICK_ACTION", "il.Preview.$a_cmd($script_args);");
280  $tmpl->setVariable("ACTION_CLASS", $action_class);
281  $tmpl->setVariable("ACTION_ID", "preview_{$a_cmd}_" . $preview_html_id);
282  $tmpl->setVariable("TXT_ACTION", $this->lng->txt($btn_topic));
283  $tmpl->parseCurrentBlock();
284  }
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
setVariable($variable, $value='')
Sets a variable value.
Definition: IT.php:514
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
buildUrl(string $a_cmd="", bool $a_async=true)
Builds the URL to call the preview GUI.
getHtmlId()
Gets the HTML id for the preview.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ renderPreview()

ilPreviewGUI::renderPreview ( )

Renders the preview and returns the HTML code that displays the preview.

Returns
string The HTML code that displays the preview.

Definition at line 290 of file class.ilPreviewGUI.php.

References ilObjectFactory\getInstanceByObjId(), and getPreviewHTML().

290  : string
291  {
292  // has read access?
293  if ($this->access_handler->checkAccess("read", "", $this->node_id)) {
294  // get the object
295  $obj = ilObjectFactory::getInstanceByObjId($this->obj_id);
296  $this->preview->create($obj);
297  }
298 
299  return $this->getPreviewHTML();
300  }
getPreviewHTML()
Gets the HTML that displays the preview.
static getInstanceByObjId(?int $obj_id, bool $stop_on_error=true)
get an instance of an Ilias object by object id
+ Here is the call graph for this function:

Field Documentation

◆ $access_handler

object ilPreviewGUI::$access_handler = null
private

Definition at line 34 of file class.ilPreviewGUI.php.

◆ $context

int ilPreviewGUI::$context = null
private

Definition at line 35 of file class.ilPreviewGUI.php.

◆ $ctrl

ilCtrl ilPreviewGUI::$ctrl = null
private

Definition at line 36 of file class.ilPreviewGUI.php.

◆ $initialized

bool ilPreviewGUI::$initialized = false
staticprivate

Definition at line 38 of file class.ilPreviewGUI.php.

◆ $lng

ilLanguage ilPreviewGUI::$lng = null
private

Definition at line 37 of file class.ilPreviewGUI.php.

◆ $node_id

int ilPreviewGUI::$node_id = null
private

Definition at line 28 of file class.ilPreviewGUI.php.

Referenced by getHtmlId().

◆ $obj_id

int ilPreviewGUI::$obj_id = null
private

Definition at line 29 of file class.ilPreviewGUI.php.

◆ $preview

ilPreview ilPreviewGUI::$preview = null
private

Definition at line 30 of file class.ilPreviewGUI.php.

◆ CONTEXT_REPOSITORY

const ilPreviewGUI::CONTEXT_REPOSITORY = 1

◆ CONTEXT_WORKSPACE

const ilPreviewGUI::CONTEXT_WORKSPACE = 2

The documentation for this class was generated from the following file: