ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
31 include_once 'class.ilMDBase.php';
32 
33 class 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)
44  function &getIdentifier_Ids()
45  {
46  include_once 'Services/MetaData/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/MetaData/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/MetaData/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 
74  function &getDescriptionIds()
75  {
76  include_once 'Services/MetaData/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/MetaData/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/MetaData/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  global $ilDB;
136 
137  $fields = $this->__getFields();
138  $fields['meta_relation_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_relation'));
139 
140  if($this->db->insert('il_meta_relation',$fields))
141  {
142  $this->setMetaId($next_id);
143  return $this->getMetaId();
144  }
145  return false;
146  }
147 
148  function update()
149  {
150  global $ilDB;
151 
152  if($this->getMetaId())
153  {
154  if($this->db->update('il_meta_relation',
155  $this->__getFields(),
156  array("meta_relation_id" => array('integer',$this->getMetaId()))))
157  {
158  return true;
159  }
160  }
161  return false;
162  }
163 
164  function delete()
165  {
166  global $ilDB;
167 
168  if($this->getMetaId())
169  {
170  $query = "DELETE FROM il_meta_relation ".
171  "WHERE meta_relation_id = ".$ilDB->quote($this->getMetaId() ,'integer');
172  $res = $ilDB->manipulate($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($id);
182  $des->delete();
183  }
184 
185  return true;
186  }
187  return false;
188  }
189 
190 
191  function __getFields()
192  {
193  return array('rbac_id' => array('integer',$this->getRBACId()),
194  'obj_id' => array('integer',$this->getObjId()),
195  'obj_type' => array('text',$this->getObjType()),
196  'kind' => array('text',$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() ,'integer');
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($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  ? $this->getKind()
229  : 'IsPartOf'));
230  $writer->xmlStartTag('Resource');
231 
232  // Identifier_
233  $ides = $this->getIdentifier_Ids();
234  foreach($ides as $id)
235  {
236  $ide =& $this->getIdentifier_($id);
237  $ide->toXML($writer);
238  }
239  if(!count($ides))
240  {
241  include_once 'Services/MetaData/classes/class.ilMDIdentifier_.php';
242  $ide = new ilMDIdentifier_($this->getRBACId(),$this->getObjId());
243  $ide->toXML($writer);
244  }
245 
246  // Description
247  $dess = $this->getDescriptionIds();
248  foreach($dess as $id)
249  {
250  $des =& $this->getDescription($id);
251  $des->toXML($writer);
252  }
253  if(!count($dess))
254  {
255  include_once 'Services/MetaData/classes/class.ilMDDescription.php';
256  $des = new ilMDDescription($this->getRBACId(),$this->getObjId());
257  $des->toXML($writer);
258  }
259 
260  $writer->xmlEndTag('Resource');
261  $writer->xmlEndTag('Relation');
262  }
263 
264 
265 
266  // STATIC
267  function _getIds($a_rbac_id,$a_obj_id)
268  {
269  global $ilDB;
270 
271  $query = "SELECT meta_relation_id FROM il_meta_relation ".
272  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
273  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
274 
275  $res = $ilDB->query($query);
276  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
277  {
278  $ids[] = $row->meta_relation_id;
279  }
280  return $ids ? $ids : array();
281  }
282 }
283 ?>