ILIAS  release_8 Revision v8.24
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 $md = new ilMD($this->pool->getId(), $this->getId(), $this->getMetadataType());
144 $md_gen = $md->getGeneral();
145
146 $item = new ilMediaPoolItem($this->getId());
147 $item->setTitle($md_gen->getTitle());
148 $item->update();
149
150 break;
151
152 default:
153 }
154 return true;
155 }
156
160 public function createMetaData(int $pool_id): bool
161 {
162 $ilUser = $this->user;
163
164 $md_creator = new ilMDCreator($pool_id, $this->getId(), $this->getMetadataType());
165 $md_creator->setTitle(self::lookupTitle($this->getId()));
166 $md_creator->setTitleLanguage($ilUser->getPref('language'));
167 $md_creator->setDescription("");
168 $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
169 $md_creator->setKeywordLanguage($ilUser->getPref('language'));
170 $md_creator->setLanguage($ilUser->getPref('language'));
171 $md_creator->create();
172
173 return true;
174 }
175
176 public function updateMetaData(): void
177 {
178 $md = new ilMD($this->pool->getId(), $this->getId(), $this->getMetadataType());
179 $md_gen = $md->getGeneral();
180 $md_gen->setTitle(self::lookupTitle($this->getId()));
181 $md_gen->update();
182 }
183
184
185 public function deleteMetaData(): void
186 {
187 // Delete meta data
188 $md = new ilMD($this->pool->getId(), $this->getId(), $this->getMetadataType());
189 $md->deleteAll();
190 }
191}
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: feed.php:28
$ilUser
Definition: imgupload.php:34