ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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="")
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Media pool repository.

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

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

Constructor & Destructor Documentation

◆ __construct()

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

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

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

32  {
33  global $DIC;
34  $this->db = ($db) ?: $DIC->database();
35  }
global $DIC
Definition: feed.php:28

Member Function Documentation

◆ 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 104 of file class.MediaPoolRepository.php.

References ILIAS\MediaPool\MediaPoolRepository\$db, $res, ilMDKeyword\_searchKeywords(), and ilDBInterface\quote().

Referenced by ILIAS\MediaPool\MediaPoolRepository\getItems().

110  : array {
111  // format filter snippets come with internal "pg" format
112  if (!in_array($format_filter, ["pg", ""])) {
113  return [];
114  }
115 
116  // snippets do not have no caption
117  if ($caption_filter != "") {
118  return [];
119  }
120 
121  $db = $this->db;
122 
123  $query = "SELECT DISTINCT mep_tree.*, mep_item.* " .
124  "FROM mep_tree JOIN mep_item ON (mep_tree.child = mep_item.obj_id) ";
125 
126  $query .=
127  " WHERE mep_tree.mep_id = " . $db->quote($pool_id, "integer") .
128  " AND mep_item.type = " . $db->quote("pg", "text");
129 
130  // filter
131  if (trim($title_filter) != "") { // title
132  $query .= " AND " . $db->like("mep_item.title", "text", "%" . trim($title_filter) . "%");
133  }
134 
135  $objs = array();
136  $set = $db->query($query);
137  while ($rec = $db->fetchAssoc($set)) {
138  //$rec["foreign_id"] = $rec["obj_id"];
139  //$rec["obj_id"] = "";
140  $objs[] = $rec;
141  }
142 
143  // Keyword filter
144  if ($keyword_filter) {
145  include_once './Services/MetaData/classes/class.ilMDKeyword.php';
146  $res = \ilMDKeyword::_searchKeywords($keyword_filter, 'mpg', $pool_id);
147  $filtered = [];
148  foreach ($objs as $obj) {
149  if (in_array($obj['obj_id'], $res)) {
150  $filtered[] = $obj;
151  }
152  }
153  return (array) $filtered;
154  }
155  return $objs;
156  }
$res
Definition: ltiservices.php:69
fetchAssoc(ilDBStatement $statement)
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.
static _searchKeywords(string $a_query, string $a_type, int $a_rbac_id=0)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 161 of file class.MediaPoolRepository.php.

References ILIAS\MediaPool\MediaPoolRepository\getContentSnippets(), and ILIAS\MediaPool\MediaPoolRepository\getMediaObjects().

167  : array {
168  $mobs = $this->getMediaObjects(
169  $pool_id,
170  $title_filter,
171  $format_filter,
172  $keyword_filter,
173  $caption_filter
174  );
175 
176  $snippets = $this->getContentSnippets(
177  $pool_id,
178  $title_filter,
179  $format_filter,
180  $keyword_filter,
181  $caption_filter
182  );
183 
184  return \ilArrayUtil::sortArray(array_merge($mobs, $snippets), "title", "asc");
185  }
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="")
+ Here is the call graph for this function:

◆ 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 40 of file class.MediaPoolRepository.php.

References ILIAS\MediaPool\MediaPoolRepository\$db, $res, ilMDKeyword\_searchKeywords(), and ilDBInterface\quote().

Referenced by ILIAS\MediaPool\MediaPoolRepository\getItems().

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  $filtered = [];
91  foreach ($objs as $obj) {
92  if (in_array($obj['foreign_id'], $res)) {
93  $filtered[] = $obj;
94  }
95  }
96  return (array) $filtered;
97  }
98  return $objs;
99  }
$res
Definition: ltiservices.php:69
equals(string $columns, $value, string $type, bool $emptyOrNull=false)
fetchAssoc(ilDBStatement $statement)
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.
static _searchKeywords(string $a_query, string $a_type, int $a_rbac_id=0)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $db


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