ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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...
 

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 initPreview ()
 Initializes the preview and loads the needed javascripts and styles. More...
 
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 37 of file class.ilPreviewGUI.php.

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

38  {
39  global $ilCtrl, $lng, $ilAccess;
40 
41  // if we are the base class, get the id's from the query string
42  if (strtolower($_GET["baseClass"]) == "ilpreviewgui")
43  {
44  $this->node_id = (int)$_GET["node_id"];
45  $this->context = (int)$_GET["context"];
46  $a_obj_id = (int)$_GET['obj_id'];
47  }
48  else
49  {
50  $this->node_id = $a_node_id;
51  $this->context = $a_context;
52  }
53 
54  // assign values
55  $this->ctrl =& $ilCtrl;
56  $this->lng =& $lng;
57 
58  // access handler NOT provided?
59  if ($a_access_handler == null)
60  {
61  if ($this->context == self::CONTEXT_WORKSPACE)
62  {
63  include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
64  $a_access_handler = new ilWorkspaceAccessHandler();
65  }
66  else
67  {
68  $a_access_handler = $ilAccess;
69  }
70  }
71  $this->access_handler = $a_access_handler;
72 
73  // object id NOT provided?
74  if ($a_obj_id == null)
75  {
76  if ($this->context == self::CONTEXT_WORKSPACE)
77  $a_obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
78  else
79  $a_obj_id = ilObject::_lookupObjId($this->node_id);
80  }
81  $this->obj_id = $a_obj_id;
82 
83  // create preview object
84  $this->preview = new ilPreview($this->obj_id);
85 
86  // if the call is NOT async initialize our stuff
87  if (!$ilCtrl->isAsynch())
89  }
$_GET["client_id"]
Access handler for personal workspace.
global $ilCtrl
Definition: ilias.php:18
static _lookupObjId($a_id)
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 314 of file class.ilPreviewGUI.php.

Referenced by getJSCall(), and renderCommand().

315  {
316  $link = "ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}&obj_id={$this->obj_id}";
317 
318  if ($a_async)
319  $link .= "&cmdMode=asynch";
320 
321  if (!empty($a_cmd))
322  $link .= "&cmd=$a_cmd";
323 
324  return $link;
325  }
+ 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 286 of file class.ilPreviewGUI.php.

References getPreviewHTML().

287  {
288  // has read access?
289  if ($this->access_handler->checkAccess("write", "", $this->node_id))
290  {
291  // get the preview
292  require_once("./Services/Preview/classes/class.ilPreview.php");
293  $this->preview->delete();
294  }
295 
296  return $this->getPreviewHTML();
297  }
getPreviewHTML()
Gets the HTML that displays the preview.
+ Here is the call graph for this function:

◆ executeCommand()

& ilPreviewGUI::executeCommand ( )

execute command

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

References $cmd.

95  {
96  $cmd = $this->ctrl->getCmd("getPreviewHTML");
97  $next_class = $this->ctrl->getNextClass($this);
98 
99  switch($next_class)
100  {
101  default:
102  return $this->$cmd();
103  break;
104  }
105  }
$cmd
Definition: sahs_server.php:35

◆ getHtmlId()

ilPreviewGUI::getHtmlId ( )
private

Gets the HTML id for the preview.

Returns
string The HTML id to use for the preview.

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

References $node_id.

Referenced by getPreviewHTML(), and renderCommand().

304  {
305  return "preview_" . $this->node_id;
306  }
+ 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 206 of file class.ilPreviewGUI.php.

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

207  {
208  $tmpl = new ilTemplate("tpl.preview_inline.html", true, true, "Services/Preview");
209  $tmpl->setVariable("PREVIEW", $this->getPreviewHTML());
210 
211  // rendering allowed?
212  if ($this->access_handler->checkAccess("read", "", $this->node_id))
213  {
214  $this->renderCommand(
215  $tmpl,
216  "render",
217  "preview_create",
218  "preview_status_creating",
220  }
221 
222  // delete allowed?
223  if ($this->access_handler->checkAccess("write", "", $this->node_id))
224  {
225  $this->renderCommand(
226  $tmpl,
227  "delete",
228  "preview_delete",
229  "preview_status_deleting",
231  }
232 
233  return $tmpl->get();
234  }
const RENDER_STATUS_FAILED
const RENDER_STATUS_NONE
getPreviewHTML()
Gets the HTML that displays the preview.
special template class to simplify handling of ITX/PEAR
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 112 of file class.ilPreviewGUI.php.

References buildUrl(), and ilPreview\RENDER_STATUS_NONE.

113  {
114  $status = $this->preview->getRenderStatus();
115  $command = $status == ilPreview::RENDER_STATUS_NONE ? "renderPreview" : "";
116  $loading_text = self::jsonSafeString($this->lng->txt($status == ilPreview::RENDER_STATUS_NONE ? "preview_status_creating" : "preview_loading"));
117 
118  // build the url
119  $link = $this->buildUrl($command);
120  return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
121  }
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 127 of file class.ilPreviewGUI.php.

References ilJsonUtil\encode(), exit, getHtmlId(), ilPreview\RENDER_STATUS_FAILED, and ilPreview\RENDER_STATUS_PENDING.

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

128  {
129  // load the template
130  $tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
131  $tmpl->setVariable("PREVIEW_ID", $this->getHtmlId());
132 
133  // check for read access and get object id
134  $preview_status = $this->preview->getRenderStatus();
135 
136  // has read access?
137  if ($this->access_handler->checkAccess("read", "", $this->node_id))
138  {
139  // preview images available?
140  $images = $this->preview->getImages();
141  if (count($images) > 0)
142  {
143  foreach ($images as $image)
144  {
145  $tmpl->setCurrentBlock("preview_item");
146  $tmpl->setVariable("IMG_URL", $image["url"]);
147  $tmpl->setVariable("WIDTH", $image["width"]);
148  $tmpl->setVariable("HEIGHT", $image["height"]);
149  $tmpl->parseCurrentBlock();
150  }
151  }
152  else
153  {
154  // set text depending on the status
155  $tmpl->setCurrentBlock("no_preview");
156  switch ($preview_status)
157  {
159  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_pending"));
160  break;
161 
163  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_failed"));
164  break;
165 
166  default:
167  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_missing"));
168  break;
169  }
170  $tmpl->parseCurrentBlock();
171  }
172  }
173  else
174  {
175  // display error message
176  $tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("no_access_item"));
177  }
178 
179  // output
180  if ($this->ctrl->isAsynch())
181  {
182  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
183 
184  $response = new stdClass();
185  $response->html = $tmpl->get();
186  $response->status = $preview_status;
187 
188  // send response object (don't use 'application/json' as IE wants to download it!)
189  header('Vary: Accept');
190  header('Content-type: text/plain');
191  echo ilJsonUtil::encode($response);
192 
193  // no further processing!
194  exit;
195  }
196  else
197  {
198  return $tmpl->get();
199  }
200  }
exit
Definition: login.php:54
const RENDER_STATUS_FAILED
const RENDER_STATUS_PENDING
static encode($mixed, $suppress_native=false)
special template class to simplify handling of ITX/PEAR
getHtmlId()
Gets the HTML id for the preview.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ initPreview()

static ilPreviewGUI::initPreview ( )
staticprivate

Initializes the preview and loads the needed javascripts and styles.

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

References $ilCtrl, $lng, $tpl, ilJsonUtil\encode(), ilPreviewSettings\getImageSize(), ilUtil\getStyleSheetLocation(), iljQueryUtil\initjQuery(), ilTooltipGUI\initLibrary(), and ilUtil\prepareFormOutput().

Referenced by __construct().

331  {
332  if (self::$initialized)
333  return;
334 
335  global $tpl, $lng, $ilCtrl;
336 
337 
338  // jquery
339  include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
341 
342  // load qtip
343  include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
345 
346  // needed scripts & styles
347  $tpl->addJavaScript("./Services/Preview/js/jquery.mousewheel.js");
348  $tpl->addJavaScript("./Services/Preview/js/ilPreview.js");
349  $tpl->addCss(ilUtil::getStyleSheetLocation("filesystem", "preview.css", "Services/Preview"));
350 
351  // create loading template
352  $tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
353  $tmpl->setCurrentBlock("no_preview");
354  $tmpl->setVariable("TXT_NO_PREVIEW", "%%0%%");
355  $tmpl->parseCurrentBlock();
356 
357  $initialHtml = str_replace(array("\r\n", "\r"), "\n", $tmpl->get());
358  $lines = explode("\n", $initialHtml);
359  $new_lines = array();
360  foreach ($lines as $i => $line)
361  {
362  if(!empty($line))
363  $new_lines[] = trim($line);
364  }
365  $initialHtml = implode($new_lines);
366 
367  // add default texts and values
368  include_once("./Services/JSON/classes/class.ilJsonUtil.php");
369  $tpl->addOnLoadCode("il.Preview.texts.preview = \"" . self::jsonSafeString($lng->txt("preview")) . "\";");
370  $tpl->addOnLoadCode("il.Preview.texts.showPreview = \"" . self::jsonSafeString($lng->txt("preview_show")) . "\";");
371  $tpl->addOnLoadCode("il.Preview.texts.close = \"" . ilUtil::prepareFormOutput($lng->txt("close")) . "\";");
372  $tpl->addOnLoadCode("il.Preview.previewSize = " . ilPreviewSettings::getImageSize() . ";");
373  $tpl->addOnLoadCode("il.Preview.initialHtml = " . ilJsonUtil::encode($initialHtml) . ";");
374  $tpl->addOnLoadCode("il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
375  $tpl->addOnLoadCode("il.Preview.init();");
376 
377  self::$initialized = true;
378  }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
static getStyleSheetLocation($mode="output", $a_css_name="", $a_css_location="")
get full style sheet file name (path inclusive) of current user
global $tpl
Definition: ilias.php:8
global $ilCtrl
Definition: ilias.php:18
static initLibrary()
Initializes the needed tooltip libraries.
static encode($mixed, $suppress_native=false)
special template class to simplify handling of ITX/PEAR
static getImageSize()
Gets the size of the preview images in pixels.
static initjQuery($a_tpl=null)
Init jQuery.
+ 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
The JSON safe text.

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

387  {
388  if (!is_string($text))
389  return $text;
390 
391  $text = htmlentities($text, ENT_COMPAT | ENT_HTML401, "UTF-8");
392  $text = str_replace("'", "'", $text);
393  return $text;
394  }

◆ 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 244 of file class.ilPreviewGUI.php.

References buildUrl(), and getHtmlId().

Referenced by getInlineHTML().

245  {
246  $preview_html_id = $this->getHtmlId();
247  $preview_status = $this->preview->getRenderStatus();
248  $loading_text = self::jsonSafeString($this->lng->txt($loading_topic));
249 
250  $link = $this->buildUrl($a_cmd . "Preview");
251  $script_args = "event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
252 
253  $action_class = "";
254  if (!is_array($a_display_status) || !in_array($preview_status, $a_display_status))
255  $action_class = "ilPreviewActionHidden";
256 
257  $tmpl->setCurrentBlock("preview_action");
258  $tmpl->setVariable("CLICK_ACTION", "il.Preview.$a_cmd($script_args);");
259  $tmpl->setVariable("ACTION_CLASS", "$action_class");
260  $tmpl->setVariable("ACTION_ID", "preview_{$a_cmd}_" . $this->node_id);
261  $tmpl->setVariable("TXT_ACTION", $this->lng->txt($btn_topic));
262  $tmpl->parseCurrentBlock();
263  }
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 269 of file class.ilPreviewGUI.php.

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

270  {
271  // has read access?
272  if ($this->access_handler->checkAccess("read", "", $this->node_id))
273  {
274  // get the object
275  $obj = ilObjectFactory::getInstanceByObjId($this->obj_id);
276  $this->preview->create($obj);
277  }
278 
279  return $this->getPreviewHTML();
280  }
getPreviewHTML()
Gets the HTML that displays the preview.
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 20 of file class.ilPreviewGUI.php.

◆ $context

ilPreviewGUI::$context = null
private

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

◆ $ctrl

ilPreviewGUI::$ctrl = null
private

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

◆ $initialized

ilPreviewGUI::$initialized = false
staticprivate

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

◆ $lng

ilPreviewGUI::$lng = null
private

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

Referenced by __construct(), and initPreview().

◆ $node_id

ilPreviewGUI::$node_id = null
private

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

Referenced by getHtmlId().

◆ $obj_id

ilPreviewGUI::$obj_id = null
private

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

◆ $preview

ilPreviewGUI::$preview = null
private

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