ILIAS  release_8 Revision v8.24
ilMDKeyword Class Reference
+ Inheritance diagram for ilMDKeyword:
+ Collaboration diagram for ilMDKeyword:

Public Member Functions

 setKeyword (string $a_keyword)
 
 getKeyword ()
 
 setKeywordLanguage (ilMDLanguageItem $lng_obj)
 
 getKeywordLanguage ()
 
 getKeywordLanguageCode ()
 
 save ()
 
 update ()
 
 delete ()
 
 __getFields ()
 
 read ()
 
 toXML (ilXmlWriter $writer)
 
- Public Member Functions inherited from ilMDBase
 __construct (int $a_rbac_id=0, int $a_obj_id=0, string $a_type='')
 constructor More...
 
 read ()
 
 setRBACId (int $a_id)
 
 getRBACId ()
 
 setObjId (int $a_id)
 
 getObjId ()
 
 setObjType (string $a_type)
 
 getObjType ()
 
 setMetaId (int $a_meta_id, bool $a_read_data=true)
 
 getMetaId ()
 
 setParentType (string $a_parent_type)
 
 getParentType ()
 
 setParentId (int $a_id)
 
 getParentId ()
 
 setExportMode (bool $a_export_mode=true)
 
 getExportMode ()
 
 validate ()
 
 update ()
 
 save ()
 
 delete ()
 
 toXML (ilXmlWriter $writer)
 

Static Public Member Functions

static _getIds (int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
 
static _getKeywordsByLanguage (int $a_rbac_id, int $a_obj_id, string $a_type)
 
static _getKeywordsByLanguageAsString (int $a_rbac_id, int $a_obj_id, string $a_type)
 
static _searchKeywords (string $a_query, string $a_type, int $a_rbac_id=0)
 
static _getMatchingKeywords (string $a_query, string $a_type, int $a_rbac_id=0)
 
static lookupKeywords (int $a_rbac_id, int $a_obj_id, bool $a_return_ids=false)
 
static updateKeywords (ilMDGeneral $a_md_section, array $a_keywords)
 

Private Attributes

string $keyword = ''
 
ilMDLanguageItem $keyword_language = null
 

Additional Inherited Members

- Protected Attributes inherited from ilMDBase
ilLogger $log
 
ilDBInterface $db
 

Detailed Description

Definition at line 26 of file class.ilMDKeyword.php.

Member Function Documentation

◆ __getFields()

ilMDKeyword::__getFields ( )
Returns
array<string, array<string, mixed>>

Definition at line 93 of file class.ilMDKeyword.php.

93 : array
94 {
95 return array(
96 'rbac_id' => array('integer', $this->getRBACId()),
97 'obj_id' => array('integer', $this->getObjId()),
98 'obj_type' => array('text', $this->getObjType()),
99 'parent_type' => array('text', $this->getParentType()),
100 'parent_id' => array('integer', $this->getParentId()),
101 'keyword' => array('text', $this->getKeyword()),
102 'keyword_language' => array('text', $this->getKeywordLanguageCode())
103 );
104 }

References getKeyword(), getKeywordLanguageCode(), ilMDBase\getObjId(), ilMDBase\getObjType(), ilMDBase\getParentId(), ilMDBase\getParentType(), and ilMDBase\getRBACId().

Referenced by save(), and update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getIds()

static ilMDKeyword::_getIds ( int  $a_rbac_id,
int  $a_obj_id,
int  $a_parent_id,
string  $a_parent_type 
)
static
Returns
int[]

Definition at line 142 of file class.ilMDKeyword.php.

142 : array
143 {
144 global $DIC;
145
146 $ilDB = $DIC->database();
147
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 ";
154
155 $res = $ilDB->query($query);
156 $ids = [];
157 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
158 $ids[] = (int) $row->meta_keyword_id;
159 }
160 return $ids;
161 }
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query

References $DIC, $ilDB, $query, $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\int().

Referenced by ilMDClassification\getKeywordIds(), and ilMDGeneral\getKeywordIds().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ _getKeywordsByLanguage()

static ilMDKeyword::_getKeywordsByLanguage ( int  $a_rbac_id,
int  $a_obj_id,
string  $a_type 
)
static
Returns
array<string, string[]>

Definition at line 166 of file class.ilMDKeyword.php.

166 : array
167 {
168 global $DIC;
169
170 $ilDB = $DIC->database();
171 $ilObjDataCache = $DIC['ilObjDataCache'];
172
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') . " ";
178 $res = $ilDB->query($query);
179 $keywords = [];
180 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
181 if ($row->keyword) {
182 $keywords[$row->keyword_language][] = $row->keyword;
183 }
184 }
185 return $keywords;
186 }

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

◆ _getKeywordsByLanguageAsString()

static ilMDKeyword::_getKeywordsByLanguageAsString ( int  $a_rbac_id,
int  $a_obj_id,
string  $a_type 
)
static
Returns
array<string, string>

Definition at line 191 of file class.ilMDKeyword.php.

