ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
IIMManager.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 
31 {
32  protected \ILIAS\MediaObjects\MediaObjectManager $media_manager;
33  protected \ilLogger $log;
35  protected \ILIAS\COPage\Dom\DomUtil $dom_util;
36 
37  public function __construct(
38  InternalDomainService $domain
39  ) {
40  global $DIC;
41  $this->domain = $domain;
42  $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
43  if (isset($DIC['ilLoggerFactory'])) {
44  $this->log = $domain->log();
45  }
46  $this->media_manager = $DIC->mediaObjects()->internal()->domain()->mediaObject();
47  }
48 
49  public function handleUploadResult(
50  FileUpload $upload,
51  UploadResult $result,
52  ?\ilObjMediaObject $mob = null
54  $this->log->debug("Handle mob upload");
55  $title = $result->getName();
56  $this->log->debug($title);
57 
58  if (is_null($mob)) {
59  $this->log->debug("New...");
60  $mob = new \ilObjMediaObject();
61  $mob->setTitle($title);
62  $mob->setDescription("");
63  $mob->create();
64 
65  $media_item = $mob->addMediaItemFromUpload(
66  "Standard",
67  $result
68  );
69  } else {
70  $this->log->debug("Update...");
71  $media_item = $mob->replaceMediaItemFromUpload(
72  "Standard",
73  $result
74  );
75  }
76  $mob->update();
77 
78  return new BasicHandlerResult(
79  "mob_id",
81  (string) $mob->getId(),
82  ''
83  );
84  }
85 
86  public function handleOverlayUpload(
87  \ilObjMediaObject $mob,
88  FileUpload $upload,
89  UploadResult $result
92  $result,
93  "overlays"
94  );
95  $mob->makeThumbnail(
96  "overlays/" . $result->getName(),
97  "thumb/" . $this->getOverlayThumbnailName($result->getName())
98  );
99  return new BasicHandlerResult(
100  "mob_id",
102  (string) $mob->getId(),
103  ''
104  );
105  }
106 
107  public function getOverlayWebPath(\ilObjMediaObject $mob, string $file): string
108  {
109  return $this->media_manager->getLocalSrc($mob->getId(), "/overlays/" . $file);
110  }
111 
112  public function getOverlayThumbnailPath(\ilObjMediaObject $mob, string $file): string
113  {
114  return $this->media_manager->getLocalSrc($mob->getId(), "/thumb/" . $file);
115  }
116 
117  protected function getOverlayThumbnailName(string $file): string
118  {
119  $piname = pathinfo($file);
120  return basename($file, "." . $piname['extension']) . ".png";
121  }
122 
123  public function getOverlays(\ilObjMediaObject $mob): array
124  {
125  $overlays = [];
126  foreach ($mob->getFilesOfDirectory("/overlays") as $file) {
127  $file = $file["basename"];
128  $overlays[] = [
129  "name" => $file,
130  "thumbpath" => $this->getOverlayThumbnailPath($mob, $file),
131  "webpath" => $this->getOverlayWebPath($mob, $file)
132  ];
133  }
134  return $overlays;
135  }
136 
141  public function resolveIIMMediaAliases(
142  \DOMDocument $dom,
143  array $a_mapping
144  ): bool {
145  // resolve normal internal links
146  $path = "//InteractiveImage/MediaAlias";
147  $changed = false;
148  $nodes = $this->dom_util->path($dom, $path);
149  foreach ($nodes as $node) {
150  $old_id = $node->getAttribute("OriginId");
151  if (($a_mapping[$old_id] ?? 0) > 0) {
152  $node->setAttribute("OriginId", "il__mob_" . $a_mapping[$old_id]);
153  $changed = true;
154  }
155  }
156  return $changed;
157  }
158 }
resolveIIMMediaAliases(\DOMDocument $dom, array $a_mapping)
Resolve iim media aliases (in ilContObjParse)
Definition: IIMManager.php:141
getOverlayThumbnailPath(\ilObjMediaObject $mob, string $file)
Definition: IIMManager.php:112
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(InternalDomainService $domain)
Definition: IIMManager.php:37
$path
Definition: ltiservices.php:29
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
handleUploadResult(FileUpload $upload, UploadResult $result, ?\ilObjMediaObject $mob=null)
Definition: IIMManager.php:49
getFilesOfDirectory(string $dir_path="")
global $DIC
Definition: shib_login.php:22
handleOverlayUpload(\ilObjMediaObject $mob, FileUpload $upload, UploadResult $result)
Definition: IIMManager.php:86
Class FileUpload.
Definition: FileUpload.php:37
getOverlayWebPath(\ilObjMediaObject $mob, string $file)
Definition: IIMManager.php:107
makeThumbnail(string $source, string $thumbname,)
Make thumbnail.
addAdditionalFileFromUpload(UploadResult $result, string $subdir)
ILIAS MediaObjects MediaObjectManager $media_manager
Definition: IIMManager.php:32