ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 if ($this->db->autoExecute(
94 'il_meta_rights',
95 $this->__getFields(),
97 )) {
98 $this->setMetaId($this->db->getLastInsertId());
99
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->autoExecute(
111 'il_meta_rights',
112 $this->__getFields(),
114 "meta_rights_id = " . $ilDB->quote($this->getMetaId())
115 )) {
116 return true;
117 }
118 }
119 return false;
120 }
121
122 public function delete()
123 {
124 global $ilDB;
125
126 if ($this->getMetaId()) {
127 $query = "DELETE FROM il_meta_rights " .
128 "WHERE meta_rights_id = " . $ilDB->quote($this->getMetaId());
129
130 $this->db->query($query);
131
132 return true;
133 }
134 return false;
135 }
136
137
138 public function __getFields()
139 {
140 return array('rbac_id' => $this->getRBACId(),
141 'obj_id' => $this->getObjId(),
142 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
143 'costs' => ilUtil::prepareDBString($this->getCosts()),
144 'copyright_and_other_restrictions' => ilUtil::prepareDBString($this->getCopyrightAndOtherRestrictions()),
145 'description' => ilUtil::prepareDBString($this->getDescription()),
146 'description_language' => ilUtil::prepareDBString($this->getDescriptionLanguageCode()));
147 }
148
149 public function read()
150 {
151 global $ilDB;
152
153 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
154
155
156 if ($this->getMetaId()) {
157 $query = "SELECT * FROM il_meta_rights " .
158 "WHERE meta_rights_id = " . $ilDB->quote($this->getMetaId());
159
160
161 $res = $this->db->query($query);
162 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163 $this->setRBACId($row->rbac_id);
164 $this->setObjId($row->obj_id);
165 $this->setObjType($row->obj_type);
166 $this->setDescription(ilUtil::stripSlashes($row->description));
167 $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
168 $this->setCosts(ilUtil::stripSlashes($row->costs));
169 $this->setCopyrightAndOtherRestrictions(ilUtil::stripSlashes($row->copyright_and_other_restrictions));
170 }
171 return true;
172 }
173 return false;
174 }
175
176 /*
177 * XML Export of all meta data
178 * @param object (xml writer) see class.ilMD2XML.php
179 *
180 */
181 public function toXML(&$writer)
182 {
183 $writer->xmlStartTag('Rights', array('Costs' => $this->getCosts(),
184 'CopyrightAndOtherRestrictions' => $this->getCopyrightAndOtherRestrictions()));
185 $writer->xmlElement('Description', array('Language' => $this->getDescriptionLanguageCode()), $this->getDescription());
186 $writer->xmlEndTag('Rights');
187 }
188
189 // STATIC
190 public function _getId($a_rbac_id, $a_obj_id)
191 {
192 global $ilDB;
193
194 $query = "SELECT meta_rights_id FROM il_meta_rights " .
195 "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
196 "AND obj_id = " . $ilDB->quote($a_obj_id);
197
198 $res = $ilDB->query($query);
199 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
200 return $row->meta_rights_id;
201 }
202 return false;
203 }
204}
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)
getCopyrightAndOtherRestrictions()
& getDescriptionLanguage()
setCosts($a_costs)
getDescriptionLanguageCode()
setDescription($a_description)
setDescriptionLanguage(&$lng_obj)
_getId($a_rbac_id, $a_obj_id)
setCopyrightAndOtherRestrictions($a_caor)
toXML(&$writer)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
$query
foreach($_POST as $key=> $value) $res
global $ilDB