191 : array
192 {
193 $key_string = [];
194 foreach (self::_getKeywordsByLanguage($a_rbac_id, $a_obj_id, $a_type) as $lng_code => $keywords) {
195 $key_string[$lng_code] = implode(",", $keywords);
196 }
197 return $key_string;
198 }

Referenced by ilMDUtils\_fillHTMLMetaTags().

+ Here is the caller graph for this function:

◆ _getMatchingKeywords()

static ilMDKeyword::_getMatchingKeywords ( string  $a_query,
string  $a_type,
int  $a_rbac_id = 0 
)
static
Returns
string[]

Definition at line 241 of file class.ilMDKeyword.php.

241 : array
242 {
243 global $DIC;
244
245 $ilDB = $DIC->database();
246
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) . '%') . ' ';
250
251 if ($a_rbac_id) {
252 $query .= "AND rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . ' ';
253 }
254
255 $res = $ilDB->query($query);
256 $kws = [];
257 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
258 $kws[] = $row->keyword;
259 }
260 return $kws;
261 }

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

Referenced by ilMDEditorGUI\keywordAutocomplete().

+ Here is the caller graph for this function:

◆ _searchKeywords()

static ilMDKeyword::_searchKeywords ( string  $a_query,
string  $a_type,
int  $a_rbac_id = 0 
)
static
Returns
int[]

Definition at line 203 of file class.ilMDKeyword.php.

203 : array
204 {
205 global $DIC;
206
207 $ilDB = $DIC->database();
208
209 $qs = 'AND ';
210 $counter = 0;
211 foreach ((array) explode(' ', $a_query) as $part) {
212 if ($counter++) {
213 $qs .= 'OR ';
214 }
215 $qs .= ($ilDB->like('keyword', 'text', $part) . ' ');
216 }
217
218 if ($a_rbac_id) {
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') . ' ' .
222 $qs;
223 } else {
224 $query = "SELECT obj_id FROM il_meta_keyword " .
225 'WHERE obj_type = ' . $ilDB->quote($a_type, 'text') . ' ' .
226 $qs;
227 }
228
229 $res = $ilDB->query($query);
230 $obj_ids = [];
231 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
232 $obj_ids[] = $row->obj_id;
233 }
234
235 return $obj_ids;
236 }

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

◆ delete()

ilMDKeyword::delete ( )

Reimplemented from ilMDBase.

Definition at line 78 of file class.ilMDKeyword.php.

78 : bool
79 {
80 if ($this->getMetaId()) {
81 $query = "DELETE FROM il_meta_keyword " .
82 "WHERE meta_keyword_id = " . $this->db->quote($this->getMetaId(), 'integer');
83 $res = $this->db->manipulate($query);
84
85 return true;
86 }
87 return false;
88 }

References $query, $res, and ilMDBase\getMetaId().

+ Here is the call graph for this function:

◆ getKeyword()

ilMDKeyword::getKeyword ( )

Definition at line 37 of file class.ilMDKeyword.php.

37 : string
38 {
39 return $this->keyword;
40 }

References $keyword.

Referenced by __getFields(), and toXML().

+ Here is the caller graph for this function:

◆ getKeywordLanguage()

ilMDKeyword::getKeywordLanguage ( )

Definition at line 47 of file class.ilMDKeyword.php.

48 {
49 return is_object($this->keyword_language) ? $this->keyword_language : null;
50 }

◆ getKeywordLanguageCode()

ilMDKeyword::getKeywordLanguageCode ( )

Definition at line 52 of file class.ilMDKeyword.php.

52 : string
53 {
54 return is_object($this->keyword_language) ? $this->keyword_language->getLanguageCode() : '';
55 }

Referenced by __getFields(), and toXML().

+ Here is the caller graph for this function:

◆ lookupKeywords()

static ilMDKeyword::lookupKeywords ( int  $a_rbac_id,
int  $a_obj_id,
bool  $a_return_ids = false 
)
static

Definition at line 263 of file class.ilMDKeyword.php.

263 : array
264 {
265 global $DIC;
266
267 $ilDB = $DIC->database();
268
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') . ' ';
272 $res = $ilDB->query($query);
273 $kws = [];
274 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
275 if (!$a_return_ids) {
276 if (is_string($row->keyword) && $row->keyword !== '') {
277 $kws[] = $row->keyword;
278 }
279 } else {
280 $kws[] = $row->meta_keyword_id;
281 }
282 }
283 return $kws;
284 }

References $DIC, $ilDB, $query, $res, and ilDBConstants\FETCHMODE_OBJECT.

◆ read()

ilMDKeyword::read ( )

Reimplemented from ilMDBase.

Definition at line 106 of file class.ilMDKeyword.php.

