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
34{
35 // METHODS OF CHILD OBJECTS (Taxon)
37 {
38 include_once 'Services/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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/MetaData/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 global $ilDB;
128
129 $fields = $this->__getFields();
130 $fields['meta_relation_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_relation'));
131
132 if($this->db->insert('il_meta_relation',$fields))
133 {
134 $this->setMetaId($next_id);
135 return $this->getMetaId();
136 }
137 return false;
138 }
139
140 function update()
141 {
142 global $ilDB;
143
144 if($this->getMetaId())
145 {
146 if($this->db->update('il_meta_relation',
147 $this->__getFields(),
148 array("meta_relation_id" => array('integer',$this->getMetaId()))))
149 {
150 return true;
151 }
152 }
153 return false;
154 }
155
156 function delete()
157 {
158 global $ilDB;
159
160 if($this->getMetaId())
161 {
162 $query = "DELETE FROM il_meta_relation ".
163 "WHERE meta_relation_id = ".$ilDB->quote($this->getMetaId() ,'integer');
164 $res = $ilDB->manipulate($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($id);
174 $des->delete();
175 }
176
177 return true;
178 }
179 return false;
180 }
181
182
183 function __getFields()
184 {
185 return array('rbac_id' => array('integer',$this->getRBACId()),
186 'obj_id' => array('integer',$this->getObjId()),
187 'obj_type' => array('text',$this->getObjType()),
188 'kind' => array('text',$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() ,'integer');
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($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 ? $this->getKind()
221 : 'IsPartOf'));
222 $writer->xmlStartTag('Resource');
223
224 // Identifier_
225 $ides = $this->getIdentifier_Ids();
226 foreach($ides as $id)
227 {
228 $ide =& $this->getIdentifier_($id);
229 $ide->toXML($writer);
230 }
231 if(!count($ides))
232 {
233 include_once 'Services/MetaData/classes/class.ilMDIdentifier_.php';
234 $ide = new ilMDIdentifier_($this->getRBACId(),$this->getObjId());
235 $ide->toXML($writer);
236 }
237
238 // Description
239 $dess = $this->getDescriptionIds();
240 foreach($dess as $id)
241 {
242 $des =& $this->getDescription($id);
243 $des->toXML($writer);
244 }
245 if(!count($dess))
246 {
247 include_once 'Services/MetaData/classes/class.ilMDDescription.php';
248 $des = new ilMDDescription($this->getRBACId(),$this->getObjId());
249 $des->toXML($writer);
250 }
251
252 $writer->xmlEndTag('Resource');
253 $writer->xmlEndTag('Relation');
254 }
255
256
257
258 // STATIC
259 static function _getIds($a_rbac_id,$a_obj_id)
260 {
261 global $ilDB;
262
263 $query = "SELECT meta_relation_id FROM il_meta_relation ".
264 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
265 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
266
267 $res = $ilDB->query($query);
268 while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
269 {
270 $ids[] = $row->meta_relation_id;
271 }
272 return $ids ? $ids : array();
273 }
274}
275?>
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)
& getDescription($a_description_id)
static _getIds($a_rbac_id, $a_obj_id)
global $ilDB