ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
IIMManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 
31 {
32  protected \ilLogger $log;
34  protected \ILIAS\COPage\Dom\DomUtil $dom_util;
35 
36  public function __construct(
37  InternalDomainService $domain
38  ) {
39  global $DIC;
40  $this->domain = $domain;
41  $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
42  if (isset($DIC['ilLoggerFactory'])) {
43  $this->log = $domain->log();
44  }
45  }
46 
47  public function handleUploadResult(
48  FileUpload $upload,
49  UploadResult $result,
50  \ilObjMediaObject $mob = null
52  $this->log->debug("Handle mob upload");
53  $title = $result->getName();
54  $this->log->debug($title);
55 
56  if (is_null($mob)) {
57  $this->log->debug("New...");
58  $mob = new \ilObjMediaObject();
59  $mob->setTitle($title);
60  $mob->setDescription("");
61  $mob->create();
62 
63  $mob->createDirectory();
64  $media_item = new \ilMediaItem();
65  $mob->addMediaItem($media_item);
66  $media_item->setPurpose("Standard");
67  } else {
68  $this->log->debug("Update...");
69  $media_item = $mob->getMediaItem("Standard");
70  }
71 
72  $mob_dir = \ilObjMediaObject::_getRelativeDirectory($mob->getId());
73  $file_name = \ilObjMediaObject::fixFilename($title);
74  $file = $mob_dir . "/" . $file_name;
75 
76  $this->log->debug("Move file to: " . $mob_dir . ", " . $file_name);
77  $upload->moveOneFileTo(
78  $result,
79  $mob_dir,
81  $file_name,
82  true
83  );
84 
85  // get mime type
86  $format = \ilObjMediaObject::getMimeType($file);
87  $location = $file_name;
88 
89  // set real meta and object data
90  $media_item->setFormat($format);
91  $media_item->setLocation($location);
92  $media_item->setLocationType("LocalFile");
93  $mob->update();
94 
95  return new BasicHandlerResult(
96  "mob_id",
98  (string) $mob->getId(),
99  ''
100  );
101  }
102 
103  public function handleOverlayUpload(
104  \ilObjMediaObject $mob,
105  FileUpload $upload,
106  UploadResult $result
107  ): BasicHandlerResult {
109  $upload,
110  $result,
111  "overlays"
112  );
113  $mob->makeThumbnail(
114  "overlays/" . $result->getName(),
115  $this->getOverlayThumbnailName($result->getName())
116  );
117  return new BasicHandlerResult(
118  "mob_id",
120  (string) $mob->getId(),
121  ''
122  );
123  }
124 
125  public function getOverlayWebPath(\ilObjMediaObject $mob, string $file): string
126  {
127  return \ilObjMediaObject::_getURL($mob->getId()) . "/overlays/" . $file;
128  }
129 
130  public function getOverlayThumbnailPath(\ilObjMediaObject $mob, string $file): string
131  {
132  return \ilObjMediaObject::getThumbnailPath(
133  $mob->getId(),
134  $this->getOverlayThumbnailName($file)
135  );
136  }
137 
138  protected function getOverlayThumbnailName(string $file): string
139  {
140  $piname = pathinfo($file);
141  return basename($file, "." . $piname['extension']) . ".png";
142  }
143 
144  public function getOverlays(\ilObjMediaObject $mob): array
145  {
146  return array_map(
147  function ($file) use ($mob) {
148  return [
149  "name" => $file,
150  "thumbpath" => $this->getOverlayThumbnailPath($mob, $file),
151  "webpath" => $this->getOverlayWebPath($mob, $file)
152  ];
153  },
154  $mob->getFilesOfDirectory("overlays")
155  );
156  }
157 
162  public function resolveIIMMediaAliases(
163  \DOMDocument $dom,
164  array $a_mapping
165  ): bool {
166  // resolve normal internal links
167  $path = "//InteractiveImage/MediaAlias";
168  $changed = false;
169  $nodes = $this->dom_util->path($dom, $path);
170  foreach ($nodes as $node) {
171  $old_id = $node->getAttribute("OriginId");
172  if (($a_mapping[$old_id] ?? 0) > 0) {
173  $node->setAttribute("OriginId", "il__mob_" . $a_mapping[$old_id]);
174  $changed = true;
175  }
176  }
177  return $changed;
178  }
179 }
resolveIIMMediaAliases(\DOMDocument $dom, array $a_mapping)
Resolve iim media aliases (in ilContObjParse)
Definition: IIMManager.php:162
handleUploadResult(FileUpload $upload, UploadResult $result, \ilObjMediaObject $mob=null)
Definition: IIMManager.php:47
getOverlayThumbnailPath(\ilObjMediaObject $mob, string $file)
Definition: IIMManager.php:130
static _getRelativeDirectory(int $a_mob_id)
Get relative (to webspace dir) directory.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
__construct(InternalDomainService $domain)
Definition: IIMManager.php:36
addAdditionalFileFromUpload(FileUpload $upload, UploadResult $result, string $subdir)
$path
Definition: ltiservices.php:32
global $DIC
Definition: feed.php:28
static getMimeType(string $a_file, bool $a_external=false)
get mime type for file
moveOneFileTo(UploadResult $uploadResult, string $destination, int $location=Location::STORAGE, string $file_name='', bool $override_existing=false)
Moves a single File (the attributes, metadata and upload-status of which are contained in UploadResul...
handleOverlayUpload(\ilObjMediaObject $mob, FileUpload $upload, UploadResult $result)
Definition: IIMManager.php:103
Class FileUpload.
Definition: FileUpload.php:34
getOverlayWebPath(\ilObjMediaObject $mob, string $file)
Definition: IIMManager.php:125
static fixFilename(string $a_name)
Fix filename of uploaded file.
makeThumbnail(string $a_file, string $a_thumbname,)
Make thumbnail.
getFilesOfDirectory(string $a_subdir="")
Get files of directory.
const WEB
The filesystem within the ilias web root.
Definition: Location.php:35