106 : bool
107 {
108 if ($this->getMetaId()) {
109 $query = "SELECT * FROM il_meta_keyword " .
110 "WHERE meta_keyword_id = " . $this->db->quote($this->getMetaId(), 'integer');
111
112 $res = $this->db->query($query);
113 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
114 $this->setRBACId((int) $row->rbac_id);
115 $this->setObjId((int) $row->obj_id);
116 $this->setObjType((string) $row->obj_type);
117 $this->setParentId((int) $row->parent_id);
118 $this->setParentType((string) $row->parent_type);
119 $this->setKeyword((string) $row->keyword);
120 $this->setKeywordLanguage(new ilMDLanguageItem($row->keyword_language ?? ''));
121 }
122 }
123 return true;
124 }
setObjType(string $a_type)
setParentType(string $a_parent_type)
setObjId(int $a_id)
setRBACId(int $a_id)
setParentId(int $a_id)
setKeywordLanguage(ilMDLanguageItem $lng_obj)
setKeyword(string $a_keyword)

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, ilMDBase\getMetaId(), setKeyword(), setKeywordLanguage(), ilMDBase\setObjId(), ilMDBase\setObjType(), ilMDBase\setParentId(), ilMDBase\setParentType(), and ilMDBase\setRBACId().

+ Here is the call graph for this function:

◆ save()

ilMDKeyword::save ( )

Reimplemented from ilMDBase.

Definition at line 57 of file class.ilMDKeyword.php.

57 : int
58 {
59 $fields = $this->__getFields();
60 $fields['meta_keyword_id'] = array('integer', $next_id = $this->db->nextId('il_meta_keyword'));
61
62 if ($this->db->insert('il_meta_keyword', $fields)) {
63 $this->setMetaId($next_id);
64 return $this->getMetaId();
65 }
66 return 0;
67 }
setMetaId(int $a_meta_id, bool $a_read_data=true)

References __getFields(), ilMDBase\getMetaId(), and ilMDBase\setMetaId().

+ Here is the call graph for this function:

◆ setKeyword()

ilMDKeyword::setKeyword ( string  $a_keyword)

Definition at line 32 of file class.ilMDKeyword.php.

32 : void
33 {
34 $this->keyword = $a_keyword;
35 }

Referenced by read().

+ Here is the caller graph for this function:

◆ setKeywordLanguage()

ilMDKeyword::setKeywordLanguage ( ilMDLanguageItem  $lng_obj)

Definition at line 42 of file class.ilMDKeyword.php.

42 : void
43 {
44 $this->keyword_language = $lng_obj;
45 }

Referenced by read().

+ Here is the caller graph for this function:

◆ toXML()

ilMDKeyword::toXML ( ilXmlWriter  $writer)

Reimplemented from ilMDBase.

Definition at line 126 of file class.ilMDKeyword.php.

126 : void
127 {
128 $writer->xmlElement(
129 'Keyword',
130 array(
131 'Language' => $this->getKeywordLanguageCode() ?: 'en'
132 ),
133 $this->getKeyword()
134 );
135 }
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)

References getKeyword(), getKeywordLanguageCode(), and ilXmlWriter\xmlElement().

+ Here is the call graph for this function:

◆ update()

ilMDKeyword::update ( )

Reimplemented from ilMDBase.

Definition at line 69 of file class.ilMDKeyword.php.

69 : bool
70 {
71 return $this->getMetaId() && $this->db->update(
72 'il_meta_keyword',
73 $this->__getFields(),
74 array("meta_keyword_id" => array('integer', $this->getMetaId()))
75 );
76 }

References __getFields(), and ilMDBase\getMetaId().

+ Here is the call graph for this function:

◆ updateKeywords()

static ilMDKeyword::updateKeywords ( ilMDGeneral  $a_md_section,
array  $a_keywords 
)
static

Definition at line 286 of file class.ilMDKeyword.php.

286 : void
287 {
288 // trim keywords
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))) {
294 $new_keywords[$lang][] = $keyword;
295 }
296 }
297 }
298
299 // update existing author entries (delete if not entered)
300 foreach ($ids = $a_md_section->getKeywordIds() as $id) {
301 $md_key = $a_md_section->getKeyword($id);
302 $lang = $md_key->getKeywordLanguageCode();
303
304 // entered keyword already exists
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)]);
307 } else { // existing keyword has not been entered again -> delete
308 $md_key->delete();
309 }
310 }
311
312 // insert entered, but not existing keywords
313 foreach ($new_keywords as $lang => $key_arr) {
314 foreach ($key_arr as $keyword) {
315 if ($keyword !== "") {
316 $md_key = $a_md_section->addKeyword();
317 $md_key->setKeyword(ilUtil::stripSlashes($keyword));
318 $md_key->setKeywordLanguage(new ilMDLanguageItem($lang));
319 $md_key->save();
320 }
321 }
322 }
323 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
getKeyword(int $a_keyword_id)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$lang
Definition: xapiexit.php:26

References $id, $keyword, $lang, ilMDGeneral\addKeyword(), ilMDGeneral\getKeyword(), ilMDGeneral\getKeywordIds(), and ilUtil\stripSlashes().

Referenced by ilObjLTIConsumerGUI\initMetadata(), and ilMDEditorGUI\updateQuickEdit().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $keyword

string ilMDKeyword::$keyword = ''
private

Definition at line 28 of file class.ilMDKeyword.php.

Referenced by getKeyword(), and updateKeywords().

◆ $keyword_language

ilMDLanguageItem ilMDKeyword::$keyword_language = null
private

Definition at line 29 of file class.ilMDKeyword.php.


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