ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMDRelation.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
33class ilMDRelation extends ilMDBase
34{
35 function ilMDRelation($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
43 // METHODS OF CHILD OBJECTS (Taxon)
45 {
46 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier_.php';
47
48 return ilMDIdentifier_::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_relation');
49 }
50 function &getIdentifier_($a_identifier__id)
51 {
52 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier_.php';
53
54 if(!$a_identifier__id)
55 {
56 return false;
57 }
58 $ide =& new ilMDIdentifier_();
59 $ide->setMetaId($a_identifier__id);
60
61 return $ide;
62 }
63 function &addIdentifier_()
64 {
65 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier_.php';
66
67 $ide =& new ilMDIdentifier_($this->getRBACId(),$this->getObjId(),$this->getObjType());
68 $ide->setParentId($this->getMetaId());
69 $ide->setParentType('meta_relation');
70
71 return $ide;
72 }
73
75 {
76 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDDescription.php';
77
78 return ilMdDescription::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_relation');
79 }
80 function &getDescription($a_description_id)
81 {
82 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDDescription.php';
83
84 if(!$a_description_id)
85 {
86 return false;
87 }
88 $des =& new ilMDDescription();
89 $des->setMetaId($a_description_id);
90
91 return $des;
92 }
93 function &addDescription()
94 {
95 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDDescription.php';
96
97 $des =& new ilMDDescription($this->getRBACId(),$this->getObjId(),$this->getObjType());
98 $des->setParentId($this->getMetaId());
99 $des->setParentType('meta_relation');
100
101 return $des;
102 }
103 // SET/GET
104 function setKind($a_kind)
105 {
106 switch($a_kind)
107 {
108 case 'IsPartOf':
109 case 'HasPart':
110 case 'IsVersionOf':
111 case 'HasVersion':
112 case 'IsFormatOf':
113 case 'HasFormat':
114 case 'References':
115 case 'IsReferencedBy':
116 case 'IsBasedOn':
117 case 'IsBasisFor':
118 case 'Requires':
119 case 'IsRequiredBy':
120 $this->kind = $a_kind;
121 return true;
122
123 default:
124 return false;
125 }
126 }
127 function getKind()
128 {
129 return $this->kind;
130 }
131
132
133 function save()
134 {
135 if($this->db->autoExecute('il_meta_relation',
136 $this->__getFields(),
137 DB_AUTOQUERY_INSERT))
138 {
139 $this->setMetaId($this->db->getLastInsertId());
140
141 return $this->getMetaId();
142 }
143 return false;
144 }
145
146 function update()
147 {
148 global $ilDB;
149
150 if($this->getMetaId())
151 {
152 if($this->db->autoExecute('il_meta_relation',
153 $this->__getFields(),
154 DB_AUTOQUERY_UPDATE,
155 "meta_relation_id = ".$ilDB->quote($this->getMetaId())))
156 {
157 return true;
158 }
159 }
160 return false;
161 }
162
163 function delete()
164 {
165 global $ilDB;
166
167 if($this->getMetaId())
168 {
169 $query = "DELETE FROM il_meta_relation ".
170 "WHERE meta_relation_id = ".$ilDB->quote($this->getMetaId());
171
172 $this->db->query($query);
173
174 foreach($this->getIdentifier_Ids() as $id)
175 {
176 $ide = $this->getIdentifier_($id);
177 $ide->delete();
178 }
179 foreach($this->getDescriptionIds() as $id)
180 {
181 $des = $this->getDescription();
182 $des->delete();
183 }
184
185 return true;
186 }
187 return false;
188 }
189
190
191 function __getFields()
192 {
193 return array('rbac_id' => $this->getRBACId(),
194 'obj_id' => $this->getObjId(),
195 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
196 'kind' => ilUtil::prepareDBString($this->getKind()));
197 }
198
199 function read()
200 {
201 global $ilDB;
202
203 if($this->getMetaId())
204 {
205 $query = "SELECT * FROM il_meta_relation ".
206 "WHERE meta_relation_id = ".$ilDB->quote($this->getMetaId());
207
208 $res = $this->db->query($query);
209 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
210 {
211 $this->setRBACId($row->rbac_id);
212 $this->setObjId($row->obj_id);
213 $this->setObjType($row->obj_type);
214 $this->setKind(ilUtil::stripSlashes($row->kind));
215 }
216 }
217 return true;
218 }
219
220 /*
221 * XML Export of all meta data
222 * @param object (xml writer) see class.ilMD2XML.php
223 *
224 */
225 function toXML(&$writer)
226 {
227 $writer->xmlStartTag('Relation',array('Kind' => $this->getKind()));
228 $writer->xmlStartTag('Resource');
229
230 // Identifier_
231 foreach($this->getIdentifier_Ids() as $id)
232 {
233 $ide =& $this->getIdentifier_($id);
234 $ide->toXML($writer);
235 }
236 // Description
237 foreach($this->getDescriptionIds() as $id)
238 {
239 $des =& $this->getDescription($id);
240 $des->toXML($writer);
241 }
242 $writer->xmlEndTag('Resource');
243 $writer->xmlEndTag('Relation');
244 }
245
246
247
248 // STATIC
249 function _getIds($a_rbac_id,$a_obj_id)
250 {
251 global $ilDB;
252
253 $query = "SELECT meta_relation_id FROM il_meta_relation ".
254 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
255 "AND obj_id = ".$ilDB->quote($a_obj_id);
256
257 $res = $ilDB->query($query);
258 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
259 {
260 $ids[] = $row->meta_relation_id;
261 }
262 return $ids ? $ids : array();
263 }
264}
265?>
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)
& getIdentifier_($a_identifier__id)
_getIds($a_rbac_id, $a_obj_id)
ilMDRelation($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
& getDescription($a_description_id)
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