ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
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 103 of file class.MediaPoolRepository.php.

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

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

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  }
$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.
$query
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 159 of file class.MediaPoolRepository.php.

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

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  }
$mobs
Definition: imgupload.php:70
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, $query, $res, and ilMDKeyword\_searchKeywords().

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  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  }
$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.
$query
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: