ILIAS  trunk Revision v11.0_alpha-1761-g6dbbfa7b760
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ILIAS\Style\Content\ImageFileRepo Class Reference
+ Collaboration diagram for ILIAS\Style\Content\ImageFileRepo:

Public Member Functions

 __construct (InternalDataService $factory, Filesystem\Filesystem $web_files, FileUpload $upload, protected IRSSWrapper $irss)
 
 getImages (int $style_id, string $rid)
 Get images of style. More...
 
 getWebPath (string $path)
 
 deleteImageByFilename (int $style_id, string $filename)
 
 importFromUploadResult (string $rid, UploadResult $result,)
 

Protected Member Functions

 dir (int $style_id)
 

Protected Attributes

const DIR_PATH = "sty/sty_%id%/images"
 
InternalDataService $factory
 
Filesystem Filesystem $web_files
 
FileUpload $upload
 

Detailed Description

Definition at line 32 of file class.ImageFileRepo.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Style\Content\ImageFileRepo::__construct ( InternalDataService  $factory,
Filesystem\Filesystem  $web_files,
FileUpload  $upload,
protected IRSSWrapper  $irss 
)

Member Function Documentation

◆ deleteImageByFilename()

ILIAS\Style\Content\ImageFileRepo::deleteImageByFilename ( int  $style_id,
string  $filename 
)

Definition at line 145 of file class.ImageFileRepo.php.

References ILIAS\Style\Content\ImageFileRepo\dir().

145  : void
146  {
147  $dir = $this->dir($style_id);
148  $this->web_files->delete($dir . "/" . $filename);
149  }
$filename
Definition: buildRTE.php:78
+ Here is the call graph for this function:

◆ dir()

ILIAS\Style\Content\ImageFileRepo::dir ( int  $style_id)
protected

Definition at line 52 of file class.ImageFileRepo.php.

Referenced by ILIAS\Style\Content\ImageFileRepo\deleteImageByFilename(), and ILIAS\Style\Content\ImageFileRepo\getImages().

52  : string
53  {
54  return str_replace("%id%", (string) $style_id, self::DIR_PATH);
55  }
+ Here is the caller graph for this function:

◆ getImages()

ILIAS\Style\Content\ImageFileRepo::getImages ( int  $style_id,
string  $rid 
)

Get images of style.

Parameters
int$style_id
Returns
Generator
Exceptions
Filesystem

Definition at line 63 of file class.ImageFileRepo.php.

References Vendor\Package\$e, $path, ILIAS\Style\Content\ImageFileRepo\dir(), factory(), ILIAS\Style\Content\ImageFileRepo\getWebPath(), and ILIAS\Data\DataSize\KB.

Referenced by ILIAS\Style\Content\ImageFileRepo\getWebPath().

66  : Generator {
67  if ($rid !== "") {
68  $unzip = $this->irss->getContainerZip($rid);
69  $uri = $this->irss->stream($rid)->getMetadata("uri");
70  $zip_archive = new \ZipArchive();
71  $zip_archive->open($uri, \ZipArchive::RDONLY);
72 
73  foreach ($unzip->getPaths() as $path) {
74  if (str_starts_with($path, ".")) {
75  continue;
76  }
77  if (!str_starts_with($path, "images")) {
78  continue;
79  }
80  if (!in_array(strtolower(pathinfo($path, PATHINFO_EXTENSION)), ["jpg", "png", "gif", "svg"])) {
81  continue;
82  }
83  $att = $zip_archive->statName($path);
84  $full_path = $this->irss->getContainerUri($rid, $path);
85  try {
86  $image_size = getimagesize($full_path);
87  } catch (\Exception $e) {
88  }
89  $width = $image_size[0] ?? 0;
90  $height = $image_size[1] ?? 0;
91  yield $this->factory->image(
92  $this->irss->getContainerUri($rid, $path),
93  new DataSize($att["size"], DataSize::KB),
94  $width,
95  $height
96  );
97  }
98  }
99 
100 
101  $dir = $this->dir($style_id);
102  if ($this->web_files->hasDir($dir)) {
103  foreach ($this->web_files->listContents($dir) as $meta) {
104  if ($meta->isFile()) {
105  $size = $this->web_files->getSize(
106  $meta->getPath(),
108  );
109  $image_size = getimagesize($this->getWebPath($meta->getPath()));
110  $width = $image_size[0] ?? 0;
111  $height = $image_size[1] ?? 0;
112  yield $this->factory->image(
113  $meta->getPath(),
114  $size,
115  $width,
116  $height
117  );
118  }
119  }
120  }
121  }
factory()
$path
Definition: ltiservices.php:29
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getWebPath()

ILIAS\Style\Content\ImageFileRepo::getWebPath ( string  $path)

Definition at line 124 of file class.ImageFileRepo.php.

References $filename, $path, CLIENT_ID, ILIAS\Style\Content\ImageFileRepo\getImages(), ILIAS_WEB_DIR, and null.

Referenced by ILIAS\Style\Content\ImageFileRepo\getImages().

124  : string
125  {
126  if (str_starts_with($path, "http")) {
127  return $path;
128  }
129  return ILIAS_WEB_DIR . "/" . CLIENT_ID . "/" . $path;
130  }
$path
Definition: ltiservices.php:29
const CLIENT_ID
Definition: constants.php:41
const ILIAS_WEB_DIR
Definition: constants.php:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ importFromUploadResult()

ILIAS\Style\Content\ImageFileRepo::importFromUploadResult ( string  $rid,
UploadResult  $result 
)

Definition at line 151 of file class.ImageFileRepo.php.

154  : void {
155  $this->irss->addUploadToContainer(
156  $rid,
157  $result
158  );
159  }

Field Documentation

◆ $factory

InternalDataService ILIAS\Style\Content\ImageFileRepo::$factory
protected

◆ $upload

FileUpload ILIAS\Style\Content\ImageFileRepo::$upload
protected

◆ $web_files

Filesystem Filesystem ILIAS\Style\Content\ImageFileRepo::$web_files
protected

◆ DIR_PATH

const ILIAS\Style\Content\ImageFileRepo::DIR_PATH = "sty/sty_%id%/images"
protected

Definition at line 34 of file class.ImageFileRepo.php.


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