19declare(strict_types=1);
23trait ManipulateImagesInChoiceQuestionsTrait
30 protected function deleteImage($image_filename): void
32 $cleaned_image_file_name = basename($image_filename);
33 $imagepath = $this->getImagePath();
34 @unlink($imagepath . $cleaned_image_file_name);
35 $thumbpath = $imagepath . $this->getThumbPrefix() . $cleaned_image_file_name;
39 private function cloneImages(
40 int $source_question_id,
41 int $source_parent_id,
42 int $target_question_id,
43 int $target_parent_id,
46 $image_source_path = $this->getImagePath($source_question_id, $source_parent_id);
47 $image_target_path = $this->getImagePath($target_question_id, $target_parent_id);
49 if (!file_exists($image_target_path)) {
52 $this->removeAllImageFiles($image_target_path);
55 foreach ($answers as $answer) {
61 if (!file_exists($image_source_path .
$filename)
63 $this->log->forComponent(
'qpl')->warning(
'Image could not be cloned for object for question: ' . $target_question_id);
65 if (!file_exists($image_source_path . $this->getThumbPrefix() .
$filename)
66 || !
copy($image_source_path . $this->getThumbPrefix() .
$filename, $image_target_path . $this->getThumbPrefix() .
$filename)) {
67 $this->log->forComponent(
'qpl')->warning(
'Image thumbnail could not be cloned for object for question: ' . $target_question_id);
72 public function rebuildThumbnails(
78 if (!$is_single_line || $thumbnail_size === 0) {
82 foreach ($answers as $answer) {
83 if ($answer->getImage() ===
null || $answer->getImage() ===
'') {
87 $thumb_path = $image_path . $this->getThumbPrefix() . $answer->getImage();
88 if (file_exists($thumb_path)) {
92 $current_file_path = $image_path . $answer->getImage();
93 if (!file_exists($current_file_path)) {
96 $new_file_name = $this->buildHashedImageFilename($answer->getImage(),
true);
97 $new_file_path = $image_path . $new_file_name;
98 rename($current_file_path, $new_file_path);
99 $answer->setImage($new_file_name);
101 $this->generateThumbForFile(
111 public function getThumbPrefix(): string
116 public function generateThumbForFile(
121 $file_path = $image_path . $file_name;
122 if (!file_exists($file_path)) {
126 $thumb_path = $image_path . $this->getThumbPrefix() . $file_name;
127 $path_info = pathinfo($file_path);
129 switch (strtoupper($path_info[
'extension'])) {
static makeDirParents(string $a_dir)
Create a new directory and all parent directories.
static convertImage(string $a_from, string $a_to, string $a_target_format="", string $a_geometry="", string $a_background_color="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if(!file_exists('../ilias.ini.php'))