ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilPreview Class Reference
+ Collaboration diagram for ilPreview:

Public Member Functions

 __construct ($a_obj_id, $a_type="")
 Creates a new ilPreview.
 exists ()
 Determines whether the preview exists or not.
 create ($a_obj, $a_force=false)
 Creates the preview.
 delete ()
 Deletes the preview.
 getImages ()
 Gets an array of preview images.
 save ()
 Saves the preview data to the database.
 getObjId ()
 Gets the id of the object the preview is for.
 getObjType ()
 Gets the type of the object the preview is for.
 getStoragePath ()
 Gets the path where the previews are stored relative to the web directory.
 getAbsoluteStoragePath ()
 Gets the absolute path where the previews are stored.
 getFilePathFormat ()
 Gets the absolute file path for preview images that contains a placeholder in the file name ('%02d') to be formatted with the preview number (use 'sprintf' for that).
 getRenderDate ()
 Gets the date when the preview was rendered.
 setRenderDate ($a_date)
 Sets the date when the preview was rendered.
 getRenderStatus ()
 Gets the status of the rendering process.
 setRenderStatus ($a_status)
 Sets the status of the rendering process.
 getStorage ()
 Gets the storage object for the preview.

Static Public Member Functions

static createPreview ($a_obj, $a_force=false)
 Creates the preview for the object with the specified id.
static deletePreview ($a_obj_id)
 Deletes the preview for the object with the specified id.
static copyPreviews ($a_src_id, $a_dest_id)
 Copies the preview images from one preview to a new preview object.
static hasPreview ($a_obj_id, $a_type="")
 Determines whether the object with the specified reference id has a preview.
static lookupRenderStatus ($a_obj_id)
 Gets the render status for the object with the specified id.

Data Fields

const RENDER_STATUS_NONE = "none"
const RENDER_STATUS_PENDING = "pending"
const RENDER_STATUS_CREATED = "created"
const RENDER_STATUS_FAILED = "failed"
const FILENAME_FORMAT = "preview_%02d.jpg"

Protected Member Functions

 doCreate ()
 Create entry in database.
 doRead ()
 Read data from database.
 doUpdate ()
 Update data in database.
 doDelete ()
 Delete data from database.

Private Member Functions

 init ()
 Initializes the preview object.

Private Attributes

 $obj_id = null
 $obj_type = null
 $storage = null
 $exists = false
 $render_date = false
 $render_status = self::RENDER_STATUS_NONE

Detailed Description

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

Constructor & Destructor Documentation

ilPreview::__construct (   $a_obj_id,
  $a_type = "" 
)

Creates a new ilPreview.

Parameters
int$a_obj_idThe object id.
int$a_typeThe type of the object.

Definition at line 69 of file class.ilPreview.php.

References init().

{
$this->obj_id = $a_obj_id;
$this->obj_type = $a_type;
$this->init();
}

+ Here is the call graph for this function:

Member Function Documentation

static ilPreview::copyPreviews (   $a_src_id,
  $a_dest_id 
)
static

Copies the preview images from one preview to a new preview object.

Parameters
int$a_src_idThe id of the object to copy from.
int$a_dest_idThe id of the object to copy to.

Definition at line 107 of file class.ilPreview.php.

References ilPreviewSettings\isPreviewEnabled(), and ilUtil\rCopy().

Referenced by ilObjFile\doCloneObject().

{
return;
// get source preview
$src = new ilPreview($a_src_id);
$status = $src->getRenderStatus();
// created? copy the previews
if ($status == self::RENDER_STATUS_CREATED)
{
// create destination preview and set it's properties
$dest = new ilPreview($a_dest_id);
$dest->setRenderDate($src->getRenderDate());
$dest->setRenderStatus($src->getRenderStatus());
// create path
$dest->getStorage()->create();
// copy previews
ilUtil::rCopy($src->getStoragePath(), $dest->getStoragePath());
// save copy
$dest->doCreate();
}
else
{
// all other status need no action
// self::RENDER_STATUS_FAILED
// self::RENDER_STATUS_NONE
// self::RENDER_STATUS_PENDING
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::create (   $a_obj,
  $a_force = false 
)

Creates the preview.

Parameters
ilObject$a_objThe object to create the preview for.
bool$a_forcetrue, to force the creation of the preview; false, to create the preview only if needed.
Returns
bool true, if the preview was created; otherwise, false.

Definition at line 193 of file class.ilPreview.php.

References getRenderDate(), ilRendererFactory\getRenderer(), getRenderStatus(), getStorage(), ilPreviewSettings\isPreviewEnabled(), and save().

{
return false;
// get renderer for preview
require_once("./Services/Preview/classes/class.ilRendererFactory.php");
$renderer = ilRendererFactory::getRenderer($this);
// no renderer available?
if ($renderer == null)
return false;
// exists, but still pending?
if ($this->getRenderStatus() == self::RENDER_STATUS_PENDING)
return false;
// not forced? check if update really needed
if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED && !$a_force)
{
// check last modified against last render date
if ($a_obj->getLastUpdateDate() <= $this->getRenderDate())
return false;
}
// re-create the directory to store the previews
$this->getStorage()->delete();
$this->getStorage()->create();
// let the renderer create the preview
$renderer->render($this, $a_obj, true);
// save to database
$this->save();
return true;
}

+ Here is the call graph for this function:

static ilPreview::createPreview (   $a_obj,
  $a_force = false 
)
static

Creates the preview for the object with the specified id.

Parameters
ilObject$a_objThe object to create the preview for.
bool$a_forcetrue, to force the creation of the preview; false, to create the preview only if needed.
Returns
bool true, if the preview was created; otherwise, false.

Definition at line 84 of file class.ilPreview.php.

References $preview.

{
$preview = new ilPreview($a_obj->getId(), $a_obj->getType());
return $preview->create($a_obj, $a_force);
}
ilPreview::delete ( )

Deletes the preview.

Definition at line 234 of file class.ilPreview.php.

References doDelete(), exists(), getStorage(), and RENDER_STATUS_NONE.

{
// does exist?
if ($this->exists())
{
// delete files and database entry
$this->getStorage()->delete();
$this->doDelete();
// reset values
$this->exists = false;
$this->render_date = false;
$this->render_status = self::RENDER_STATUS_NONE;
}
}

+ Here is the call graph for this function:

static ilPreview::deletePreview (   $a_obj_id)
static

Deletes the preview for the object with the specified id.

Parameters
int$a_obj_idThe id of the object to create the preview for.

Definition at line 95 of file class.ilPreview.php.

References $preview.

{
$preview = new ilPreview($a_obj_id);
$preview->delete();
}
ilPreview::doCreate ( )
protected

Create entry in database.

Definition at line 312 of file class.ilPreview.php.

References exists(), getObjId(), getRenderDate(), and getRenderStatus().

Referenced by save().

{
global $ilDB;
$ilDB->insert(
"preview_data",
array(
"obj_id" => array("integer", $this->getObjId()),
"render_date" => array("timestamp", $this->getRenderDate()),
"render_status" => array("text", $this->getRenderStatus())
)
);
$this->exists = true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::doDelete ( )
protected

Delete data from database.

Definition at line 367 of file class.ilPreview.php.

References getObjId().

Referenced by delete().

{
global $ilDB;
$ilDB->manipulateF(
"DELETE FROM preview_data WHERE obj_id=%s",
array("integer"),
array($this->getObjId()));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::doRead ( )
protected

Read data from database.

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

References exists(), getObjId(), setRenderDate(), and setRenderStatus().

Referenced by init().

{
global $ilDB;
$set = $ilDB->queryF(
"SELECT * FROM preview_data WHERE obj_id=%s",
array("integer"),
array($this->getObjId()));
while ($rec = $ilDB->fetchAssoc($set))
{
$this->setRenderDate($rec["render_date"]);
$this->setRenderStatus($rec["render_status"]);
$this->exists = true;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::doUpdate ( )
protected

Update data in database.

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

References getObjId(), getRenderDate(), and getRenderStatus().

Referenced by save().

{
global $ilDB;
$ilDB->update(
"preview_data",
array(
"render_date" => array("timestamp", $this->getRenderDate()),
"render_status" => array("text", $this->getRenderStatus())
),
array("obj_id" => array("integer", $this->getObjId()))
);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::exists ( )

Determines whether the preview exists or not.

Returns
bool true, if a preview exists for the object; otherwise, false.

Definition at line 181 of file class.ilPreview.php.

References $exists.

Referenced by delete(), doCreate(), doRead(), and save().

{
return $this->exists;
}

+ Here is the caller graph for this function:

ilPreview::getAbsoluteStoragePath ( )

Gets the absolute path where the previews are stored.

Returns
string The path where the previews are stored.

Definition at line 416 of file class.ilPreview.php.

References getStorage(), and ILIAS_ABSOLUTE_PATH.

Referenced by getFilePathFormat().

{
return ILIAS_ABSOLUTE_PATH . substr($this->getStorage()->getPath(), 1);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::getFilePathFormat ( )

Gets the absolute file path for preview images that contains a placeholder in the file name ('%02d') to be formatted with the preview number (use 'sprintf' for that).

Returns
string The format of the absolute file path.

Definition at line 427 of file class.ilPreview.php.

References $path, FILENAME_FORMAT, getAbsoluteStoragePath(), and ilUtil\removeTrailingPathSeparators().

+ Here is the call graph for this function:

ilPreview::getImages ( )

Gets an array of preview images.

Returns
array The preview images.

Definition at line 255 of file class.ilPreview.php.

References $file, $path, $size, ilUtil\getHtmlPath(), getRenderStatus(), and getStoragePath().

{
$images = array();
// status must be created
$path = $this->getStoragePath();
if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED)
{
// load files
if ($handle = @opendir($path))
{
while (false !== ($file = readdir($handle)))
{
$filepath = $path . "/" . $file;
if (!is_file($filepath))
continue;
if ($file != '.' && $file != '..' && strpos($file, "preview_") === 0)
{
$image = array();
$image["url"] = ilUtil::getHtmlPath($filepath);
// get image size
$size = @getimagesize($filepath);
if ($size !== false)
{
$image["width"] = $size[0];
$image["height"] = $size[1];
}
$images[$file] = $image;
}
}
closedir($handle);
// sort by key
ksort($images);
}
}
return $images;
}

+ Here is the call graph for this function:

ilPreview::getObjId ( )

Gets the id of the object the preview is for.

Returns
int The id of the object the preview is for.

Definition at line 382 of file class.ilPreview.php.

References $obj_id.

Referenced by doCreate(), doDelete(), doRead(), doUpdate(), and getObjType().

{
return $this->obj_id;
}

+ Here is the caller graph for this function:

ilPreview::getObjType ( )

Gets the type of the object the preview is for.

Returns
string The type of the object the preview is for.

Definition at line 392 of file class.ilPreview.php.

References $obj_type, ilObject\_lookupType(), and getObjId().

{
// not evaluated before or specified?
if (empty($this->obj_type))
$this->obj_type = ilObject::_lookupType($this->getObjId(), false);
}

+ Here is the call graph for this function:

ilPreview::getRenderDate ( )

Gets the date when the preview was rendered.

Returns
datetime The date when the preview was rendered.

Definition at line 438 of file class.ilPreview.php.

References $render_date.

Referenced by create(), doCreate(), and doUpdate().

{
}

+ Here is the caller graph for this function:

ilPreview::getRenderStatus ( )

Gets the status of the rendering process.

Returns
string The status of the rendering process.

Definition at line 458 of file class.ilPreview.php.

References $render_status.

Referenced by create(), doCreate(), doUpdate(), and getImages().

{
}

+ Here is the caller graph for this function:

ilPreview::getStorage ( )

Gets the storage object for the preview.

Returns
ilFSStoragePreview The storage object.

Definition at line 478 of file class.ilPreview.php.

References $storage.

Referenced by create(), delete(), getAbsoluteStoragePath(), and getStoragePath().

{
if ($this->storage == null)
$this->storage = new ilFSStoragePreview($this->obj_id);
}

+ Here is the caller graph for this function:

ilPreview::getStoragePath ( )

Gets the path where the previews are stored relative to the web directory.

Returns
string The path where the previews are stored.

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

References getStorage().

Referenced by getImages().

{
return $this->getStorage()->getPath();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilPreview::hasPreview (   $a_obj_id,
  $a_type = "" 
)
static

Determines whether the object with the specified reference id has a preview.

Parameters
int$a_obj_idThe id of the object to check.
string$a_typeThe type of the object to check.
Returns
bool true, if the object has a preview; otherwise, false.

Definition at line 149 of file class.ilPreview.php.

References $preview, ilRendererFactory\getRenderer(), and ilPreviewSettings\isPreviewEnabled().

Referenced by ilObjFileGUI\infoScreenForward(), and ilObjectListGUI\insertTitle().

{
return false;
$preview = new ilPreview($a_obj_id, $a_type);
if ($preview->exists())
return true;
// does not exist, enable on demand rendering if there's any renderer that supports our object
require_once("./Services/Preview/classes/class.ilRendererFactory.php");
return $renderer != null;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::init ( )
private

Initializes the preview object.

Definition at line 489 of file class.ilPreview.php.

References doRead().

Referenced by __construct().

{
// read entry
$this->doRead();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilPreview::lookupRenderStatus (   $a_obj_id)
static

Gets the render status for the object with the specified id.

Parameters
int$a_obj_idThe id of the object to get the status for.
Returns
string The status of the rendering process.

Definition at line 170 of file class.ilPreview.php.

References $preview.

Referenced by ilObjectListGUI\insertTitle().

{
$preview = new ilPreview($a_obj_id);
return $preview->getRenderStatus();
}

+ Here is the caller graph for this function:

ilPreview::save ( )

Saves the preview data to the database.

Definition at line 301 of file class.ilPreview.php.

References doCreate(), doUpdate(), and exists().

Referenced by create().

{
if ($this->exists)
$this->doUpdate();
else
$this->doCreate();
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilPreview::setRenderDate (   $a_date)

Sets the date when the preview was rendered.

Parameters
datetime$a_statusThe date when the preview was rendered.

Definition at line 448 of file class.ilPreview.php.

Referenced by doRead().

{
$this->render_date = $a_date;
}

+ Here is the caller graph for this function:

ilPreview::setRenderStatus (   $a_status)

Sets the status of the rendering process.

Parameters
string$a_statusThe status to set.

Definition at line 468 of file class.ilPreview.php.

Referenced by doRead().

{
$this->render_status = $a_status;
}

+ Here is the caller graph for this function:

Field Documentation

ilPreview::$exists = false
private

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

Referenced by exists().

ilPreview::$obj_id = null
private

Definition at line 31 of file class.ilPreview.php.

Referenced by getObjId().

ilPreview::$obj_type = null
private

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

Referenced by getObjType().

ilPreview::$render_date = false
private

Definition at line 55 of file class.ilPreview.php.

Referenced by getRenderDate().

ilPreview::$render_status = self::RENDER_STATUS_NONE
private

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

Referenced by getRenderStatus().

ilPreview::$storage = null
private

Definition at line 43 of file class.ilPreview.php.

Referenced by getStorage().

const ilPreview::FILENAME_FORMAT = "preview_%02d.jpg"

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

Referenced by getFilePathFormat().

const ilPreview::RENDER_STATUS_CREATED = "created"

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

Referenced by ilPreviewGUI\getInlineHTML(), and ilPreviewRenderer\render().

const ilPreview::RENDER_STATUS_FAILED = "failed"
const ilPreview::RENDER_STATUS_NONE = "none"
const ilPreview::RENDER_STATUS_PENDING = "pending"

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

Referenced by ilPreviewGUI\getPreviewHTML(), and ilPreviewRenderer\render().


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