ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

70 {
71 $this->obj_id = $a_obj_id;
72 $this->obj_type = $a_type;
73
74 $this->init();
75 }
init()
Initializes the preview object.

References init().

+ 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.

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 isPreviewEnabled()
Gets whether the preview functionality is enabled.
static rCopy($a_sdir, $a_tdir, $preserveTimeAttributes=false)
Copies content of a directory $a_sdir recursively to a directory $a_tdir.

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

Referenced by ilObjFile\doCloneObject().

+ 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.

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 return false;
205
206 // exists, but still pending?
207 if ($this->getRenderStatus() == self::RENDER_STATUS_PENDING)
208 return false;
209
210 // not forced? check if update really needed
211 if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED && !$a_force)
212 {
213 // check last modified against last render date
214 if ($a_obj->getLastUpdateDate() <= $this->getRenderDate())
215 return false;
216 }
217
218 // re-create the directory to store the previews
219 $this->getStorage()->delete();
220 $this->getStorage()->create();
221
222 // let the renderer create the preview
223 $renderer->render($this, $a_obj, true);
224
225 // save to database
226 $this->save();
227
228 return true;
229 }
save()
Saves the preview data to the database.
getStorage()
Gets the storage object for the preview.
getRenderStatus()
Gets the status of the rendering process.
static getRenderer($preview)
Gets the renderer that is able to create a preview for the specified preview object.

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

+ 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.

85 {
86 $preview = new ilPreview($a_obj->getId(), $a_obj->getType());
87 return $preview->create($a_obj, $a_force);
88 }
$preview

References $preview.

Referenced by ilObjFile\createPreview(), and ilDataCollectionDatatype\parseHTML().

+ Here is the caller graph for this function:

◆ delete()

ilPreview::delete ( )

Deletes the preview.

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

235 {
236 // does exist?
237 if ($this->exists())
238 {
239 // delete files and database entry
240 $this->getStorage()->delete();
241 $this->doDelete();
242
243 // reset values
244 $this->exists = false;
245 $this->render_date = false;
246 $this->render_status = self::RENDER_STATUS_NONE;
247 }
248 }
const RENDER_STATUS_NONE
exists()
Determines whether the preview exists or not.
doDelete()
Delete data from database.

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

+ 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.

96 {
97 $preview = new ilPreview($a_obj_id);
98 $preview->delete();
99 }

References $preview.

Referenced by ilObjFile\deletePreview().

+ Here is the caller graph for this function:

◆ doCreate()

ilPreview::doCreate ( )
protected

Create entry in database.

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

313 {
314 global $ilDB;
315
316 $ilDB->insert(
317 "preview_data",
318 array(
319 "obj_id" => array("integer", $this->getObjId()),
320 "render_date" => array("timestamp", $this->getRenderDate()),
321 "render_status" => array("text", $this->getRenderStatus())
322 )
323 );
324 $this->exists = true;
325 }
getObjId()
Gets the id of the object the preview is for.
getRenderDate()
Gets the date when the preview was rendered.
global $ilDB

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

Referenced by save().

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

368 {
369 global $ilDB;
370
371 $ilDB->manipulateF(
372 "DELETE FROM preview_data WHERE obj_id=%s",
373 array("integer"),
374 array($this->getObjId()));
375 }

References $ilDB, and getObjId().

Referenced by delete().

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

331 {
332 global $ilDB;
333
334 $set = $ilDB->queryF(
335 "SELECT * FROM preview_data WHERE obj_id=%s",
336 array("integer"),
337 array($this->getObjId()));
338
339 while ($rec = $ilDB->fetchAssoc($set))
340 {
341 $this->setRenderDate($rec["render_date"]);
342 $this->setRenderStatus($rec["render_status"]);
343 $this->exists = true;
344 }
345 }
setRenderStatus($a_status)
Sets the status of the rendering process.
setRenderDate($a_date)
Sets the date when the preview was rendered.

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

Referenced by init().

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

351 {
352 global $ilDB;
353
354 $ilDB->update(
355 "preview_data",
356 array(
357 "render_date" => array("timestamp", $this->getRenderDate()),
358 "render_status" => array("text", $this->getRenderStatus())
359 ),
360 array("obj_id" => array("integer", $this->getObjId()))
361 );
362 }

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

Referenced by save().

+ 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.

182 {
183 return $this->exists;
184 }

References $exists.

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

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

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

References getStorage(), and ILIAS_ABSOLUTE_PATH.

Referenced by getFilePathFormat().

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

428 {
430 return $path . "/" . self::FILENAME_FORMAT;
431 }
getAbsoluteStoragePath()
Gets the absolute path where the previews are stored.
const FILENAME_FORMAT
static removeTrailingPathSeparators($path)
$path
Definition: index.php:22

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

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

256 {
257 $images = array();
258
259 // status must be created
260 $path = $this->getStoragePath();
261 if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED)
262 {
263 // load files
264 if ($handle = @opendir($path))
265 {
266 while (false !== ($file = readdir($handle)))
267 {
268 $filepath = $path . "/" . $file;
269 if (!is_file($filepath))
270 continue;
271
272 if ($file != '.' && $file != '..' && strpos($file, "preview_") === 0)
273 {
274 $image = array();
275 $image["url"] = ilUtil::getHtmlPath($filepath);
276
277 // get image size
278 $size = @getimagesize($filepath);
279 if ($size !== false)
280 {
281 $image["width"] = $size[0];
282 $image["height"] = $size[1];
283 }
284
285 $images[$file] = $image;
286 }
287 }
288 closedir($handle);
289
290 // sort by key
291 ksort($images);
292 }
293 }
294
295 return $images;
296 }
print $file
$size
Definition: RandomTest.php:79
getStoragePath()
Gets the path where the previews are stored relative to the web directory.
static getHtmlPath($relative_path)
get url of path

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

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

383 {
384 return $this->obj_id;
385 }

References $obj_id.

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

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

393 {
394 // not evaluated before or specified?
395 if (empty($this->obj_type))
396 $this->obj_type = ilObject::_lookupType($this->getObjId(), false);
397
398 return $this->obj_type;
399 }
static _lookupType($a_id, $a_reference=false)
lookup object type

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

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

439 {
440 return $this->render_date;
441 }

References $render_date.

Referenced by doCreate(), and doUpdate().

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

459 {
461 }

References $render_status.

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

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

479 {
480 if ($this->storage == null)
481 $this->storage = new ilFSStoragePreview($this->obj_id);
482
483 return $this->storage;
484 }

References $storage.

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

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

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

References getStorage().

Referenced by getImages().

+ 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.

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 }

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

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

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

490 {
491 // read entry
492 $this->doRead();
493 }
doRead()
Read data from database.

References doRead().

Referenced by __construct().

+ 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.

171 {
172 $preview = new ilPreview($a_obj_id);
173 return $preview->getRenderStatus();
174 }

References $preview.

Referenced by ilObjectListGUI\insertTitle(), and ilDataCollectionDatatype\parseHTML().

+ Here is the caller graph for this function:

◆ save()

ilPreview::save ( )

Saves the preview data to the database.

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

302 {
303 if ($this->exists)
304 $this->doUpdate();
305 else
306 $this->doCreate();
307 }
doUpdate()
Update data in database.
doCreate()
Create entry in database.

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

Referenced by create().

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

449 {
450 $this->render_date = $a_date;
451 }

Referenced by doRead().

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

469 {
470 $this->render_status = $a_status;
471 }

Referenced by doRead().

+ 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.

Referenced by getFilePathFormat().

◆ 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: