ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 function ilMDRights($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
36 {
37 parent::ilMDBase($a_rbac_id,
38 $a_obj_id,
39 $a_obj_type);
40 }
41
42 // SET/GET
43 function setCosts($a_costs)
44 {
45 switch($a_costs)
46 {
47 case 'Yes':
48 case 'No':
49 $this->costs = $a_costs;
50 return true;
51
52 default:
53 return false;
54 }
55 }
56 function getCosts()
57 {
58 return $this->costs;
59 }
61 {
62 switch($a_caor)
63 {
64 case 'Yes':
65 case 'No':
66 $this->caor = $a_caor;
67 return true;
68
69 default:
70 return false;
71 }
72 }
74 {
75 return $this->caor;
76 }
77 function setDescription($a_description)
78 {
79 $this->description = $a_description;
80 }
81 function getDescription()
82 {
83 return $this->description;
84 }
85 function setDescriptionLanguage(&$lng_obj)
86 {
87 if(is_object($lng_obj))
88 {
89 $this->description_language = $lng_obj;
90 }
91 }
93 {
94 return is_object($this->description_language) ? $this->description_language : false;
95 }
97 {
98 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
99 }
100
101 function save()
102 {
103 global $ilDB;
104
105 $fields = $this->__getFields();
106 $fields['meta_rights_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_rights'));
107
108 if($this->db->insert('il_meta_rights',$fields))
109 {
110 $this->setMetaId($next_id);
111 return $this->getMetaId();
112 }
113 return false;
114 }
115
116 function update()
117 {
118 global $ilDB;
119
120 if($this->getMetaId())
121 {
122 if($this->db->update('il_meta_rights',
123 $this->__getFields(),
124 array("meta_rights_id" => array('integer',$this->getMetaId()))))
125 {
126 return true;
127 }
128 }
129 return false;
130 }
131
132 function delete()
133 {
134 global $ilDB;
135
136 if($this->getMetaId())
137 {
138 $query = "DELETE FROM il_meta_rights ".
139 "WHERE meta_rights_id = ".$ilDB->quote($this->getMetaId() ,'integer');
140
141 $this->db->query($query);
142
143 return true;
144 }
145 return false;
146 }
147
148
149 function __getFields()
150 {
151 return array('rbac_id' => array('integer',$this->getRBACId()),
152 'obj_id' => array('integer',$this->getObjId()),
153 'obj_type' => array('text',$this->getObjType()),
154 'costs' => array('text',$this->getCosts()),
155 'cpr_and_or' => array('text',$this->getCopyrightAndOtherRestrictions()),
156 'description' => array('text',$this->getDescription()),
157 'description_language' => array('text',$this->getDescriptionLanguageCode()));
158 }
159
160 function read()
161 {
162 global $ilDB;
163
164 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
165
166
167 if($this->getMetaId())
168 {
169
170 $query = "SELECT * FROM il_meta_rights ".
171 "WHERE meta_rights_id = ".$ilDB->quote($this->getMetaId() ,'integer');
172
173
174 $res = $this->db->query($query);
175 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
176 {
177 $this->setRBACId($row->rbac_id);
178 $this->setObjId($row->obj_id);
179 $this->setObjType($row->obj_type);
180 $this->setDescription($row->description);
181 $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
182 $this->setCosts($row->costs);
183 $this->setCopyrightAndOtherRestrictions($row->cpr_and_or);
184 }
185 return true;
186 }
187 return false;
188 }
189
190 /*
191 * XML Export of all meta data
192 * @param object (xml writer) see class.ilMD2XML.php
193 *
194 */
195 function toXML(&$writer)
196 {
197 $writer->xmlStartTag('Rights',array('Cost' => $this->getCosts()
198 ? $this->getCosts()
199 : 'No',
200 'CopyrightAndOtherRestrictions' => $this->getCopyrightAndOtherRestrictions()
202 : 'No'));
203 include_once './Services/MetaData/classes/class.ilMDCopyrightSelectionEntry.php';
204 $writer->xmlElement(
205 'Description',array('Language' => $this->getDescriptionLanguageCode()
207 : 'en'),
209 );
210 $writer->xmlEndTag('Rights');
211 }
212
221 public function _lookupDescription($a_rbac_id,$a_obj_id)
222 {
223 global $ilDB;
224
225 $query = "SELECT description FROM il_meta_rights ".
226 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
227 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ";
228 $res = $ilDB->query($query);
229 $row = $res->fetchRow(DB_FETCHMODE_OBJECT);
230 return $row->description ? $row->description : '';
231 }
232
233 // STATIC
234 function _getId($a_rbac_id,$a_obj_id)
235 {
236 global $ilDB;
237
238 $query = "SELECT meta_rights_id FROM il_meta_rights ".
239 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
240 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
241
242 $res = $ilDB->query($query);
243 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
244 {
245 return $row->meta_rights_id;
246 }
247 return false;
248 }
249}
250?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
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()
ilMDRights($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
setCosts($a_costs)
getDescriptionLanguageCode()
setDescription($a_description)
setDescriptionLanguage(&$lng_obj)
_getId($a_rbac_id, $a_obj_id)
_lookupDescription($a_rbac_id, $a_obj_id)
Lookup description (copyright)
setCopyrightAndOtherRestrictions($a_caor)
toXML(&$writer)
global $ilDB