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