/**
  * Creates the preview of the specified preview object.
  * 
  * @param ilPreview $preview The preview object.
  * @param ilObject $obj The object to create a preview for.
  * @param bool $async true, if the rendering should be done asynchronously; otherwise, false.
  * @return bool true, if the preview was successfully rendered; otherwise, false.
  */
 public final function render($preview, $obj, $async)
 {
     $preview->setRenderDate(ilUtil::now());
     $preview->setRenderStatus(ilPreview::RENDER_STATUS_PENDING);
     $preview->save();
     // TODO: this should be done in background if $async is true
     // the deriving renderer should deliver images
     require_once "./Services/Preview/classes/class.ilRenderedImage.php";
     $images = $this->renderImages($obj);
     // process each image
     if (is_array($images) && count($images) > 0) {
         $success = false;
         foreach ($images as $idx => $image) {
             // create the ending preview image
             $success |= $this->createPreviewImage($image->getImagePath(), sprintf($preview->getFilePathFormat(), $idx + 1));
             // if the image is temporary we can delete it
             if ($image->isTemporary()) {
                 $image->delete();
             }
         }
         $preview->setRenderDate(ilUtil::now());
         $preview->setRenderStatus($success ? ilPreview::RENDER_STATUS_CREATED : ilPreview::RENDER_STATUS_FAILED);
         return $success;
     } else {
         $preview->setRenderDate(ilUtil::now());
         $preview->setRenderStatus(ilPreview::RENDER_STATUS_FAILED);
         return false;
     }
 }
Esempio n. 2
0
 /**
  * Copies the preview images from one preview to a new preview object.
  * 
  * @param int $a_src_id The id of the object to copy from.
  * @param int $a_dest_id The id of the object to copy to.
  */
 public static function copyPreviews($a_src_id, $a_dest_id)
 {
     if (!ilPreviewSettings::isPreviewEnabled()) {
         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
     }
 }