ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMDGeneral.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
32include_once 'class.ilMDBase.php';
33
34class ilMDGeneral extends ilMDBase
35{
37 {
38 $subs['Identifier'] = 'meta_identifier';
39 $subs['Language'] = 'meta_language';
40 $subs['Description'] = 'meta_description';
41 $subs['Keyword'] = 'meta_keyword';
42
43 return $subs;
44 }
45
46
47 // Subelements (Identifier, Language, Description, Keyword)
48 function &getIdentifierIds()
49 {
50 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier.php';
51
52 return ilMDIdentifier::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
53 }
54 function &getIdentifier($a_identifier_id)
55 {
56 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier.php';
57
58 if(!$a_identifier_id)
59 {
60 return false;
61 }
62 $ide = new ilMDIdentifier();
63 $ide->setMetaId($a_identifier_id);
64
65 return $ide;
66 }
67 function &addIdentifier()
68 {
69 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier.php';
70
71 $ide = new ilMDIdentifier($this->getRBACId(),$this->getObjId(),$this->getObjType());
72 $ide->setParentId($this->getMetaId());
73 $ide->setParentType('meta_general');
74
75 return $ide;
76 }
77 function &getLanguageIds()
78 {
79 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguage.php';
80
81 return ilMDLanguage::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
82 }
83 function &getLanguage($a_language_id)
84 {
85 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguage.php';
86
87 if(!$a_language_id)
88 {
89 return false;
90 }
91 $lan = new ilMDLanguage();
92 $lan->setMetaId($a_language_id);
93
94 return $lan;
95
96 }
97 function &addLanguage()
98 {
99 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguage.php';
100
101 $lan = new ilMDLanguage($this->getRBACId(),$this->getObjId(),$this->getObjType());
102 $lan->setParentId($this->getMetaId());
103 $lan->setParentType('meta_general');
104
105 return $lan;
106 }
108 {
109 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDDescription.php';
110
111 return ilMDDescription::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
112 }
113 function &getDescription($a_description_id)
114 {
115 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDDescription.php';
116
117
118 if(!$a_description_id)
119 {
120 return false;
121 }
122 $des = new ilMDDescription();
123 $des->setMetaId($a_description_id);
124
125 return $des;
126 }
127 function &addDescription()
128 {
129 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDDescription.php';
130
131 $des = new ilMDDescription($this->getRBACId(),$this->getObjId(),$this->getObjType());
132 $des->setParentId($this->getMetaId());
133 $des->setParentType('meta_general');
134
135 return $des;
136 }
137 function &getKeywordIds()
138 {
139 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDKeyword.php';
140
141 return ilMDKeyword::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_general');
142 }
143 function &getKeyword($a_keyword_id)
144 {
145 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDKeyword.php';
146
147 if(!$a_keyword_id)
148 {
149 return false;
150 }
151 $key = new ilMDKeyword();
152 $key->setMetaId($a_keyword_id);
153
154 return $key;
155 }
156 function &addKeyword()
157 {
158 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDKeyword.php';
159
160 $key = new ilMDKeyword($this->getRBACId(),$this->getObjId(),$this->getObjType());
161 $key->setParentId($this->getMetaId());
162 $key->setParentType('meta_general');
163
164 return $key;
165 }
166
167
168
169 // SET/GET
170 function setStructure($a_structure)
171 {
172 switch($a_structure)
173 {
174 case 'Atomic':
175 case 'Collection':
176 case 'Networked':
177 case 'Hierarchical':
178 case 'Linear':
179 $this->structure = $a_structure;
180 return true;
181
182 default:
183 return false;
184 }
185 }
186 function getStructure()
187 {
188 return $this->structure;
189 }
190 function setTitle($a_title)
191 {
192 $this->title = $a_title;
193 }
194 function getTitle()
195 {
196 return $this->title;
197 }
198 function setTitleLanguage(&$lng_obj)
199 {
200 if(is_object($lng_obj))
201 {
202 $this->title_language = $lng_obj;
203 }
204 }
206 {
207 return is_object($this->title_language) ? $this->title_language : false;
208 }
210 {
211 return is_object($this->title_language) ? $this->title_language->getLanguageCode() : false;
212 }
213
214 function setCoverage($a_coverage)
215 {
216 $this->coverage = $a_coverage;
217 }
218 function getCoverage()
219 {
220 return $this->coverage;
221 }
222
223 function setCoverageLanguage(&$lng_obj)
224 {
225 if(is_object($lng_obj))
226 {
227 $this->coverage_language =& $lng_obj;
228 }
229 }
231 {
232 return is_object($this->coverage_language) ? $this->coverage_language : false;
233 }
235 {
236 return is_object($this->coverage_language) ? $this->coverage_language->getLanguageCode() : false;
237 }
238
239
240 function save()
241 {
242 if($this->db->autoExecute('il_meta_general',
243 $this->__getFields(),
245 {
246 $this->setMetaId($this->db->getLastInsertId());
247
248 return $this->getMetaId();
249 }
250 return false;
251 }
252
253 function update()
254 {
255 global $ilDB;
256
257 if($this->getMetaId())
258 {
259 if($this->db->autoExecute('il_meta_general',
260 $this->__getFields(),
262 "meta_general_id = ".$ilDB->quote($this->getMetaId())))
263 {
264 return true;
265 }
266 }
267 return false;
268 }
269
270 function delete()
271 {
272 global $ilDB;
273
274 if(!$this->getMetaId())
275 {
276 return false;
277 }
278 // Identifier
279 foreach($this->getIdentifierIds() as $id)
280 {
281 $ide = $this->getIdentifier($id);
282 $ide->delete();
283 }
284
285 // Language
286 foreach($this->getLanguageIds() as $id)
287 {
288 $lan = $this->getLanguage($id);
289 $lan->delete();
290 }
291
292 // Description
293 foreach($this->getDescriptionIds() as $id)
294 {
295 $des = $this->getDescription($id);
296 $des->delete();
297 }
298
299 // Keyword
300 foreach($this->getKeywordIds() as $id)
301 {
302 $key = $this->getKeyword($id);
303 $key->delete();
304 }
305
306 if($this->getMetaId())
307 {
308 $query = "DELETE FROM il_meta_general ".
309 "WHERE meta_general_id = ".$ilDB->quote($this->getMetaId());
310
311 $this->db->query($query);
312
313 return true;
314 }
315
316
317 return false;
318 }
319
320
321 function __getFields()
322 {
323 return array('rbac_id' => $this->getRBACId(),
324 'obj_id' => $this->getObjId(),
325 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
326 'general_structure' => ilUtil::prepareDBString($this->getStructure()),
327 'title' => ilUtil::prepareDBString($this->getTitle()),
328 'title_language' => ilUtil::prepareDBString($this->getTitleLanguageCode()),
329 'coverage' => ilUtil::prepareDBString($this->getCoverage()),
330 'coverage_language' => ilUtil::prepareDBString($this->getCoverageLanguageCode()));
331 }
332
333 function read()
334 {
335 global $ilDB;
336
337 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
338
339 if($this->getMetaId())
340 {
341 $query = "SELECT * FROM il_meta_general ".
342 "WHERE meta_general_id = ".$ilDB->quote($this->getMetaId());
343
344 $res = $this->db->query($query);
345 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
346 {
347 $this->setRBACId($row->rbac_id);
348 $this->setObjId($row->obj_id);
349 $this->setObjType($row->obj_type);
350 $this->setStructure(ilUtil::stripSlashes($row->general_structure));
351 $this->setTitle(ilUtil::stripSlashes($row->title));
352 $this->setTitleLanguage(new ilMDLanguageItem($row->title_language));
353 $this->setCoverage(ilUtil::stripSlashes($row->coverage));
354 $this->setCoverageLanguage(new ilMDLanguageItem($row->coverage_language));
355 }
356 }
357 return true;
358 }
359
360 /*
361 * XML Export of all meta data
362 * @param object (xml writer) see class.ilMD2XML.php
363 *
364 */
365 function toXML(&$writer)
366 {
367 $writer->xmlStartTag('General',array('Structure' => $this->getStructure()));
368
369 // Identifier
370 foreach($this->getIdentifierIds() as $id)
371 {
372 $ide =& $this->getIdentifier($id);
373 $ide->toXML($writer);
374 }
375
376 // TItle
377 $writer->xmlElement('Title',array('Language' => $this->getTitleLanguageCode()),$this->getTitle());
378
379 // Language
380 foreach($this->getLanguageIds() as $id)
381 {
382 $lan =& $this->getLanguage($id);
383 $lan->toXML($writer);
384 }
385
386 // Description
387 foreach($this->getDescriptionIds() as $id)
388 {
389 $des =& $this->getDescription($id);
390 $des->toXML($writer);
391 }
392
393 // Keyword
394 foreach($this->getKeywordIds() as $id)
395 {
396 $key =& $this->getKeyword($id);
397 $key->toXML($writer);
398 }
399
400 // Copverage
401 if(strlen($this->getCoverage()))
402 {
403 $writer->xmlElement('Coverage',array('Language' => $this->getCoverageLanguageCode()),$this->getCoverage());
404 }
405 $writer->xmlEndTag('General');
406 }
407
408
409
410 // STATIC
411 function _getId($a_rbac_id,$a_obj_id)
412 {
413 global $ilDB;
414
415 $query = "SELECT meta_general_id FROM il_meta_general ".
416 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
417 "AND obj_id = ".$ilDB->quote($a_obj_id);
418
419
420 $res = $ilDB->query($query);
421 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
422 {
423 return $row->meta_general_id;
424 }
425 return false;
426 }
427}
428?>
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)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getDescription($a_description_id)
setStructure($a_structure)
setCoverage($a_coverage)
_getId($a_rbac_id, $a_obj_id)
& getIdentifier($a_identifier_id)
& getKeyword($a_keyword_id)
setTitle($a_title)
setCoverageLanguage(&$lng_obj)
& getLanguage($a_language_id)
setTitleLanguage(&$lng_obj)
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 _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
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
global $ilDB