ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\MediaPool\MediaPoolRepository Class Reference

Media pool repository. More...

+ Collaboration diagram for ILIAS\MediaPool\MediaPoolRepository:

Public Member Functions

 __construct (?\ilDBInterface $db=null)
 
 getItems (int $pool_id, string $title_filter="", string $format_filter="", string $keyword_filter="", string $caption_filter="")
 

Protected Member Functions

 getMediaObjects (int $pool_id, string $title_filter="", string $format_filter="", string $keyword_filter='', string $caption_filter="")
 
 getContentSnippets (int $pool_id, string $title_filter="", string $format_filter="", string $keyword_filter='', string $caption_filter="")
 
 filterSubIDsByLOMKeywords (string $keywords, int $pool_id, string $type, int ... $sub_ids)
 

Protected Attributes

ilDBInterface $db
 
LOMServices $lom_services
 

Detailed Description

Media pool repository.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 31 of file class.MediaPoolRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\MediaPool\MediaPoolRepository::__construct ( ?\ilDBInterface  $db = null)

Definition at line 36 of file class.MediaPoolRepository.php.

37 {
38 global $DIC;
39 $this->db = ($db) ?: $DIC->database();
40 $this->lom_services = $DIC->learningObjectMetadata();
41 }
global $DIC
Definition: shib_login.php:26

References ILIAS\MediaPool\MediaPoolRepository\$db, and $DIC.

Member Function Documentation

◆ filterSubIDsByLOMKeywords()

ILIAS\MediaPool\MediaPoolRepository::filterSubIDsByLOMKeywords ( string  $keywords,
int  $pool_id,
string  $type,
int ...  $sub_ids 
)
protected
Returns
int[]

Definition at line 198 of file class.MediaPoolRepository.php.

203 : array {
204 if (trim($keywords) === "" || empty($sub_ids)) {
205 return $sub_ids;
206 }
207
208 $searcher = $this->lom_services->search();
209 $paths = $this->lom_services->paths();
210
211 $basic_clauses = [];
212 foreach (explode(' ', $keywords) as $keyword) {
213 $basic_clauses[] = $searcher->getClauseFactory()->getBasicClause(
214 $paths->keywords(),
215 Mode::CONTAINS,
216 $keyword
217 );
218 }
219 $search_clause = $searcher->getClauseFactory()->getJoinedClauses(
221 ...$basic_clauses
222 );
223
224 $filters = [];
225 foreach ($sub_ids as $sub_id) {
226 $filters[] = $searcher->getFilter($pool_id, $sub_id, $type);
227 }
228
229 $search_results = $searcher->execute($search_clause, null, null, ...$filters);
230 $filtered_sub_ids = [];
231 foreach ($search_results as $result) {
232 $filtered_sub_ids[] = $result->subID();
233 }
234 return $filtered_sub_ids;
235 }

◆ getContentSnippets()

ILIAS\MediaPool\MediaPoolRepository::getContentSnippets ( int  $pool_id,
string  $title_filter = "",
string  $format_filter = "",
string  $keyword_filter = '',
string  $caption_filter = "" 
)
protected
Returns
array[]

Definition at line 111 of file class.MediaPoolRepository.php.

117 : array {
118 // format filter snippets come with internal "pg" format
119 if (!in_array($format_filter, ["pg", ""])) {
120 return [];
121 }
122
123 // snippets do not have no caption
124 if ($caption_filter != "") {
125 return [];
126 }
127
128 $db = $this->db;
129
130 $query = "SELECT DISTINCT mep_tree.*, mep_item.* " .
131 "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) ";
132
133 $query .=
134 " WHERE mep_tree.mep_id = " . $db->quote($pool_id, "integer") .
135 " AND mep_item.type = " . $db->quote("pg", "text");
136
137 // filter
138 if (trim($title_filter) != "") { // title
139 $query .= " AND " . $db->like("mep_item.title", "text", "%" . trim($title_filter) . "%");
140 }
141
142 $objs = [];
143 $obj_ids = [];
144 $set = $db->query($query);
145 while ($rec = $db->fetchAssoc($set)) {
146 //$rec["foreign_id"] = $rec["obj_id"];
147 //$rec["obj_id"] = "";
148 $objs[] = $rec;
149 $obj_ids[] = $rec['obj_id'];
150 }
151
152 // Keyword filter
153 if ($keyword_filter) {
154 $res = $this->filterSubIDsByLOMKeywords($keyword_filter, $pool_id, 'mpg', ...$obj_ids);
155 $filtered = [];
156 foreach ($objs as $obj) {
157 if (in_array($obj['obj_id'], $res)) {
158 $filtered[] = $obj;
159 }
160 }
161 return $filtered;
162 }
163 return $objs;
164 }
filterSubIDsByLOMKeywords(string $keywords, int $pool_id, string $type, int ... $sub_ids)
like(string $column, string $type, string $value="?", bool $case_insensitive=true)
Generate a like subquery.
quote($value, string $type)
query(string $query)
Run a (read-only) Query on the database.
fetchAssoc(ilDBStatement $statement)
$res
Definition: ltiservices.php:69

◆ getItems()

ILIAS\MediaPool\MediaPoolRepository::getItems ( int  $pool_id,
string  $title_filter = "",
string  $format_filter = "",
string  $keyword_filter = "",
string  $caption_filter = "" 
)
Returns
array[]

Definition at line 169 of file class.MediaPoolRepository.php.

175 : array {
176 $mobs = $this->getMediaObjects(
177 $pool_id,
178 $title_filter,
179 $format_filter,
180 $keyword_filter,
181 $caption_filter
182 );
183
184 $snippets = $this->getContentSnippets(
185 $pool_id,
186 $title_filter,
187 $format_filter,
188 $keyword_filter,
189 $caption_filter
190 );
191
192 return \ilArrayUtil::sortArray(array_merge($mobs, $snippets), "title", "asc");
193 }
getContentSnippets(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="")

◆ getMediaObjects()

ILIAS\MediaPool\MediaPoolRepository::getMediaObjects ( int  $pool_id,
string  $title_filter = "",
string  $format_filter = "",
string  $keyword_filter = '',
string  $caption_filter = "" 
)
protected
Returns
array[]

Definition at line 46 of file class.MediaPoolRepository.php.

52 : array {
53 $db = $this->db;
54
55 $query = "SELECT DISTINCT mep_tree.*, object_data.* " .
56 "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) " .
57 " JOIN object_data ON (mep_item.foreign_id = object_data.obj_id) ";
58
59 if ($format_filter != "" or $caption_filter != '') {
60 $query .= " JOIN media_item ON (media_item.mob_id = object_data.obj_id) ";
61 }
62
63 $query .=
64 " WHERE mep_tree.mep_id = " . $db->quote($pool_id, "integer") .
65 " AND object_data.type = " . $db->quote("mob", "text");
66
67 // filter
68 if (trim($title_filter) != "") { // title
69 $query .= " AND " . $db->like("object_data.title", "text", "%" . trim($title_filter) . "%");
70 }
71 if (!in_array($format_filter, ["", "mob"])) { // format
72 $filter = ($format_filter === "unknown")
73 ? ""
74 : $format_filter;
75 $query .= " AND " . $db->equals("media_item.format", $filter, "text", true);
76 }
77 if (trim($caption_filter)) {
78 $query .= 'AND ' . $db->like('media_item.caption', 'text', '%' . trim($caption_filter) . '%');
79 }
80
81 $query .=
82 " ORDER BY object_data.title";
83
84 $objs = [];
85 $obj_ids = [];
86 $set = $db->query($query);
87 while ($rec = $db->fetchAssoc($set)) {
88 $obj_ids[] = $rec['obj_id'];
89 $rec["foreign_id"] = $rec["obj_id"];
90 $rec["obj_id"] = "";
91 $objs[] = $rec;
92 }
93
94 // Keyword filter
95 if ($keyword_filter) {
96 $res = $this->filterSubIDsByLOMKeywords($keyword_filter, 0, 'mob', ...$obj_ids);
97 $filtered = [];
98 foreach ($objs as $obj) {
99 if (in_array($obj['foreign_id'], $res)) {
100 $filtered[] = $obj;
101 }
102 }
103 return (array) $filtered;
104 }
105 return $objs;
106 }
equals(string $columns, $value, string $type, bool $emptyOrNull=false)

Field Documentation

◆ $db

ilDBInterface ILIAS\MediaPool\MediaPoolRepository::$db
protected

◆ $lom_services

LOMServices ILIAS\MediaPool\MediaPoolRepository::$lom_services
protected

Definition at line 34 of file class.MediaPoolRepository.php.


The documentation for this class was generated from the following file: