ILIAS  release_8 Revision v8.24
class.ilMDRights.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
25class ilMDRights extends ilMDBase
26{
27 private string $costs = '';
28 private string $caor = '';
29 private string $description = '';
31
37 public static function lookupRightsByTypeAndCopyright(array $a_types, array $a_copyright): array
38 {
39 global $DIC;
40
41 $db = $DIC->database();
42
43 $query = 'SELECT rbac_id FROM il_meta_rights ' .
44 'WHERE ' . $db->in('obj_type', $a_types, false, 'text') . ' ' .
45 'AND ' . $db->in('description', $a_copyright, false, 'text');
46 $res = $db->query($query);
47
49
50 $obj_ids = [];
51 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
52 $obj_ids[] = (int) $row->rbac_id;
53 }
54 return $obj_ids;
55 }
56
57 // SET/GET
58 public function setCosts(string $a_costs): bool
59 {
60 switch ($a_costs) {
61 case 'Yes':
62 case 'No':
63 $this->costs = $a_costs;
64 return true;
65
66 default:
67 return false;
68 }
69 }
70
71 public function getCosts(): string
72 {
73 return $this->costs;
74 }
75
76 public function setCopyrightAndOtherRestrictions(string $a_caor): bool
77 {
78 switch ($a_caor) {
79 case 'Yes':
80 case 'No':
81 $this->caor = $a_caor;
82 return true;
83
84 default:
85 return false;
86 }
87 }
88
89 public function getCopyrightAndOtherRestrictions(): string
90 {
91 return $this->caor;
92 }
93
94 public function setDescription(string $a_description): void
95 {
96 $this->description = $a_description;
97 }
98
99 public function getDescription(): string
100 {
101 return $this->description;
102 }
103
104 public function setDescriptionLanguage(ilMDLanguageItem $lng_obj): void
105 {
106 $this->description_language = $lng_obj;
107 }
108
110 {
111 return is_object($this->description_language) ? $this->description_language : null;
112 }
113
114 public function getDescriptionLanguageCode(): string
115 {
116 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : '';
117 }
118
119 public function save(): int
120 {
121 $fields = $this->__getFields();
122 $fields['meta_rights_id'] = array('integer', $next_id = $this->db->nextId('il_meta_rights'));
123
124 if ($this->db->insert('il_meta_rights', $fields)) {
125 $this->setMetaId($next_id);
126 return $this->getMetaId();
127 }
128 return 0;
129 }
130
131 public function update(): bool
132 {
133 return $this->getMetaId() && $this->db->update(
134 'il_meta_rights',
135 $this->__getFields(),
136 array("meta_rights_id" => array('integer', $this->getMetaId()))
137 );
138 }
139
140 public function delete(): bool
141 {
142 if ($this->getMetaId()) {
143 $query = "DELETE FROM il_meta_rights " .
144 "WHERE meta_rights_id = " . $this->db->quote($this->getMetaId(), 'integer');
145
146 $this->db->query($query);
147
148 return true;
149 }
150 return false;
151 }
152
156 public function __getFields(): array
157 {
158 return array(
159 'rbac_id' => array('integer', $this->getRBACId()),
160 'obj_id' => array('integer', $this->getObjId()),
161 'obj_type' => array('text', $this->getObjType()),
162 'costs' => array('text', $this->getCosts()),
163 'cpr_and_or' => array('text', $this->getCopyrightAndOtherRestrictions()),
164 'description' => array('text', $this->getDescription()),
165 'description_language' => array('text', $this->getDescriptionLanguageCode())
166 );
167 }
168
169 public function read(): bool
170 {
171 if ($this->getMetaId()) {
172 $query = "SELECT * FROM il_meta_rights " .
173 "WHERE meta_rights_id = " . $this->db->quote($this->getMetaId(), 'integer');
174
175 $res = $this->db->query($query);
176 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
177 $this->setRBACId((int) $row->rbac_id);
178 $this->setObjId((int) $row->obj_id);
179 $this->setObjType((string) $row->obj_type);
180 $this->setDescription((string) $row->description);
181 $this->setDescriptionLanguage(new ilMDLanguageItem((string) $row->description_language));
182 $this->setCosts((string) $row->costs);
183 $this->setCopyrightAndOtherRestrictions((string) $row->cpr_and_or);
184 }
185 return true;
186 }
187 return false;
188 }
189
190 public function toXML(ilXmlWriter $writer): void
191 {
192 $writer->xmlStartTag('Rights', array(
193 'Cost' => $this->getCosts() ?: 'No',
194 'CopyrightAndOtherRestrictions' => $this->getCopyrightAndOtherRestrictions() ?: 'No'
195 ));
196
197 $writer->xmlElement(
198 'Description',
199 [
200 'Language' => $this->getDescriptionLanguageCode() ?: 'en'
201 ],
203 );
204 $writer->xmlEndTag('Rights');
205 }
206
207 public function parseDescriptionFromImport(string $a_description): void
208 {
210 if (!$entry_id) {
211 $this->setDescription($a_description);
212 } else {
214 }
215 }
216
217 public static function _lookupDescription(int $a_rbac_id, int $a_obj_id): string
218 {
219 global $DIC;
220
221 $ilDB = $DIC->database();
222
223 $query = "SELECT description FROM il_meta_rights " .
224 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
225 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
226 $res = $ilDB->query($query);
227 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
228
229 if (isset($row) && isset($row->description)) {
230 return $row->description;
231 }
232 return '';
233 }
234
235 // STATIC
236 public static function _getId(int $a_rbac_id, int $a_obj_id): int
237 {
238 global $DIC;
239
240 $ilDB = $DIC->database();
241
242 $query = "SELECT meta_rights_id FROM il_meta_rights " .
243 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
244 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
245
246 $res = $ilDB->query($query);
247 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
248 return (int) $row->meta_rights_id;
249 }
250 return 0;
251 }
252}
static getLogger(string $a_component_id)
Get component logger.
setObjType(string $a_type)
ilDBInterface $db
setObjId(int $a_id)
setMetaId(int $a_meta_id, bool $a_read_data=true)
setRBACId(int $a_id)
static lookupCopyrightFromImport(string $copyright_text)
static _lookupCopyrightForExport(string $a_cp_string)
static _getId(int $a_rbac_id, int $a_obj_id)
getCopyrightAndOtherRestrictions()
string $description
static _lookupDescription(int $a_rbac_id, int $a_obj_id)
setCosts(string $a_costs)
toXML(ilXmlWriter $writer)
parseDescriptionFromImport(string $a_description)
setCopyrightAndOtherRestrictions(string $a_caor)
setDescriptionLanguage(ilMDLanguageItem $lng_obj)
ilMDLanguageItem $description_language
setDescription(string $a_description)
static lookupRightsByTypeAndCopyright(array $a_types, array $a_copyright)
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)
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
global $DIC
Definition: feed.php:28
query(string $query)
Run a (read-only) Query on the database.
in(string $field, array $values, bool $negate=false, string $type="")
$res
Definition: ltiservices.php:69
$query