ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
ilPreviewGUI Class Reference
+ Collaboration diagram for ilPreviewGUI:

Public Member Functions

 __construct ($a_node_id=null, $a_context=self::CONTEXT_REPOSITORY, $a_obj_id=null, $a_access_handler=null)
 Creates a new preview GUI. More...
 
 executeCommand ()
 execute command More...
 
 getJSCall ($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 ($tmpl, $a_cmd, $btn_topic, $loading_topic, $a_display_status)
 Renders a command to the specified template. More...
 
 getHtmlId ()
 Gets the HTML id for the preview. More...
 
 buildUrl ($a_cmd="", $a_async=true)
 Builds the URL to call the preview GUI. More...
 

Static Private Member Functions

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

Private Attributes

 $node_id = null
 
 $obj_id = null
 
 $preview = null
 
 $access_handler = null
 
 $context = null
 
 $ctrl = null
 
 $lng = null
 

Static Private Attributes

static $initialized = false
 

Detailed Description

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

Constructor & Destructor Documentation

◆ __construct()

ilPreviewGUI::__construct (   $a_node_id = null,
  $a_context = self::CONTEXT_REPOSITORY,
  $a_obj_id = null,
  $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.
object$a_access_handlerThe access handler to use.

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

References $_GET, $DIC, $lng, ilObject\_lookupObjId(), and initPreview().

62  {
63  global $DIC;
64  $ilCtrl = $DIC['ilCtrl'];
65  $lng = $DIC['lng'];
66  $ilAccess = $DIC['ilAccess'];
67 
68  // if we are the base class, get the id's from the query string
69  if (strtolower($_GET["baseClass"]) == "ilpreviewgui") {
70  $this->node_id = (int) $_GET["node_id"];
71  $this->context = (int) $_GET["context"];
72  $a_obj_id = (int) $_GET['obj_id'];
73  } else {
74  $this->node_id = $a_node_id;
75  $this->context = $a_context;
76  }
77 
78  // assign values
79  $this->ctrl = $ilCtrl;
80  $this->lng = $lng;
81 
82  // access handler NOT provided?
83  if ($a_access_handler == null) {
84  if ($this->context == self::CONTEXT_WORKSPACE) {
85  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
86  $a_access_handler = new ilWorkspaceAccessHandler();
87  } else {
88  $a_access_handler = $ilAccess;
89  }
90  }
91  $this->access_handler = $a_access_handler;
92 
93  // object id NOT provided?
94  if ($a_obj_id == null) {
95  if ($this->context == self::CONTEXT_WORKSPACE) {
96  $a_obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
97  } else {
98  $a_obj_id = ilObject::_lookupObjId($this->node_id);
99  }
100  }
101  $this->obj_id = $a_obj_id;
102 
103  // create preview object
104  $this->preview = new ilPreview($this->obj_id);
105 
106  // if the call is NOT async initialize our stuff
107  if (!$ilCtrl->isAsynch()) {
109  }
110  }
$_GET["client_id"]
Access handler for personal workspace.
static _lookupObjId($a_id)
global $DIC
Definition: goto.php:24
static initPreview()
Initializes the preview and loads the needed javascripts and styles.
+ Here is the call graph for this function:

Member Function Documentation

◆ buildUrl()

ilPreviewGUI::buildUrl (   $a_cmd = "",
  $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 332 of file class.ilPreviewGUI.php.

Referenced by getJSCall(), and renderCommand().

333  {
334  $link = "ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}&obj_id={$this->obj_id}";
335 
336  if ($a_async) {
337  $link .= "&cmdMode=asynch";
338  }
339 
340  if (!empty($a_cmd)) {
341  $link .= "&cmd=$a_cmd";
342  }
343 
344  return $link;
345  }
+ 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 305 of file class.ilPreviewGUI.php.

References getPreviewHTML().

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

◆ executeCommand()

ilPreviewGUI::executeCommand ( )

execute command

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

117  {
118  $cmd = $this->ctrl->getCmd("getPreviewHTML");
119  $next_class = $this->ctrl->getNextClass($this);
120 
121  switch ($next_class) {
122  default:
123  return $this->$cmd();
124  break;
125  }
126  }

◆ getHtmlId()

ilPreviewGUI::getHtmlId ( )
private

Gets the HTML id for the preview.

Returns
string The HTML id to use for the preview.

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

References $node_id.

Referenced by getPreviewHTML(), and renderCommand().

322  {
323  return "preview_" . $this->node_id;
324  }
+ 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 225 of file class.ilPreviewGUI.php.

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

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

◆ getJSCall()

ilPreviewGUI::getJSCall (   $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 133 of file class.ilPreviewGUI.php.

References buildUrl(), and ilPreview\RENDER_STATUS_NONE.

134  {
135  $status = $this->preview->getRenderStatus();
136  $command = $status == ilPreview::RENDER_STATUS_NONE ? "renderPreview" : "";
137  $loading_text = self::jsonSafeString($this->lng->txt($status == ilPreview::RENDER_STATUS_NONE ? "preview_status_creating" : "preview_loading"));
138 
139  // build the url
140  $link = $this->buildUrl($command);
141  return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
142  }
const RENDER_STATUS_NONE
buildUrl($a_cmd="", $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 148 of file class.ilPreviewGUI.php.

References $index, $response, ilObject2\_lookupTitle(), ilJsonUtil\encode(), exit, getHtmlId(), ilPreview\RENDER_STATUS_FAILED, ilPreview\RENDER_STATUS_PENDING, and ilWACSignedPath\signFile().

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

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

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

Referenced by __construct(), and ilObjCategoryGUI\addHeaderAction().

352  {
353  if (self::$initialized) {
354  return;
355  }
356 
357  global $DIC;
358  // jquery
360 
361  // load qtip
363 
364  // needed scripts & styles
365  $DIC->ui()->mainTemplate()->addJavaScript("./libs/bower/bower_components/jquery-mousewheel/jquery.mousewheel.js");
366  $DIC->ui()->mainTemplate()->addJavaScript("./Services/Preview/js/ilPreview.js");
367 
368  // create loading template
369  $tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
370  $tmpl->setCurrentBlock("no_preview");
371  $tmpl->setVariable("TXT_NO_PREVIEW", "%%0%%");
372  $tmpl->parseCurrentBlock();
373 
374  $initialHtml = str_replace(array("\r\n", "\r"), "\n", $tmpl->get());
375  $lines = explode("\n", $initialHtml);
376  $new_lines = array();
377  foreach ($lines as $i => $line) {
378  if (!empty($line)) {
379  $new_lines[] = trim($line);
380  }
381  }
382  $initialHtml = implode($new_lines);
383 
384  // add default texts and values
385  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.texts.preview = \"" . self::jsonSafeString($DIC->language()->txt("preview")) . "\";");
386  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.texts.showPreview = \"" . self::jsonSafeString($DIC->language()->txt("preview_show"))
387  . "\";");
388  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.texts.close = \"" . ilUtil::prepareFormOutput($DIC->language()->txt("close")) . "\";");
389  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.previewSize = " . ilPreviewSettings::getImageSize() . ";");
390  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.initialHtml = " . json_encode($initialHtml) . ";");
391  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
392  $DIC->ui()->mainTemplate()->addOnLoadCode("il.Preview.init();");
393 
394  self::$initialized = true;
395  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static init()
Initializes the needed tooltip libraries.
global $DIC
Definition: goto.php:24
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:24
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ jsonSafeString()

static ilPreviewGUI::jsonSafeString (   $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 403 of file class.ilPreviewGUI.php.

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

◆ renderCommand()

ilPreviewGUI::renderCommand (   $tmpl,
  $a_cmd,
  $btn_topic,
  $loading_topic,
  $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_statusarray An array containing the statuses when the command should be visible.

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

References buildUrl(), and getHtmlId().

Referenced by getInlineHTML().

264  {
265  $preview_html_id = $this->getHtmlId();
266  $preview_status = $this->preview->getRenderStatus();
267  $loading_text = self::jsonSafeString($this->lng->txt($loading_topic));
268 
269  $link = $this->buildUrl($a_cmd . "Preview");
270  $script_args = "event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
271 
272  $action_class = "";
273  if (!is_array($a_display_status) || !in_array($preview_status, $a_display_status)) {
274  $action_class = "ilPreviewActionHidden";
275  }
276 
277  $tmpl->setCurrentBlock("preview_action");
278  $tmpl->setVariable("CLICK_ACTION", "il.Preview.$a_cmd($script_args);");
279  $tmpl->setVariable("ACTION_CLASS", "$action_class");
280  $tmpl->setVariable("ACTION_ID", "preview_{$a_cmd}_" . $preview_html_id);
281  $tmpl->setVariable("TXT_ACTION", $this->lng->txt($btn_topic));
282  $tmpl->parseCurrentBlock();
283  }
buildUrl($a_cmd="", $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 289 of file class.ilPreviewGUI.php.

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

290  {
291  // has read access?
292  if ($this->access_handler->checkAccess("read", "", $this->node_id)) {
293  // get the object
294  $obj = ilObjectFactory::getInstanceByObjId($this->obj_id);
295  $this->preview->create($obj);
296  }
297 
298  return $this->getPreviewHTML();
299  }
getPreviewHTML()
Gets the HTML that displays the preview.
static getInstanceByObjId($a_obj_id, $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

ilPreviewGUI::$access_handler = null
private

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

◆ $context

ilPreviewGUI::$context = null
private

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

◆ $ctrl

ilPreviewGUI::$ctrl = null
private

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

◆ $initialized

ilPreviewGUI::$initialized = false
staticprivate

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

◆ $lng

ilPreviewGUI::$lng = null
private

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

Referenced by __construct().

◆ $node_id

ilPreviewGUI::$node_id = null
private

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

Referenced by getHtmlId().

◆ $obj_id

ilPreviewGUI::$obj_id = null
private

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

◆ $preview

ilPreviewGUI::$preview = null
private

Definition at line 29 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: