ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups 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.
executeCommand ()
 execute command
 getJSCall ($a_html_id)
 Gets the JavaScript code to show the preview.
 getPreviewHTML ()
 Gets the HTML that displays the preview.
 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.

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.
 getHtmlId ()
 Gets the HTML id for the preview.
 buildUrl ($a_cmd="", $a_async=true)
 Builds the URL to call the preview GUI.

Static Private Member Functions

static initPreview ()
 Initializes the preview and loads the needed javascripts and styles.
static jsonSafeString ($text)
 Makes the specified string safe for JSON.

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

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().

{
global $ilCtrl, $lng, $ilAccess;
// if we are the base class, get the id's from the query string
if (strtolower($_GET["baseClass"]) == "ilpreviewgui")
{
$this->node_id = (int)$_GET["node_id"];
$this->context = (int)$_GET["context"];
}
else
{
$this->node_id = $a_node_id;
$this->context = $a_context;
}
// assign values
$this->ctrl =& $ilCtrl;
$this->lng =& $lng;
// access handler NOT provided?
if ($a_access_handler == null)
{
if ($this->context == self::CONTEXT_WORKSPACE)
{
include_once("./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php");
$a_access_handler = new ilWorkspaceAccessHandler();
}
else
{
$a_access_handler = $ilAccess;
}
}
$this->access_handler = $a_access_handler;
// object id NOT provided?
if ($a_obj_id == null)
{
if ($this->context == self::CONTEXT_WORKSPACE)
$a_obj_id = $this->access_handler->getTree()->lookupObjectId($this->node_id);
else
$a_obj_id = ilObject::_lookupObjId($this->node_id);
}
$this->obj_id = $a_obj_id;
// create preview object
$this->preview = new ilPreview($this->obj_id);
// if the call is NOT async initialize our stuff
if (!$ilCtrl->isAsynch())
}

+ Here is the call graph for this function:

Member Function Documentation

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

Referenced by getJSCall(), and renderCommand().

{
$link = "ilias.php?baseClass=ilPreviewGUI&node_id={$this->node_id}&context={$this->context}";
if ($a_async)
$link .= "&cmdMode=asynch";
if (!empty($a_cmd))
$link .= "&cmd=$a_cmd";
return $link;
}

+ Here is the caller graph for this function:

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

References getPreviewHTML().

{
// has read access?
if ($this->access_handler->checkAccess("write", "", $this->node_id))
{
// get the preview
require_once("./Services/Preview/classes/class.ilPreview.php");
$this->preview->delete();
}
return $this->getPreviewHTML();
}

+ Here is the call graph for this function:

& ilPreviewGUI::executeCommand ( )

execute command

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

References $cmd.

{
$cmd = $this->ctrl->getCmd("getPreviewHTML");
$next_class = $this->ctrl->getNextClass($this);
switch($next_class)
{
default:
return $this->$cmd();
break;
}
}
ilPreviewGUI::getHtmlId ( )
private

Gets the HTML id for the preview.

Returns
string The HTML id to use for the preview.

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

References $node_id.

Referenced by getPreviewHTML(), and renderCommand().

{
return "preview_" . $this->node_id;
}

+ Here is the caller graph for this function:

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

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

