ILIAS  release_8 Revision v8.24
class.ilMDLanguage.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
27{
28 private ?ilMDLanguageItem $language = null;
29
30 public static function _lookupFirstLanguage(int $a_rbac_id, int $a_obj_id, string $a_obj_type): string
31 {
32 global $DIC;
33
34 $ilDB = $DIC->database();
35
36 $lang = '';
37 $query = "SELECT language FROM il_meta_language " .
38 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
39 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
40 "AND obj_type = " . $ilDB->quote($a_obj_type, 'text') . " " .
41 "AND parent_type = 'meta_general' " .
42 "ORDER BY meta_language_id ";
43 $ilDB->setLimit(1, 0);
44 $res = $ilDB->query($query);
45 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
46 $lang = $row->language;
47 }
48 return $lang;
49 }
50
51 // SET/GET
52 public function setLanguage(ilMDLanguageItem $lng_obj): void
53 {
54 $this->language = $lng_obj;
55 }
56
57 public function getLanguage(): ?ilMDLanguageItem
58 {
59 return is_object($this->language) ? $this->language : null;
60 }
61
62 public function getLanguageCode(): string
63 {
64 return is_object($this->language) ? $this->language->getLanguageCode() : '';
65 }
66
67 public function save(): int
68 {
69 $fields = $this->__getFields();
70 $fields['meta_language_id'] = array('integer', $next_id = $this->db->nextId('il_meta_language'));
71 if ($this->db->insert('il_meta_language', $fields)) {
72 $this->setMetaId($next_id);
73 return $this->getMetaId();
74 }
75 return 0;
76 }
77
78 public function update(): bool
79 {
80 return $this->getMetaId() && $this->db->update(
81 'il_meta_language',
82 $this->__getFields(),
83 array("meta_language_id" => array('integer', $this->getMetaId()))
84 );
85 }
86
87 public function delete(): bool
88 {
89 if ($this->getMetaId()) {
90 $query = "DELETE FROM il_meta_language " .
91 "WHERE meta_language_id = " . $this->db->quote($this->getMetaId(), 'integer');
92 $res = $this->db->manipulate($query);
93
94 return true;
95 }
96 return false;
97 }
98
102 public function __getFields(): array
103 {
104 return array(
105 'rbac_id' => array('integer', $this->getRBACId()),
106 'obj_id' => array('integer', $this->getObjId()),
107 'obj_type' => array('text', $this->getObjType()),
108 'parent_type' => array('text', $this->getParentType()),
109 'parent_id' => array('integer', $this->getParentId()),
110 'language' => array('text', $this->getLanguageCode())
111 );
112 }
113
114 public function read(): bool
115 {
116 if ($this->getMetaId()) {
117 $query = "SELECT * FROM il_meta_language " .
118 "WHERE meta_language_id = " . $this->db->quote($this->getMetaId(), 'integer');
119
120 $res = $this->db->query($query);
121 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
122 $this->setRBACId((int) $row->rbac_id);
123 $this->setObjId((int) $row->obj_id);
124 $this->setObjType($row->obj_type);
125 $this->setParentId((int) $row->parent_id);
126 $this->setParentType($row->parent_type);
127 $this->setLanguage(new ilMDLanguageItem($row->language ?? ''));
128 }
129 }
130 return true;
131 }
132
133 public function toXML(ilXmlWriter $writer): void
134 {
135 $writer->xmlElement(
136 'Language',
137 array(
138 'Language' => $this->getLanguageCode() ?: 'en'
139 ),
140 $this->getLanguage()
141 );
142 }
143
144 // STATIC
145
149 public static function _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type): array
150 {
151 global $DIC;
152
153 $ilDB = $DIC->database();
154
155 $query = "SELECT meta_language_id FROM il_meta_language " .
156 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
157 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
158 "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
159 "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
160
161 $res = $ilDB->query($query);
162 $ids = [];
163 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
164 $ids[] = (int) $row->meta_language_id;
165 }
166 return $ids;
167 }
168}
setObjType(string $a_type)
setParentType(string $a_parent_type)
setObjId(int $a_id)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setRBACId(int $a_id)
setParentId(int $a_id)
ilMDLanguageItem $language
static _lookupFirstLanguage(int $a_rbac_id, int $a_obj_id, string $a_obj_type)
static _getIds(int $a_rbac_id, int $a_obj_id, int $a_parent_id, string $a_parent_type)
toXML(ilXmlWriter $writer)
setLanguage(ilMDLanguageItem $lng_obj)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query
$lang
Definition: xapiexit.php:26