ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilMediaPoolPage.php
Go to the documentation of this file.
1<?php
2
24{
26
27 public function getParentType(): string
28 {
29 return "mep";
30 }
31
32 public function setPool(ilObjMediaPool $pool): void
33 {
34 $this->pool = $pool;
35 }
36
37 public static function deleteAllPagesOfMediaPool(int $a_media_pool_id): void
38 {
39 // @todo deletion process of snippets
40 }
41
45 public static function exists(int $a_media_pool_id, string $a_title): void
46 {
47 // @todo: check if we need this
48 }
49
50 public static function lookupTitle(int $a_page_id): string
51 {
52 return ilMediaPoolItem::lookupTitle($a_page_id);
53 }
54
58 public function getUsages(bool $a_incl_hist = true): array
59 {
60 return self::lookupUsages($this->getId(), $a_incl_hist);
61 }
62
67 public static function lookupUsages(
68 int $a_id,
69 bool $a_incl_hist = true
70 ): array {
71 global $DIC;
72
73 $ilDB = $DIC->database();
74
75 // get usages in pages
76 $q = "SELECT * FROM page_pc_usage WHERE pc_id = " .
77 $ilDB->quote($a_id, "integer") .
78 " AND pc_type = " . $ilDB->quote("incl", "text");
79
80 if (!$a_incl_hist) {
81 $q .= " AND usage_hist_nr = " . $ilDB->quote(0, "integer");
82 }
83
84 $us_set = $ilDB->query($q);
85 $ret = array();
86 $ct = "";
87 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
88 $ut = "";
89 if (is_int(strpos($us_rec["usage_type"], ":"))) {
90 $us_arr = explode(":", $us_rec["usage_type"]);
91 $ut = $us_arr[1];
92 $ct = $us_arr[0];
93 }
94
95 // check whether page exists
96 $skip = false;
97 if ($ut === "pg" && !ilPageObject::_exists($ct, $us_rec["usage_id"])) {
98 $skip = true;
99 }
100
101 if (!$skip) {
102 $ret[] = array("type" => $us_rec["usage_type"],
103 "id" => $us_rec["usage_id"],
104 "hist_nr" => $us_rec["usage_hist_nr"],
105 "lang" => $us_rec["usage_lang"]);
106 }
107 }
108
109 // get usages in media pools
110 $q = "SELECT DISTINCT mep_id FROM mep_tree JOIN mep_item ON (child = obj_id) WHERE mep_item.obj_id = " .
111 $ilDB->quote($a_id, "integer") . " AND mep_item.type = " . $ilDB->quote("pg", "text");
112 $us_set = $ilDB->query($q);
113 while ($us_rec = $ilDB->fetchAssoc($us_set)) {
114 $ret[] = [
115 "type" => "mep",
116 "id" => (int) $us_rec["mep_id"]
117 ];
118 }
119
120 return $ret;
121 }
122
123 protected function getMetadataType(): string
124 {
125 return "mpg";
126 }
127
137 public function MDUpdateListener(string $a_element): bool
138 {
139 switch ($a_element) {
140 case 'General':
141
142 // Update Title and description
143 $paths = $this->lom_services->paths();
144 $title = $this->lom_services->read(
145 $this->pool->getId(),
146 $this->getId(),
147 $this->getMetadataType(),
148 $paths->title()
149 )->firstData($paths->title())->value();
150
151 $item = new ilMediaPoolItem($this->getId());
152 $item->setTitle($title);
153 $item->update();
154
155 break;
156
157 default:
158 }
159 return true;
160 }
161
165 public function createMetaData(int $pool_id): bool
166 {
167 $ilUser = $this->user;
168
169 $this->lom_services->derive()
170 ->fromBasicProperties(
171 self::lookupTitle($this->getId()),
172 '',
173 $ilUser->getPref('language')
174 )->forObject($pool_id, $this->getId(), $this->getMetadataType());
175
176 return true;
177 }
178
179 public function updateMetaData(): void
180 {
181 $paths = $this->lom_services->paths();
182 $this->lom_services->manipulate($this->pool->getId(), $this->getId(), $this->getMetadataType())
183 ->prepareCreateOrUpdate($paths->title(), self::lookupTitle($this->getId()))
184 ->execute();
185 }
186
187
188 public function deleteMetaData(): void
189 {
190 // Delete meta data
191 $this->lom_services->deleteAll($this->pool->getId(), $this->getId(), $this->getMetadataType());
192 }
193}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static lookupTitle(int $a_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setPool(ilObjMediaPool $pool)
static lookupTitle(int $a_page_id)
createMetaData(int $pool_id)
create meta data entry
static exists(int $a_media_pool_id, string $a_title)
Checks whether a page with given title exists.
getUsages(bool $a_incl_hist=true)
get all usages of current media object
MDUpdateListener(string $a_element)
Meta data update listener.
static deleteAllPagesOfMediaPool(int $a_media_pool_id)
static lookupUsages(int $a_id, bool $a_incl_hist=true)
Lookup usages of media object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilPageObject Handles PageObjects of ILIAS Learning Modules (see ILIAS DTD)
static _exists(string $a_parent_type, int $a_id, string $a_lang="", bool $a_no_cache=false)
Checks whether page exists.
global $DIC
Definition: shib_login.php:26
$q
Definition: shib_logout.php:23