ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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{
35 // SET/GET
36 public function setCosts($a_costs)
37 {
38 switch ($a_costs) {
39 case 'Yes':
40 case 'No':
41 $this->costs = $a_costs;
42 return true;
43
44 default:
45 return false;
46 }
47 }
48 public function getCosts()
49 {
50 return $this->costs;
51 }
52 public function setCopyrightAndOtherRestrictions($a_caor)
53 {
54 switch ($a_caor) {
55 case 'Yes':
56 case 'No':
57 $this->caor = $a_caor;
58 return true;
59
60 default:
61 return false;
62 }
63 }
65 {
66 return $this->caor;
67 }
68 public function setDescription($a_description)
69 {
70 $this->description = $a_description;
71 }
72 public function getDescription()
73 {
74 return $this->description;
75 }
76 public function setDescriptionLanguage(&$lng_obj)
77 {
78 if (is_object($lng_obj)) {
79 $this->description_language = $lng_obj;
80 }
81 }
82 public function &getDescriptionLanguage()
83 {
84 return is_object($this->description_language) ? $this->description_language : false;
85 }
87 {
88 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
89 }
90
91 public function save()
92 {
93 global $ilDB;
94
95 $fields = $this->__getFields();
96 $fields['meta_rights_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_rights'));
97
98 if ($this->db->insert('il_meta_rights', $fields)) {
99 $this->setMetaId($next_id);
100 return $this->getMetaId();
101 }
102 return false;
103 }
104
105 public function update()
106 {
107 global $ilDB;
108
109 if ($this->getMetaId()) {
110 if ($this->db->update(
111 'il_meta_rights',
112 $this->__getFields(),
113 array("meta_rights_id" => array('integer',$this->getMetaId()))
114 )) {
115 return true;
116 }
117 }
118 return false;
119 }
120
121 public function delete()
122 {
123 global $ilDB;
124
125 if ($this->getMetaId()) {
126 $query = "DELETE FROM il_meta_rights " .
127 "WHERE meta_rights_id = " . $ilDB->quote($this->getMetaId(), 'integer');
128
129 $this->db->query($query);
130
131 return true;
132 }
133 return false;
134 }
135
136
137 public function __getFields()
138 {
139 return array('rbac_id' => array('integer',$this->getRBACId()),
140 'obj_id' => array('integer',$this->getObjId()),
141 'obj_type' => array('text',$this->getObjType()),
142 'costs' => array('text',$this->getCosts()),
143 'cpr_and_or' => array('text',$this->getCopyrightAndOtherRestrictions()),
144 'description' => array('text',$this->getDescription()),
145 'description_language' => array('text',$this->getDescriptionLanguageCode()));
146 }
147
148 public function read()
149 {
150 global $ilDB;
151
152 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
153
154
155 if ($this->getMetaId()) {
156 $query = "SELECT * FROM il_meta_rights " .
157 "WHERE meta_rights_id = " . $ilDB->quote($this->getMetaId(), 'integer');
158
159
160 $res = $this->db->query($query);
161 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
162 $this->setRBACId($row->rbac_id);
163 $this->setObjId($row->obj_id);
164 $this->setObjType($row->obj_type);
165 $this->setDescription($row->description);
166 $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
167 $this->setCosts($row->costs);
168 $this->setCopyrightAndOtherRestrictions($row->cpr_and_or);
169 }
170 return true;
171 }
172 return false;
173 }
174
175 /*
176 * XML Export of all meta data
177 * @param object (xml writer) see class.ilMD2XML.php
178 *
179 */
180 public function toXML(&$writer)
181 {
182 $writer->xmlStartTag('Rights', array('Cost' => $this->getCosts()
183 ? $this->getCosts()
184 : 'No',
185 'CopyrightAndOtherRestrictions' => $this->getCopyrightAndOtherRestrictions()
187 : 'No'));
188 include_once './Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php';
189 $writer->xmlElement(
190 'Description',
191 array('Language' => $this->getDescriptionLanguageCode()
193 : 'en'),
195 );
196 $writer->xmlEndTag('Rights');
197 }
198
207 public static function _lookupDescription($a_rbac_id, $a_obj_id)
208 {
209 global $ilDB;
210
211 $query = "SELECT description FROM il_meta_rights " .
212 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
213 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " ";
214 $res = $ilDB->query($query);
216 return $row->description ? $row->description : '';
217 }
218
219 // STATIC
220 public static function _getId($a_rbac_id, $a_obj_id)
221 {
222 global $ilDB;
223
224 $query = "SELECT meta_rights_id FROM il_meta_rights " .
225 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
226 "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
227
228 $res = $ilDB->query($query);
229 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
230 return $row->meta_rights_id;
231 }
232 return false;
233 }
234}
An exception for terminatinating execution or to throw for unit testing.
setObjId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
static lookupCopyyrightTitle($a_cp_string)
Lookup copyright title.
getCopyrightAndOtherRestrictions()
& getDescriptionLanguage()
setCosts($a_costs)
getDescriptionLanguageCode()
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)
$query
foreach($_POST as $key=> $value) $res
global $ilDB