ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.FileListManager.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
27{
28 protected \ILIAS\COPage\Dom\DomUtil $dom_util;
29
30 public function __construct()
31 {
32 global $DIC;
33 $this->dom_util = $DIC->copage()->internal()->domain()->domUtil();
34 }
35
36 public function getAllFileObjIds(\DOMDocument $dom): array
37 {
38 $file_obj_ids = [];
39 $path = "//FileItem/Identifier";
40 $nodes = $this->dom_util->path($dom, $path);
41 foreach ($nodes as $node) {
42 $file_obj_ids[] = $node->getAttribute("Entry");
43 }
44 return $file_obj_ids;
45 }
46
47 public function addFileSizes(\DOMDocument $dom): void
48 {
49 $path = "//FileItem";
50 $nodes = $this->dom_util->path($dom, $path);
51 foreach ($nodes as $node) {
52 $cnode = $node;
53 $size_node = $dom->createElement("Size");
54 $size_node = $cnode->appendChild($size_node);
55
56 $size = "";
57 foreach ($cnode->childNodes as $child) {
58 if ($child->nodeName == "Identifier") {
59 if ($child->hasAttribute("Entry")) {
60 $entry = $child->getAttribute("Entry");
61 $entry_arr = explode("_", $entry);
62 $id = $entry_arr[count($entry_arr) - 1];
63 $info_repo = new \ilObjFileInfoRepository();
64 $info = $info_repo->getByObjectId((int) $id);
65 $size = $info->getFileSize()->inBytes();
66 }
67 }
68 }
69 $this->dom_util->setContent($size_node, (string) $size);
70 }
71 }
72
77 public function resolveFileItems(
78 \DOMDocument $dom,
79 array $a_mapping
80 ): bool {
81 $path = "//FileItem/Identifier";
82 $changed = false;
83 $nodes = $this->dom_util->path($dom, $path);
84 foreach ($nodes as $node) {
85 $old_id = $node->getAttribute("Entry");
86 $old_id = explode("_", $old_id);
87 $old_id = $old_id[count($old_id) - 1];
88 if (($a_mapping[$old_id] ?? 0) > 0) {
89 $node->setAttribute("Entry", "il__file_" . $a_mapping[$old_id]);
90 $changed = true;
91 }
92 }
93
94 return $changed;
95 }
96}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
resolveFileItems(\DOMDocument $dom, array $a_mapping)
Resolve file items (after import)
$info
Definition: entry_point.php:21
$path
Definition: ltiservices.php:30
global $DIC
Definition: shib_login.php:26