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