ILIAS  release_8 Revision v8.24
class.MediaPoolRepository.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
22
28{
29 protected \ilDBInterface $db;
30
31 public function __construct(\ilDBInterface $db = null)
32 {
33 global $DIC;
34 $this->db = ($db) ?: $DIC->database();
35 }
36
40 protected function getMediaObjects(
41 int $pool_id,
42 string $title_filter = "",
43 string $format_filter = "",
44 string $keyword_filter = '',
45 string $caption_filter = ""
46 ): array {
47 $db = $this->db;
48
49 $query = "SELECT DISTINCT mep_tree.*, object_data.* " .
50 "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) " .
51 " JOIN object_data ON (mep_item.foreign_id = object_data.obj_id) ";
52
53 if ($format_filter != "" or $caption_filter != '') {
54 $query .= " JOIN media_item ON (media_item.mob_id = object_data.obj_id) ";
55 }
56
57 $query .=
58 " WHERE mep_tree.mep_id = " . $db->quote($pool_id, "integer") .
59 " AND object_data.type = " . $db->quote("mob", "text");
60
61 // filter
62 if (trim($title_filter) != "") { // title
63 $query .= " AND " . $db->like("object_data.title", "text", "%" . trim($title_filter) . "%");
64 }
65 if (!in_array($format_filter, ["", "mob"])) { // format
66 $filter = ($format_filter === "unknown")
67 ? ""
68 : $format_filter;
69 $query .= " AND " . $db->equals("media_item.format", $filter, "text", true);
70 }
71 if (trim($caption_filter)) {
72 $query .= 'AND ' . $db->like('media_item.caption', 'text', '%' . trim($caption_filter) . '%');
73 }
74
75 $query .=
76 " ORDER BY object_data.title";
77
78 $objs = array();
79 $set = $db->query($query);
80 while ($rec = $db->fetchAssoc($set)) {
81 $rec["foreign_id"] = $rec["obj_id"];
82 $rec["obj_id"] = "";
83 $objs[] = $rec;
84 }
85
86 // Keyword filter
87 if ($keyword_filter) {
88 $res = \ilMDKeyword::_searchKeywords($keyword_filter, 'mob', 0);
89
90 foreach ($objs as $obj) {
91 if (in_array($obj['foreign_id'], $res)) {
92 $filtered[] = $obj;
93 }
94 }
95 return (array) $filtered;
96 }
97 return $objs;
98 }
99
103 protected function getContentSnippets(
104 int $pool_id,
105 string $title_filter = "",
106 string $format_filter = "",
107 string $keyword_filter = '',
108 string $caption_filter = ""
109 ): array {
110 // format filter snippets come with internal "pg" format
111 if (!in_array($format_filter, ["pg", ""])) {
112 return [];
113 }
114
115 // snippets do not have no caption
116 if ($caption_filter != "") {
117 return [];
118 }
119
120 $db = $this->db;
121
122 $query = "SELECT DISTINCT mep_tree.*, mep_item.* " .
123 "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) ";
124
125 $query .=
126 " WHERE mep_tree.mep_id = " . $db->quote($pool_id, "integer") .
127 " AND mep_item.type = " . $db->quote("pg", "text");
128
129 // filter
130 if (trim($title_filter) != "") { // title
131 $query .= " AND " . $db->like("mep_item.title", "text", "%" . trim($title_filter) . "%");
132 }
133
134 $objs = array();
135 $set = $db->query($query);
136 while ($rec = $db->fetchAssoc($set)) {
137 //$rec["foreign_id"] = $rec["obj_id"];
138 //$rec["obj_id"] = "";
139 $objs[] = $rec;
140 }
141
142 // Keyword filter
143 if ($keyword_filter) {
144 include_once './Services/MetaData/classes/class.ilMDKeyword.php';
145 $res = \ilMDKeyword::_searchKeywords($keyword_filter, 'mpg', $pool_id);
146 foreach ($objs as $obj) {
147 if (in_array($obj['obj_id'], $res)) {
148 $filtered[] = $obj;
149 }
150 }
151 return (array) $filtered;
152 }
153 return $objs;
154 }
155
159 public function getItems(
160 int $pool_id,
161 string $title_filter = "",
162 string $format_filter = "",
163 string $keyword_filter = "",
164 string $caption_filter = ""
165 ): array {
166 $mobs = $this->getMediaObjects(
167 $pool_id,
168 $title_filter,
169 $format_filter,
170 $keyword_filter,
171 $caption_filter
172 );
173
174 $snippets = $this->getContentSnippets(
175 $pool_id,
176 $title_filter,
177 $format_filter,
178 $keyword_filter,
179 $caption_filter
180 );
181
182 return \ilArrayUtil::sortArray(array_merge($mobs, $snippets), "title", "asc");
183 }
184}
getContentSnippets(int $pool_id, string $title_filter="", string $format_filter="", string $keyword_filter='', string $caption_filter="")
getItems(int $pool_id, string $title_filter="", string $format_filter="", string $keyword_filter="", string $caption_filter="")
getMediaObjects(int $pool_id, string $title_filter="", string $format_filter="", string $keyword_filter='', string $caption_filter="")
static _searchKeywords(string $a_query, string $a_type, int $a_rbac_id=0)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
$mobs
Definition: imgupload.php:70
Interface ilDBInterface.
like(string $column, string $type, string $value="?", bool $case_insensitive=true)
Generate a like subquery.
equals(string $columns, $value, string $type, bool $emptyOrNull=false)
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)
$res
Definition: ltiservices.php:69
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query