ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
31 include_once 'class.ilMDBase.php';
32 
33 class 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  if($this->db->autoExecute('il_meta_rights',
104  $this->__getFields(),
105  DB_AUTOQUERY_INSERT))
106  {
107  $this->setMetaId($this->db->getLastInsertId());
108 
109  return $this->getMetaId();
110  }
111  return false;
112  }
113 
114  function update()
115  {
116  global $ilDB;
117 
118  if($this->getMetaId())
119  {
120  if($this->db->autoExecute('il_meta_rights',
121  $this->__getFields(),
122  DB_AUTOQUERY_UPDATE,
123  "meta_rights_id = ".$ilDB->quote($this->getMetaId())))
124  {
125  return true;
126  }
127  }
128  return false;
129  }
130 
131  function delete()
132  {
133  global $ilDB;
134 
135  if($this->getMetaId())
136  {
137  $query = "DELETE FROM il_meta_rights ".
138  "WHERE meta_rights_id = ".$ilDB->quote($this->getMetaId());
139 
140  $this->db->query($query);
141 
142  return true;
143  }
144  return false;
145  }
146 
147 
148  function __getFields()
149  {
150  return array('rbac_id' => $this->getRBACId(),
151  'obj_id' => $this->getObjId(),
152  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
153  'costs' => ilUtil::prepareDBString($this->getCosts()),
154  'copyright_and_other_restrictions' => ilUtil::prepareDBString($this->getCopyrightAndOtherRestrictions()),
155  'description' => ilUtil::prepareDBString($this->getDescription()),
156  'description_language' => ilUtil::prepareDBString($this->getDescriptionLanguageCode()));
157  }
158 
159  function read()
160  {
161  global $ilDB;
162 
163  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
164 
165 
166  if($this->getMetaId())
167  {
168 
169  $query = "SELECT * FROM il_meta_rights ".
170  "WHERE meta_rights_id = ".$ilDB->quote($this->getMetaId());
171 
172 
173  $res = $this->db->query($query);
174  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
175  {
176  $this->setRBACId($row->rbac_id);
177  $this->setObjId($row->obj_id);
178  $this->setObjType($row->obj_type);
179  $this->setDescription(ilUtil::stripSlashes($row->description));
180  $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
181  $this->setCosts(ilUtil::stripSlashes($row->costs));
182  $this->setCopyrightAndOtherRestrictions(ilUtil::stripSlashes($row->copyright_and_other_restrictions));
183  }
184  return true;
185  }
186  return false;
187  }
188 
189  /*
190  * XML Export of all meta data
191  * @param object (xml writer) see class.ilMD2XML.php
192  *
193  */
194  function toXML(&$writer)
195  {
196  $writer->xmlStartTag('Rights',array('Costs' => $this->getCosts(),
197  'CopyrightAndOtherRestrictions' => $this->getCopyrightAndOtherRestrictions()));
198  $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()),$this->getDescription());
199  $writer->xmlEndTag('Rights');
200  }
201 
202  // STATIC
203  function _getId($a_rbac_id,$a_obj_id)
204  {
205  global $ilDB;
206 
207  $query = "SELECT meta_rights_id FROM il_meta_rights ".
208  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
209  "AND obj_id = ".$ilDB->quote($a_obj_id);
210 
211  $res = $ilDB->query($query);
212  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
213  {
214  return $row->meta_rights_id;
215  }
216  return false;
217  }
218 }
219 ?>