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