{
$tmpl = new ilTemplate("tpl.preview_inline.html", true, true, "Services/Preview");
$tmpl->setVariable("PREVIEW", $this->getPreviewHTML());
// rendering allowed?
if ($this->access_handler->checkAccess("read", "", $this->node_id))
{
$this->renderCommand(
$tmpl,
"render",
"preview_create",
"preview_status_creating",
}
// delete allowed?
if ($this->access_handler->checkAccess("write", "", $this->node_id))
{
$this->renderCommand(
$tmpl,
"delete",
"preview_delete",
"preview_status_deleting",
}
return $tmpl->get();
}

+ Here is the call graph for this function:

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

References buildUrl(), jsonSafeString(), and ilPreview\RENDER_STATUS_NONE.

{
$status = $this->preview->getRenderStatus();
$command = $status == ilPreview::RENDER_STATUS_NONE ? "renderPreview" : "";
$loading_text = self::jsonSafeString($this->lng->txt($status == ilPreview::RENDER_STATUS_NONE ? "preview_status_creating" : "preview_loading"));
// build the url
$link = $this->buildUrl($command);
return "il.Preview.toggle(event, { id: '{$this->node_id}', htmlId: '{$a_html_id}', url: '$link', status: '$status', loadingText: '$loading_text' });";
}

+ Here is the call graph for this function:

ilPreviewGUI::getPreviewHTML ( )

Gets the HTML that displays the preview.

Returns
string The HTML that displays the preview.

Definition at line 126 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().

{
// load the template
$tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
$tmpl->setVariable("PREVIEW_ID", $this->getHtmlId());
// check for read access and get object id
$preview_status = $this->preview->getRenderStatus();
// has read access?
if ($this->access_handler->checkAccess("read", "", $this->node_id))
{
// preview images available?
$images = $this->preview->getImages();
if (count($images) > 0)
{
foreach ($images as $image)
{
$tmpl->setCurrentBlock("preview_item");
$tmpl->setVariable("IMG_URL", $image["url"]);
$tmpl->setVariable("WIDTH", $image["width"]);
$tmpl->setVariable("HEIGHT", $image["height"]);
$tmpl->parseCurrentBlock();
}
}
else
{
// set text depending on the status
$tmpl->setCurrentBlock("no_preview");
switch ($preview_status)
{
$tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_pending"));
break;
$tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_failed"));
break;
default:
$tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("preview_status_missing"));
break;
}
$tmpl->parseCurrentBlock();
}
}
else
{
// display error message
$tmpl->setVariable("TXT_NO_PREVIEW", $this->lng->txt("no_access_item"));
}
// output
if ($this->ctrl->isAsynch())
{
include_once("./Services/JSON/classes/class.ilJsonUtil.php");
$response = new stdClass();
$response->html = $tmpl->get();
$response->status = $preview_status;
// send response object (don't use 'application/json' as IE wants to download it!)
header('Vary: Accept');
header('Content-type: text/plain');
echo ilJsonUtil::encode($response);
// no further processing!
}
else
{
return $tmpl->get();
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilPreviewGUI::initPreview ( )
staticprivate

Initializes the preview and loads the needed javascripts and styles.

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

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

Referenced by __construct().

{
if (self::$initialized)
return;
global $tpl, $lng, $ilCtrl;
// jquery
include_once("./Services/jQuery/classes/class.iljQueryUtil.php");
// load qtip
include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
// needed scripts & styles
$tpl->addJavaScript("./Services/Preview/js/jquery.mousewheel.js");
$tpl->addJavaScript("./Services/Preview/js/ilPreview.js");
$tpl->addCss(ilUtil::getStyleSheetLocation("filesystem", "preview.css", "Services/Preview"));
// create loading template
$tmpl = new ilTemplate("tpl.preview.html", true, true, "Services/Preview");
$tmpl->setCurrentBlock("no_preview");
$tmpl->setVariable("TXT_NO_PREVIEW", "%%0%%");
$tmpl->parseCurrentBlock();
$initialHtml = str_replace(array("\r\n", "\r"), "\n", $tmpl->get());
$lines = explode("\n", $initialHtml);
$new_lines = array();
foreach ($lines as $i => $line)
{
if(!empty($line))
$new_lines[] = trim($line);
}
$initialHtml = implode($new_lines);
// add default texts and values
include_once("./Services/JSON/classes/class.ilJsonUtil.php");
$tpl->addOnLoadCode("il.Preview.texts.preview = \"" . self::jsonSafeString($lng->txt("preview")) . "\";");
$tpl->addOnLoadCode("il.Preview.texts.showPreview = \"" . self::jsonSafeString($lng->txt("preview_show")) . "\";");
$tpl->addOnLoadCode("il.Preview.texts.close = \"" . self::jsonSafeString($lng->txt("close")) . "\";");
$tpl->addOnLoadCode("il.Preview.previewSize = " . ilPreviewSettings::getImageSize() . ";");
$tpl->addOnLoadCode("il.Preview.initialHtml = " . ilJsonUtil::encode($initialHtml) . ";");
$tpl->addOnLoadCode("il.Preview.highlightClass = \"ilContainerListItemOuterHighlight\";");
$tpl->addOnLoadCode("il.Preview.init();");
self::$initialized = true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

Referenced by getJSCall(), and renderCommand().

{
if (!is_string($text))
return $text;
$text = htmlentities($text, ENT_COMPAT | ENT_HTML401, "UTF-8");
$text = str_replace("'", "'", $text);
return $text;
}

+ Here is the caller graph for this function:

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

References buildUrl(), getHtmlId(), and jsonSafeString().

Referenced by getInlineHTML().

{
$preview_html_id = $this->getHtmlId();
$preview_status = $this->preview->getRenderStatus();
$loading_text = self::jsonSafeString($this->lng->txt($loading_topic));
$link = $this->buildUrl($a_cmd . "Preview");
$script_args = "event, { id: '{$this->node_id}', htmlId: '$preview_html_id', url: '$link', loadingText: '$loading_text' }";
$action_class = "";
if (!is_array($a_display_status) || !in_array($preview_status, $a_display_status))
$action_class = "ilPreviewActionHidden";
$tmpl->setCurrentBlock("preview_action");
$tmpl->setVariable("CLICK_ACTION", "il.Preview.$a_cmd($script_args);");
$tmpl->setVariable("ACTION_CLASS", "$action_class");
$tmpl->setVariable("ACTION_ID", "preview_{$a_cmd}_" . $this->node_id);
$tmpl->setVariable("TXT_ACTION", $this->lng->txt($btn_topic));
$tmpl->parseCurrentBlock();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

{
// has read access?
if ($this->access_handler->checkAccess("read", "", $this->node_id))
{
// get the object
$obj = ilObjectFactory::getInstanceByObjId($this->obj_id);
$this->preview->create($obj);
}
return $this->getPreviewHTML();
}

+ Here is the call graph for this function:

Field Documentation

ilPreviewGUI::$access_handler = null
private

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

ilPreviewGUI::$context = null
private

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

ilPreviewGUI::$ctrl = null
private

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

ilPreviewGUI::$initialized = false
staticprivate

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

ilPreviewGUI::$lng = null
private

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

Referenced by __construct(), and initPreview().

ilPreviewGUI::$node_id = null
private

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

Referenced by getHtmlId().

ilPreviewGUI::$obj_id = null
private

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

ilPreviewGUI::$preview = null
private

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

const ilPreviewGUI::CONTEXT_REPOSITORY = 1

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

Referenced by ilObjFileGUI\infoScreenForward().

const ilPreviewGUI::CONTEXT_WORKSPACE = 2

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

Referenced by ilObjFileGUI\infoScreenForward().


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