ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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.
$a_type
Definition: workflow.php:92

References $a_type, and 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
113 // get source preview
114 $src = new ilPreview($a_src_id);
115 $status = $src->getRenderStatus();
116
117 // created? copy the previews
118 if ($status == self::RENDER_STATUS_CREATED) {
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 } else {
133 // all other status need no action
134 // self::RENDER_STATUS_FAILED
135 // self::RENDER_STATUS_NONE
136 // self::RENDER_STATUS_PENDING
137 }
138 }
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
199 // get renderer for preview
200 require_once("./Services/Preview/classes/class.ilRendererFactory.php");
201 $renderer = ilRendererFactory::getRenderer($this);
202
203 // no renderer available?
204 if ($renderer == null) {
205 // bugfix mantis 23293
206 $this->delete();
207 return false;
208 }
209
210 // exists, but still pending?
212 return false;
213 }
214
215 // not forced? check if update really needed
216 if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED && !$a_force) {
217 // check last modified against last render date
218 if ($a_obj->getLastUpdateDate() <= $this->getRenderDate()) {
219 return false;
220 }
221 }
222
223 // re-create the directory to store the previews
224 $this->getStorage()->delete();
225 $this->getStorage()->create();
226
227 // let the renderer create the preview
228 $renderer->render($this, $a_obj, true);
229
230 // save to database
231 $this->save();
232
233 return true;
234 }
save()
Saves the preview data to the database.
getStorage()
Gets the storage object for the preview.
getRenderStatus()
Gets the status of the rendering process.
getRenderDate()
Gets the date when the preview was rendered.
const RENDER_STATUS_PENDING
static getRenderer($preview)
Gets the renderer that is able to create a preview for the specified preview object.

References getRenderDate(), ilRendererFactory\getRenderer(), getRenderStatus(), getStorage(), ilPreviewSettings\isPreviewEnabled(), RENDER_STATUS_PENDING, 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 ilDclFileuploadRecordRepresentation\getHTML().

+ Here is the caller graph for this function:

◆ delete()

ilPreview::delete ( )

Deletes the preview.

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

240 {
241 // does exist?
242 if ($this->exists()) {
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 }
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 313 of file class.ilPreview.php.

314 {
315 global $DIC;
316 $ilDB = $DIC['ilDB'];
317
318 $ilDB->insert(
319 "preview_data",
320 array(
321 "obj_id" => array("integer", $this->getObjId()),
322 "render_date" => array("timestamp", $this->getRenderDate()),
323 "render_status" => array("text", $this->getRenderStatus())
324 )
325 );
326 $this->exists = true;
327 }
getObjId()
Gets the id of the object the preview is for.
global $DIC
Definition: saml.php:7
global $ilDB

References $DIC, $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 371 of file class.ilPreview.php.

372 {
373 global $DIC;
374 $ilDB = $DIC['ilDB'];
375
376 $ilDB->manipulateF(
377 "DELETE FROM preview_data WHERE obj_id=%s",
378 array("integer"),
379 array($this->getObjId())
380 );
381 }

References $DIC, $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 332 of file class.ilPreview.php.

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

References $DIC, $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 353 of file class.ilPreview.php.

354 {
355 global $DIC;
356 $ilDB = $DIC['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 }

References $DIC, $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 423 of file class.ilPreview.php.

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

References getStorage().

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

435 {
437 return $path . "/" . self::FILENAME_FORMAT;
438 }
$path
Definition: aliased.php:25
getAbsoluteStoragePath()
Gets the absolute path where the previews are stored.
const FILENAME_FORMAT
static removeTrailingPathSeparators($path)

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

260 {
261 $images = array();
262
263 // status must be created
264 $path = $this->getStoragePath();
265 if ($this->getRenderStatus() == self::RENDER_STATUS_CREATED) {
266 // load files
267 if ($handle = @opendir($path)) {
268 while (false !== ($file = readdir($handle))) {
269 $filepath = $path . "/" . $file;
270 if (!is_file($filepath)) {
271 continue;
272 }
273
274 if ($file != '.' && $file != '..' && strpos($file, "preview_") === 0) {
275 $image = array();
276 $image["url"] = ilUtil::getHtmlPath($filepath);
277
278 // get image size
279 $size = @getimagesize($filepath);
280 if ($size !== false) {
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 }
$size
Definition: RandomTest.php:84
getStoragePath()
Gets the path where the previews are stored relative to the web directory.
static getHtmlPath($relative_path)
get url of path

References $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 388 of file class.ilPreview.php.

389 {
390 return $this->obj_id;
391 }

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

399 {
400 // not evaluated before or specified?
401 if (empty($this->obj_type)) {
402 $this->obj_type = ilObject::_lookupType($this->getObjId(), false);
403 }
404
405 return $this->obj_type;
406 }
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 445 of file class.ilPreview.php.

446 {
447 return $this->render_date;
448 }

References $render_date.

Referenced by create(), 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 465 of file class.ilPreview.php.

466 {
468 }

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

486 {
487 if ($this->storage == null) {
488 $this->storage = new ilFSStoragePreview($this->obj_id);
489 }
490
491 return $this->storage;
492 }

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

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

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

148 {
150 return false;
151 }
152
153 $preview = new ilPreview($a_obj_id, $a_type);
154 if ($preview->exists()) {
155 return true;
156 }
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 $a_type, $preview, ilRendererFactory\getRenderer(), and ilPreviewSettings\isPreviewEnabled().

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

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

498 {
499 // read entry
500 $this->doRead();
501 }
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 ilDclFileuploadRecordRepresentation\getHTML(), and ilObjectListGUI\insertTitle().

+ 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 }
308 }
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 455 of file class.ilPreview.php.

456 {
457 $this->render_date = $a_date;
458 }

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

476 {
477 $this->render_status = $a_status;
478 }

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"

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