3 declare(strict_types=1);
34 $this->keyword = $a_keyword;
44 $this->keyword_language = $lng_obj;
49 return is_object($this->keyword_language) ? $this->keyword_language : null;
54 return is_object($this->keyword_language) ? $this->keyword_language->getLanguageCode() :
'';
60 $fields[
'meta_keyword_id'] = array(
'integer', $next_id = $this->db->nextId(
'il_meta_keyword'));
62 if ($this->db->insert(
'il_meta_keyword', $fields)) {
71 return $this->
getMetaId() && $this->db->update(
74 array(
"meta_keyword_id" => array(
'integer', $this->
getMetaId()))
78 public function delete():
bool 81 $query =
"DELETE FROM il_meta_keyword " .
82 "WHERE meta_keyword_id = " . $this->db->quote($this->
getMetaId(),
'integer');
96 'rbac_id' => array(
'integer', $this->
getRBACId()),
97 'obj_id' => array(
'integer', $this->
getObjId()),
98 'obj_type' => array(
'text', $this->
getObjType()),
100 'parent_id' => array(
'integer', $this->
getParentId()),
101 'keyword' => array(
'text', $this->
getKeyword()),
109 $query =
"SELECT * FROM il_meta_keyword " .
110 "WHERE meta_keyword_id = " . $this->db->quote($this->
getMetaId(),
'integer');
115 $this->
setObjId((
int) $row->obj_id);
142 public static function _getIds(
int $a_rbac_id,
int $a_obj_id,
int $a_parent_id,
string $a_parent_type): array
146 $ilDB = $DIC->database();
148 $query =
"SELECT meta_keyword_id FROM il_meta_keyword " .
149 "WHERE rbac_id = " .
$ilDB->quote($a_rbac_id,
'integer') .
" " .
150 "AND obj_id = " .
$ilDB->quote($a_obj_id,
'integer') .
" " .
151 "AND parent_id = " .
$ilDB->quote($a_parent_id,
'integer') .
" " .
152 "AND parent_type = " .
$ilDB->quote($a_parent_type,
'text') .
" " .
153 "ORDER BY meta_keyword_id ";
158 $ids[] = (
int) $row->meta_keyword_id;
170 $ilDB = $DIC->database();
171 $ilObjDataCache = $DIC[
'ilObjDataCache'];
173 $query =
"SELECT keyword,keyword_language " .
174 "FROM il_meta_keyword " .
175 "WHERE rbac_id = " .
$ilDB->quote($a_rbac_id,
'integer') .
" " .
176 "AND obj_id = " .
$ilDB->quote($a_obj_id,
'integer') .
" " .
177 "AND obj_type = " .
$ilDB->quote($a_type,
'text') .
" ";
182 $keywords[$row->keyword_language][] = $row->keyword;
194 foreach (self::_getKeywordsByLanguage($a_rbac_id, $a_obj_id, $a_type) as $lng_code => $keywords) {
195 $key_string[$lng_code] = implode(
",", $keywords);
203 public static function _searchKeywords(
string $a_query,
string $a_type,
int $a_rbac_id = 0): array
207 $ilDB = $DIC->database();
211 foreach ((array) explode(
' ', $a_query) as $part) {
215 $qs .= (
$ilDB->like(
'keyword',
'text', $part) .
' ');
219 $query =
"SELECT obj_id FROM il_meta_keyword " .
220 "WHERE rbac_id = " .
$ilDB->quote($a_rbac_id,
'integer') .
' ' .
221 'AND obj_type = ' .
$ilDB->quote($a_type,
'text') .
' ' .
224 $query =
"SELECT obj_id FROM il_meta_keyword " .
225 'WHERE obj_type = ' .
$ilDB->quote($a_type,
'text') .
' ' .
232 $obj_ids[] = $row->obj_id;
245 $ilDB = $DIC->database();
247 $query =
"SELECT DISTINCT keyword FROM il_meta_keyword " .
248 'WHERE obj_type = ' .
$ilDB->quote($a_type,
'text') .
' ' .
249 'AND ' .
$ilDB->like(
'keyword',
'text',
'%' . trim($a_query) .
'%') .
' ';
252 $query .=
"AND rbac_id = " .
$ilDB->quote($a_rbac_id,
'integer') .
' ';
258 $kws[] = $row->keyword;
263 public static function lookupKeywords(
int $a_rbac_id,
int $a_obj_id,
bool $a_return_ids =
false): array
267 $ilDB = $DIC->database();
269 $query =
"SELECT * FROM il_meta_keyword " .
270 "WHERE rbac_id = " .
$ilDB->quote($a_rbac_id,
'integer') .
' ' .
271 "AND obj_id = " .
$ilDB->quote($a_obj_id,
'integer') .
' ';
275 if (!$a_return_ids) {
276 if (is_string($row->keyword) && $row->keyword !==
'') {
277 $kws[] = $row->keyword;
280 $kws[] = $row->meta_keyword_id;
289 $new_keywords = array();
290 foreach ($a_keywords as
$lang => $keywords) {
291 foreach ((array) $keywords as $keyword) {
292 $keyword = trim($keyword);
293 if ($keyword !==
"" && !(isset($new_keywords[
$lang]) && in_array($keyword, $new_keywords[$lang],
true))) {
302 $lang = $md_key->getKeywordLanguageCode();
305 if (is_array($new_keywords[
$lang] ??
false) && in_array($md_key->getKeyword(), $new_keywords[
$lang],
true)) {
306 unset($new_keywords[$lang][array_search($md_key->getKeyword(), $new_keywords[
$lang],
true)]);
313 foreach ($new_keywords as
$lang => $key_arr) {
314 foreach ($key_arr as $keyword) {
315 if ($keyword !==
"") {
static _getKeywordsByLanguage(int $a_rbac_id, int $a_obj_id, string $a_type)
static _getMatchingKeywords(string $a_query, string $a_type, int $a_rbac_id=0)
static _getKeywordsByLanguageAsString(int $a_rbac_id, int $a_obj_id, string $a_type)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
setKeyword(string $a_keyword)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
toXML(ilXmlWriter $writer)
static updateKeywords(ilMDGeneral $a_md_section, array $a_keywords)
static lookupKeywords(int $a_rbac_id, int $a_obj_id, bool $a_return_ids=false)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
ilMDLanguageItem $keyword_language
getKeyword(int $a_keyword_id)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
setParentType(string $a_parent_type)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setKeywordLanguage(ilMDLanguageItem $lng_obj)
setObjType(string $a_type)
static _searchKeywords(string $a_query, string $a_type, int $a_rbac_id=0)