ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilPreview Class Reference
+ Collaboration diagram for ilPreview:

Public Member Functions

 __construct ($a_obj_id, $a_type="")
 Creates a new ilPreview. More...
 
 exists ()
 Determines whether the preview exists or not. More...
 
 create ($a_obj, $a_force=false)
 Creates the preview. More...
 
 delete ()
 Deletes the preview. More...
 
 getImages ()
 Gets an array of preview images. More...
 
 save ()
 Saves the preview data to the database. More...
 
 getObjId ()
 Gets the id of the object the preview is for. More...
 
 getObjType ()
 Gets the type of the object the preview is for. More...
 
 getStoragePath ()
 Gets the path where the previews are stored relative to the web directory. More...
 
 getAbsoluteStoragePath ()
 Gets the absolute path where the previews are stored. More...
 
 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). More...
 
 getRenderDate ()
 Gets the date when the preview was rendered. More...
 
 setRenderDate ($a_date)
 Sets the date when the preview was rendered. More...
 
 getRenderStatus ()
 Gets the status of the rendering process. More...
 
 setRenderStatus ($a_status)
 Sets the status of the rendering process. More...
 
 getStorage ()
 Gets the storage object for the preview. More...
 

Static Public Member Functions

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

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. More...
 
 doRead ()
 Read data from database. More...
 
 doUpdate ()
 Update data in database. More...
 
 doDelete ()
 Delete data from database. More...
 

Private Member Functions

 init ()
 Initializes the preview object. More...
 

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

◆ __construct()

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 $a_type, and init().

70  {
71  $this->obj_id = $a_obj_id;
72  $this->obj_type = $a_type;
73 
74  $this->init();
75  }
init()
Initializes the preview object.
$a_type
Definition: workflow.php:93
+ Here is the call graph for this function:

Member Function Documentation

◆ copyPreviews()

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

108  {
110  return;
111 
112  // get source preview
113  $src = new ilPreview($a_src_id);
114  $status = $src->getRenderStatus();
115 
116  // created? copy the previews
117  if ($status == self::RENDER_STATUS_CREATED)
118  {
119  // create destination preview and set it's properties
120  $dest = new ilPreview($a_dest_id);
121  $dest->setRenderDate($src->getRenderDate());
122  $dest->setRenderStatus($src->getRenderStatus());
123 
124  // create path
125  $dest->getStorage()->create();
126 
127  // copy previews
128  ilUtil::rCopy($src->getStoragePath(), $dest->getStoragePath());
129 
130  // save copy
131  $dest->doCreate();
132  }
133  else
134  {
135  // all other status need no action
136  // self::RENDER_STATUS_FAILED
137  // self::RENDER_STATUS_NONE
138  // self::RENDER_STATUS_PENDING
139  }
140  }
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.
static isPreviewEnabled()
Gets whether the preview functionality is enabled.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ create()

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

194  {
196  return false;
197 
198  // get renderer for preview
199  require_once("./Services/Preview/classes/class.ilRendererFactory.php");
200  $renderer = ilRendererFactory::getRenderer($this);
201 
202  // no renderer available?
203  if ($renderer == null)
204  {
205  // bugfix mantis 23293
206  $this->delete();
207  return false;
208  }
209 
210  // exists, but still pending?
211  if ($this->getRenderStatus() == self::RENDER_STATUS_PENDING)
212  return false;
213 
214  // not forced? check if update really needed
215  if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED && !$a_force)
216  {
217  // check last modified against last render date
218  if ($a_obj->getLastUpdateDate() <= $this->getRenderDate())
219  return false;
220  }
221 
222  // re-create the directory to store the previews
223  $this->getStorage()->delete();
224  $this->getStorage()->create();
225 
226  // let the renderer create the preview
227  $renderer->render($this, $a_obj, true);
228 
229  // save to database
230  $this->save();
231 
232  return true;
233  }
static getRenderer($preview)
Gets the renderer that is able to create a preview for the specified preview object.
getRenderStatus()
Gets the status of the rendering process.
static isPreviewEnabled()
Gets whether the preview functionality is enabled.
getRenderDate()
Gets the date when the preview was rendered.
save()
Saves the preview data to the database.
getStorage()
Gets the storage object for the preview.
+ Here is the call graph for this function:

◆ createPreview()

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.

Referenced by ilObjFile\createPreview(), and ilDclFileuploadRecordRepresentation\getHTML().

85  {
86  $preview = new ilPreview($a_obj->getId(), $a_obj->getType());
87  return $preview->create($a_obj, $a_force);
88  }
$preview
+ Here is the caller graph for this function:

◆ delete()

ilPreview::delete ( )

Deletes the preview.

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

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

239  {
240  // does exist?
241  if ($this->exists())
242  {
243  // delete files and database entry
244  $this->getStorage()->delete();
245  $this->doDelete();
246 
247  // reset values
248  $this->exists = false;
249  $this->render_date = false;
250  $this->render_status = self::RENDER_STATUS_NONE;
251  }
252  }
exists()
Determines whether the preview exists or not.
doDelete()
Delete data from database.
getStorage()
Gets the storage object for the preview.
+ Here is the call graph for this function:

◆ deletePreview()

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.

Referenced by ilObjFile\deletePreview().

96  {
97  $preview = new ilPreview($a_obj_id);
98  $preview->delete();
99  }
$preview
+ Here is the caller graph for this function:

◆ doCreate()

ilPreview::doCreate ( )
protected

Create entry in database.

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

References $ilDB, array, exists(), getObjId(), getRenderDate(), and getRenderStatus().

Referenced by save().

317  {
318  global $ilDB;
319 
320  $ilDB->insert(
321  "preview_data",
322  array(
323  "obj_id" => array("integer", $this->getObjId()),
324  "render_date" => array("timestamp", $this->getRenderDate()),
325  "render_status" => array("text", $this->getRenderStatus())
326  )
327  );
328  $this->exists = true;
329  }
exists()
Determines whether the preview exists or not.
getRenderStatus()
Gets the status of the rendering process.
Create styles array
The data for the language used.
getObjId()
Gets the id of the object the preview is for.
getRenderDate()
Gets the date when the preview was rendered.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doDelete()

ilPreview::doDelete ( )
protected

Delete data from database.

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

References $ilDB, array, and getObjId().

Referenced by delete().

372  {
373  global $ilDB;
374 
375  $ilDB->manipulateF(
376  "DELETE FROM preview_data WHERE obj_id=%s",
377  array("integer"),
378  array($this->getObjId()));
379  }
Create styles array
The data for the language used.
getObjId()
Gets the id of the object the preview is for.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doRead()

ilPreview::doRead ( )
protected

Read data from database.

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

References $ilDB, array, exists(), getObjId(), setRenderDate(), and setRenderStatus().

Referenced by init().

335  {
336  global $ilDB;
337 
338  $set = $ilDB->queryF(
339  "SELECT * FROM preview_data WHERE obj_id=%s",
340  array("integer"),
341  array($this->getObjId()));
342 
343  while ($rec = $ilDB->fetchAssoc($set))
344  {
345  $this->setRenderDate($rec["render_date"]);
346  $this->setRenderStatus($rec["render_status"]);
347  $this->exists = true;
348  }
349  }
exists()
Determines whether the preview exists or not.
Create styles array
The data for the language used.
getObjId()
Gets the id of the object the preview is for.
setRenderStatus($a_status)
Sets the status of the rendering process.
global $ilDB
setRenderDate($a_date)
Sets the date when the preview was rendered.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ doUpdate()

ilPreview::doUpdate ( )
protected

Update data in database.

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

References $ilDB, array, getObjId(), getRenderDate(), and getRenderStatus().

Referenced by save().

355  {
356  global $ilDB;
357 
358  $ilDB->update(
359  "preview_data",
360  array(
361  "render_date" => array("timestamp", $this->getRenderDate()),
362  "render_status" => array("text", $this->getRenderStatus())
363  ),
364  array("obj_id" => array("integer", $this->getObjId()))
365  );
366  }
getRenderStatus()
Gets the status of the rendering process.
Create styles array
The data for the language used.
getObjId()
Gets the id of the object the preview is for.
getRenderDate()
Gets the date when the preview was rendered.
global $ilDB
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ exists()

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

182  {
183  return $this->exists;
184  }
+ Here is the caller graph for this function:

◆ getAbsoluteStoragePath()

ilPreview::getAbsoluteStoragePath ( )

Gets the absolute path where the previews are stored.

Returns
string The path where the previews are stored.

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

References getStorage().

Referenced by getFilePathFormat().

421  {
422  return ILIAS_ABSOLUTE_PATH . substr($this->getStorage()->getPath(), 1);
423  }
getStorage()
Gets the storage object for the preview.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFilePathFormat()

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 431 of file class.ilPreview.php.

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

432  {
434  return $path . "/" . self::FILENAME_FORMAT;
435  }
$path
Definition: aliased.php:25
getAbsoluteStoragePath()
Gets the absolute path where the previews are stored.
static removeTrailingPathSeparators($path)
+ Here is the call graph for this function:

◆ getImages()

ilPreview::getImages ( )

Gets an array of preview images.

Returns
array The preview images.

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

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

260  {
261  $images = array();
262 
263  // status must be created
264  $path = $this->getStoragePath();
265  if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED)
266  {
267  // load files
268  if ($handle = @opendir($path))
269  {
270  while (false !== ($file = readdir($handle)))
271  {
272  $filepath = $path . "/" . $file;
273  if (!is_file($filepath))
274  continue;
275 
276  if ($file != '.' && $file != '..' && strpos($file, "preview_") === 0)
277  {
278  $image = array();
279  $image["url"] = ilUtil::getHtmlPath($filepath);
280 
281  // get image size
282  $size = @getimagesize($filepath);
283  if ($size !== false)
284  {
285  $image["width"] = $size[0];
286  $image["height"] = $size[1];
287  }
288 
289  $images[$file] = $image;
290  }
291  }
292  closedir($handle);
293 
294  // sort by key
295  ksort($images);
296  }
297  }
298 
299  return $images;
300  }
$path
Definition: aliased.php:25
$size
Definition: RandomTest.php:79
getRenderStatus()
Gets the status of the rendering process.
static getHtmlPath($relative_path)
get url of path
Create styles array
The data for the language used.
getStoragePath()
Gets the path where the previews are stored relative to the web directory.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
+ Here is the call graph for this function:

◆ getObjId()

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 386 of file class.ilPreview.php.

References $obj_id.

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

387  {
388  return $this->obj_id;
389  }
+ Here is the caller graph for this function:

◆ getObjType()

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 396 of file class.ilPreview.php.

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

397  {
398  // not evaluated before or specified?
399  if (empty($this->obj_type))
400  $this->obj_type = ilObject::_lookupType($this->getObjId(), false);
401 
402  return $this->obj_type;
403  }
static _lookupType($a_id, $a_reference=false)
lookup object type
getObjId()
Gets the id of the object the preview is for.
+ Here is the call graph for this function:

◆ getRenderDate()

ilPreview::getRenderDate ( )

Gets the date when the preview was rendered.

Returns
datetime The date when the preview was rendered.

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

References $render_date.

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

443  {
444  return $this->render_date;
445  }
+ Here is the caller graph for this function:

◆ getRenderStatus()

ilPreview::getRenderStatus ( )

Gets the status of the rendering process.

Returns
string The status of the rendering process.

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

References $render_status.

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

463  {
464  return $this->render_status;
465  }
+ Here is the caller graph for this function:

◆ getStorage()

ilPreview::getStorage ( )

Gets the storage object for the preview.

Returns
ilFSStoragePreview The storage object.

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

References $storage.

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

483  {
484  if ($this->storage == null)
485  $this->storage = new ilFSStoragePreview($this->obj_id);
486 
487  return $this->storage;
488  }
+ Here is the caller graph for this function:

◆ getStoragePath()

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 410 of file class.ilPreview.php.

References getStorage().

Referenced by getImages().

411  {
412  return $this->getStorage()->getPath();
413  }
getStorage()
Gets the storage object for the preview.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ hasPreview()

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 $a_type, $preview, ilRendererFactory\getRenderer(), and ilPreviewSettings\isPreviewEnabled().

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

150  {
152  return false;
153 
154  $preview = new ilPreview($a_obj_id, $a_type);
155  if ($preview->exists())
156  return true;
157 
158  // does not exist, enable on demand rendering if there's any renderer that supports our object
159  require_once("./Services/Preview/classes/class.ilRendererFactory.php");
161  return $renderer != null;
162  }
$preview
static getRenderer($preview)
Gets the renderer that is able to create a preview for the specified preview object.
$a_type
Definition: workflow.php:93
static isPreviewEnabled()
Gets whether the preview functionality is enabled.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init()

ilPreview::init ( )
private

Initializes the preview object.

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

References doRead().

Referenced by __construct().

494  {
495  // read entry
496  $this->doRead();
497  }
doRead()
Read data from database.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lookupRenderStatus()

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 ilDclFileuploadRecordRepresentation\getHTML(), and ilObjectListGUI\insertTitle().

171  {
172  $preview = new ilPreview($a_obj_id);
173  return $preview->getRenderStatus();
174  }
$preview
+ Here is the caller graph for this function:

◆ save()

ilPreview::save ( )

Saves the preview data to the database.

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

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

Referenced by create().

306  {
307  if ($this->exists)
308  $this->doUpdate();
309  else
310  $this->doCreate();
311  }
exists()
Determines whether the preview exists or not.
doCreate()
Create entry in database.
doUpdate()
Update data in database.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setRenderDate()

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 452 of file class.ilPreview.php.

Referenced by doRead().

453  {
454  $this->render_date = $a_date;
455  }
+ Here is the caller graph for this function:

◆ setRenderStatus()

ilPreview::setRenderStatus (   $a_status)

Sets the status of the rendering process.

Parameters
string$a_statusThe status to set.

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

Referenced by doRead().

473  {
474  $this->render_status = $a_status;
475  }
+ Here is the caller graph for this function:

Field Documentation

◆ $exists

ilPreview::$exists = false
private

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

Referenced by exists().

◆ $obj_id

ilPreview::$obj_id = null
private

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

Referenced by getObjId().

◆ $obj_type

ilPreview::$obj_type = null
private

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

Referenced by getObjType().

◆ $render_date

ilPreview::$render_date = false
private

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

Referenced by getRenderDate().

◆ $render_status

ilPreview::$render_status = self::RENDER_STATUS_NONE
private

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

Referenced by getRenderStatus().

◆ $storage

ilPreview::$storage = null
private

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

Referenced by getStorage().

◆ FILENAME_FORMAT

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

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

◆ RENDER_STATUS_CREATED

const ilPreview::RENDER_STATUS_CREATED = "created"

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

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

◆ RENDER_STATUS_FAILED

const ilPreview::RENDER_STATUS_FAILED = "failed"

◆ RENDER_STATUS_NONE

const ilPreview::RENDER_STATUS_NONE = "none"

◆ RENDER_STATUS_PENDING

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: