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