ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMDRights.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
24
31include_once 'class.ilMDBase.php';
32
33class ilMDRights extends ilMDBase
34{
40 public static function lookupRightsByTypeAndCopyright(array $a_types, array $a_copyright)
41 {
42 global $DIC;
43
44 $db = $DIC->database();
45
46 $query = 'SELECT rbac_id FROM il_meta_rights ' .
47 'WHERE ' . $db->in('obj_type', $a_types, false, 'text') . ' ' .
48 'AND ' . $db->in('description', $a_copyright, false, 'text');
49 $res = $db->query($query);
50
52
53 $obj_ids = [];
54 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
55 $obj_ids[] = $row->rbac_id;
56 }
57 return $obj_ids;
58 }
59
60
61
62 // SET/GET
63 public function setCosts($a_costs)
64 {
65 switch ($a_costs) {
66 case 'Yes':
67 case 'No':
68 $this->costs = $a_costs;
69 return true;
70
71 default:
72 return false;
73 }
74 }
75 public function getCosts()
76 {
77 return $this->costs;
78 }
79 public function setCopyrightAndOtherRestrictions($a_caor)
80 {
81 switch ($a_caor) {
82 case 'Yes':
83 case 'No':
84 $this->caor = $a_caor;
85 return true;
86
87 default:
88 return false;
89 }
90 }
92 {
93 return $this->caor;
94 }
95 public function setDescription($a_description)
96 {
97 $this->description = $a_description;
98 }
99 public function getDescription()
100 {
101 return $this->description;
102 }
103 public function setDescriptionLanguage(&$lng_obj)
104 {
105 if (is_object($lng_obj)) {
106 $this->description_language = $lng_obj;
107 }
108 }
109 public function &getDescriptionLanguage()
110 {
111 return is_object($this->description_language) ? $this->description_language : false;
112 }
114 {
115 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
116 }
117
118 public function save()
119 {
120 global $DIC;
121
122 $ilDB = $DIC['ilDB'];
123
124 $fields = $this->__getFields();
125 $fields['meta_rights_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_rights'));
126
127 if ($this->db->insert('il_meta_rights', $fields)) {
128 $this->setMetaId($next_id);
129 return $this->getMetaId();
130 }
131 return false;
132 }
133
134 public function update()
135 {
136 global $DIC;
137
138 $ilDB = $DIC['ilDB'];
139
140 if ($this->getMetaId()) {
141 if ($this->db->update(
142 'il_meta_rights',
143 $this->__getFields(),
144 array("meta_rights_id" => array('integer',$this->getMetaId()))
145 )) {
146 return true;
147 }
148 }
149 return false;
150 }
151
152 public function delete()
153 {
154 global $DIC;
155
156 $ilDB = $DIC['ilDB'];
157
158 if ($this->getMetaId()) {
159 $query = "DELETE FROM il_meta_rights " .
160 "WHERE meta_rights_id = " . $ilDB->quote($this->getMetaId(), 'integer');
161
162 $this->db->query($query);
163
164 return true;
165 }
166 return false;
167 }
168
169
170 public function __getFields()
171 {
172 return array('rbac_id' => array('integer',$this->getRBACId()),
173 'obj_id' => array('integer',$this->getObjId()),
174 'obj_type' => array('text',$this->getObjType()),
175 'costs' => array('text',$this->getCosts()),
176 'cpr_and_or' => array('text',$this->getCopyrightAndOtherRestrictions()),
177 'description' => array('text',$this->getDescription()),
178 'description_language' => array('text',$this->getDescriptionLanguageCode()));
179 }
180
181 public function read()
182 {
183 global $DIC;
184
185 $ilDB = $DIC['ilDB'];
186
187 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
188
189
190 if ($this->getMetaId()) {
191 $query = "SELECT * FROM il_meta_rights " .
192 "WHERE meta_rights_id = " . $ilDB->quote($this->getMetaId(), 'integer');
193
194
195 $res = $this->db->query($query);
196 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
197 $this->setRBACId($row->rbac_id);
198 $this->setObjId($row->obj_id);
199 $this->setObjType($row->obj_type);
200 $this->setDescription($row->description);
201 $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
202 $this->setCosts($row->costs);
203 $this->setCopyrightAndOtherRestrictions($row->cpr_and_or);
204 }
205 return true;
206 }
207 return false;
208 }
209
210 /*
211 * XML Export of all meta data
212 * @param object (xml writer) see class.ilMD2XML.php
213 *
214 */
215 public function toXML(&$writer)
216 {
217 $writer->xmlStartTag('Rights', array('Cost' => $this->getCosts()
218 ? $this->getCosts()
219 : 'No',
220 'CopyrightAndOtherRestrictions' => $this->getCopyrightAndOtherRestrictions()
222 : 'No'));
223 include_once './Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php';
224 $writer->xmlElement(
225 'Description',
226 [
227 'Language' => $this->getDescriptionLanguageCode()
229 : 'en'
230 ],
232 );
233 $writer->xmlEndTag('Rights');
234 }
235
240 public function parseDescriptionFromImport($a_description)
241 {
242 $entry_id = ilMDCopyrightSelectionEntry::lookupCopyrightByText($a_description);
243 if (!$entry_id) {
244 $this->setDescription($a_description);
245 } else {
247 }
248 }
249
258 public static function _lookupDescription($a_rbac_id, $a_obj_id)
259 {
260 global $DIC;
261
262 $ilDB = $DIC['ilDB'];
263
264 $query = "SELECT description FROM il_meta_rights " .
265 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
266 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
267 $res = $ilDB->query($query);
268 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
269 return $row->description ? $row->description : '';
270 }
271
272 // STATIC
273 public static function _getId($a_rbac_id, $a_obj_id)
274 {
275 global $DIC;
276
277 $ilDB = $DIC['ilDB'];
278
279 $query = "SELECT meta_rights_id FROM il_meta_rights " .
280 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
281 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
282
283 $res = $ilDB->query($query);
284 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
285 return $row->meta_rights_id;
286 }
287 return false;
288 }
289}
An exception for terminatinating execution or to throw for unit testing.
static getLogger($a_component_id)
Get component logger.
setObjId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
static createIdentifier($a_entry_id)
Create identifier for entry id.
static _lookupCopyright($a_cp_string)
lookup copyright by entry id
getCopyrightAndOtherRestrictions()
& getDescriptionLanguage()
setCosts($a_costs)
parseDescriptionFromImport($a_description)
setDescription($a_description)
setDescriptionLanguage(&$lng_obj)
setCopyrightAndOtherRestrictions($a_caor)
toXML(&$writer)
static _getId($a_rbac_id, $a_obj_id)
static _lookupDescription($a_rbac_id, $a_obj_id)
Lookup description (copyright)
static lookupRightsByTypeAndCopyright(array $a_types, array $a_copyright)
global $DIC
Definition: goto.php:24
$query
foreach($_POST as $key=> $value) $res
global $ilDB