ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMDMetaMetadata.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 
34 {
36  {
37  $subs['Identifier'] = 'meta_identifier';
38  $subs['Contribute'] = 'meta_contribute';
39 
40  return $subs;
41  }
42 
43 
44  // SUBELEMENTS
45  function &getIdentifierIds()
46  {
47  include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
48 
49  return ilMDIdentifier::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
50  }
51  function &getIdentifier($a_identifier_id)
52  {
53  include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
54 
55  if(!$a_identifier_id)
56  {
57  return false;
58  }
59  $ide = new ilMDIdentifier();
60  $ide->setMetaId($a_identifier_id);
61 
62  return $ide;
63  }
64  function &addIdentifier()
65  {
66  include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
67 
68  $ide = new ilMDIdentifier($this->getRBACId(),$this->getObjId(),$this->getObjType());
69  $ide->setParentId($this->getMetaId());
70  $ide->setParentType('meta_meta_data');
71 
72  return $ide;
73  }
74 
75  function &getContributeIds()
76  {
77  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
78 
79  return ilMDContribute::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
80  }
81  function &getContribute($a_contribute_id)
82  {
83  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
84 
85  if(!$a_contribute_id)
86  {
87  return false;
88  }
89  $con = new ilMDContribute();
90  $con->setMetaId($a_contribute_id);
91 
92  return $con;
93  }
94  function &addContribute()
95  {
96  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
97 
98  $con = new ilMDContribute($this->getRBACId(),$this->getObjId(),$this->getObjType());
99  $con->setParentId($this->getMetaId());
100  $con->setParentType('meta_meta_data');
101 
102  return $con;
103  }
104 
105 
106 
107  // SET/GET
108  function setMetaDataScheme($a_val)
109  {
110  $this->meta_data_scheme = $a_val;
111  }
112  function getMetaDataScheme()
113  {
114  // Fixed attribute
115  return 'LOM v 1.0';
116  }
117  function setLanguage(&$lng_obj)
118  {
119  if(is_object($lng_obj))
120  {
121  $this->language = $lng_obj;
122  }
123  }
124  function &getLanguage()
125  {
126  return is_object($this->language) ? $this->language : false;
127  }
128  function getLanguageCode()
129  {
130  return is_object($this->language) ? $this->language->getLanguageCode() : false;
131  }
132 
133 
134  function save()
135  {
136  global $ilDB;
137 
138  $fields = $this->__getFields();
139  $fields['meta_meta_data_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_meta_data'));
140 
141  if($this->db->insert('il_meta_meta_data',$fields))
142  {
143  $this->setMetaId($next_id);
144  return $this->getMetaId();
145  }
146  return false;
147  }
148 
149  function update()
150  {
151  global $ilDB;
152 
153  if($this->getMetaId())
154  {
155  if($this->db->update('il_meta_meta_data',
156  $this->__getFields(),
157  array("meta_meta_data_id" => array('integer',$this->getMetaId()))))
158  {
159  return true;
160  }
161  }
162  return false;
163  }
164 
165  function delete()
166  {
167  global $ilDB;
168 
169  if($this->getMetaId())
170  {
171  $query = "DELETE FROM il_meta_meta_data ".
172  "WHERE meta_meta_data_id = ".$ilDB->quote($this->getMetaId() ,'integer');
173  $res = $ilDB->manipulate($query);
174 
175 
176  foreach($this->getIdentifierIds() as $id)
177  {
178  $ide = $this->getIdentifier($id);
179  $ide->delete();
180  }
181 
182  foreach($this->getContributeIds() as $id)
183  {
184  $con = $this->getContribute($id);
185  $con->delete();
186  }
187  return true;
188  }
189 
190  return false;
191  }
192 
193 
194  function __getFields()
195  {
196  return array('rbac_id' => array('integer',$this->getRBACId()),
197  'obj_id' => array('integer',$this->getObjId()),
198  'obj_type' => array('text',$this->getObjType()),
199  'meta_data_scheme' => array('text',$this->getMetaDataScheme()),
200  'language' => array('text',$this->getLanguageCode()));
201  }
202 
203  function read()
204  {
205  global $ilDB;
206 
207  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
208 
209 
210  if($this->getMetaId())
211  {
212 
213  $query = "SELECT * FROM il_meta_meta_data ".
214  "WHERE meta_meta_data_id = ".$ilDB->quote($this->getMetaId() ,'integer');
215 
216 
217  $res = $this->db->query($query);
218  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
219  {
220  $this->setRBACId($row->rbac_id);
221  $this->setObjId($row->obj_id);
222  $this->setObjType($row->obj_type);
223  $this->setMetaDataScheme($row->meta_data_scheme);
224  $this->setLanguage(new ilMDLanguageItem($row->language));
225  }
226  return true;
227  }
228  return false;
229  }
230 
231  /*
232  * XML Export of all meta data
233  * @param object (xml writer) see class.ilMD2XML.php
234  *
235  */
236  function toXML(&$writer)
237  {
238  if($this->getMetaDataScheme())
239  {
240  $attr['MetadataScheme'] = $this->getMetaDataScheme();
241  }
242  if($this->getLanguageCode())
243  {
244  $attr['Language'] = $this->getLanguageCode();
245  }
246  $writer->xmlStartTag('Meta-Metadata',$attr ? $attr : null);
247 
248  // ELEMENT IDENTIFIER
249  $identifiers = $this->getIdentifierIds();
250  foreach($identifiers as $id)
251  {
252  $ide =& $this->getIdentifier($id);
253  $ide->toXML($writer);
254  }
255  if(!count($identifiers))
256  {
257  include_once 'Services/Metadata/classes/class.ilMDIdentifier.php';
258  $ide = new ilMDIdentifier($this->getRBACId(),$this->getObjId());
259  $ide->toXML($writer);
260  }
261 
262  // ELEMETN Contribute
263  $contributes = $this->getContributeIds();
264  foreach($contributes as $id)
265  {
266  $con =& $this->getContribute($id);
267  $con->toXML($writer);
268  }
269  if(!count($contributes))
270  {
271  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
272  $con = new ilMDContribute($this->getRBACId(),$this->getObjId());
273  $con->toXML($writer);
274  }
275 
276  $writer->xmlEndTag('Meta-Metadata');
277  }
278 
279  // STATIC
280  static function _getId($a_rbac_id,$a_obj_id)
281  {
282  global $ilDB;
283 
284  $query = "SELECT meta_meta_data_id FROM il_meta_meta_data ".
285  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
286  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
287 
288  $res = $ilDB->query($query);
289  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
290  {
291  return $row->meta_meta_data_id;
292  }
293  return false;
294  }
295 }
296 ?>
setObjType($a_type)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static _getId($a_rbac_id, $a_obj_id)
& getIdentifier($a_identifier_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjId($a_id)
setRBACId($a_id)
& getContribute($a_contribute_id)
Create styles array
The data for the language used.
global $ilDB