ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMDMetaMetadata.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 ilMDMetaMetadata extends ilMDBase
34 {
35 
36  function ilMDMetaMetadata($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
37  {
38  parent::ilMDBase($a_rbac_id,
39  $a_obj_id,
40  $a_obj_type);
41  }
42 
43  // SUBELEMENTS
44  function &getIdentifierIds()
45  {
46  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier.php';
47 
48  return ilMDIdentifier::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
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_meta_data');
70 
71  return $ide;
72  }
73 
74  function &getContributeIds()
75  {
76  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDContribute.php';
77 
78  return ilMDContribute::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
79  }
80  function &getContribute($a_contribute_id)
81  {
82  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDContribute.php';
83 
84  if(!$a_contribute_id)
85  {
86  return false;
87  }
88  $con =& new ilMDContribute();
89  $con->setMetaId($a_contribute_id);
90 
91  return $con;
92  }
93  function &addContribute()
94  {
95  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDContribute.php';
96 
97  $con =& new ilMDContribute($this->getRBACId(),$this->getObjId(),$this->getObjType());
98  $con->setParentId($this->getMetaId());
99  $con->setParentType('meta_meta_data');
100 
101  return $con;
102  }
103 
104 
105 
106  // SET/GET
107  function setMetaDataScheme($a_val)
108  {
109  $this->meta_data_scheme = $a_val;
110  }
111  function getMetaDataScheme()
112  {
113  // Fixed attribute
114  return 'LOM v 1.0';
115  }
116  function setLanguage(&$lng_obj)
117  {
118  if(is_object($lng_obj))
119  {
120  $this->language = $lng_obj;
121  }
122  }
123  function &getLanguage()
124  {
125  return is_object($this->language) ? $this->language : false;
126  }
127  function getLanguageCode()
128  {
129  return is_object($this->language) ? $this->language->getLanguageCode() : false;
130  }
131 
132 
133  function save()
134  {
135  if($this->db->autoExecute('il_meta_meta_data',
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_meta_data',
153  $this->__getFields(),
154  DB_AUTOQUERY_UPDATE,
155  "meta_meta_data_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_meta_data ".
170  "WHERE meta_meta_data_id = ".$ilDB->quote($this->getMetaId());
171 
172  $this->db->query($query);
173 
174 
175  foreach($this->getIdentifierIds() as $id)
176  {
177  $ide = $this->getIdentifier($id);
178  $ide->delete();
179  }
180 
181  foreach($this->getContributeIds() as $id)
182  {
183  $con = $this->getContribute($id);
184  $con->delete();
185  }
186  return true;
187  }
188 
189  return false;
190  }
191 
192 
193  function __getFields()
194  {
195  return array('rbac_id' => $this->getRBACId(),
196  'obj_id' => $this->getObjId(),
197  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
198  'meta_data_scheme' => ilUtil::prepareDBString($this->getMetaDataScheme()),
199  'language' => ilUtil::prepareDBString($this->getLanguageCode()));
200  }
201 
202  function read()
203  {
204  global $ilDB;
205 
206  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
207 
208 
209  if($this->getMetaId())
210  {
211 
212  $query = "SELECT * FROM il_meta_meta_data ".
213  "WHERE meta_meta_data_id = ".$ilDB->quote($this->getMetaId());
214 
215 
216  $res = $this->db->query($query);
217  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
218  {
219  $this->setRBACId($row->rbac_id);
220  $this->setObjId($row->obj_id);
221  $this->setObjType($row->obj_type);
222  $this->setMetaDataScheme(ilUtil::stripSlashes($row->meta_data_scheme));
223  $this->setLanguage(new ilMDLanguageItem($row->language));
224  }
225  return true;
226  }
227  return false;
228  }
229 
230  /*
231  * XML Export of all meta data
232  * @param object (xml writer) see class.ilMD2XML.php
233  *
234  */
235  function toXML(&$writer)
236  {
237  if($this->getMigration/DBUpdate_426Scheme())
238  {
239  $attr['Metadata-Scheme'] = $this->getMigration/DBUpdate_426Scheme();
240  }
241  if($this->getLanguageCode())
242  {
243  $attr['Language'] = $this->getLanguageCode();
244  }
245  $writer->xmlStartTag('Meta-Metadata',$attr ? $attr : null);
246 
247  // ELEMENT IDENTIFIER
248  foreach($this->getIdentifierIds() as $id)
249  {
250  $ide =& $this->getIdentifier($id);
251  $ide->toXML($writer);
252  }
253 
254  // ELEMETN Contribute
255  foreach($this->getContributeIds() as $id)
256  {
257  $con =& $this->getContribute($id);
258  $con->toXML($writer);
259  }
260 
261  $writer->xmlEndTag('Meta-Metadata');
262  }
263 
264  // STATIC
265  function _getId($a_rbac_id,$a_obj_id)
266  {
267  global $ilDB;
268 
269  $query = "SELECT meta_meta_data_id FROM il_meta_meta_data ".
270  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
271  "AND obj_id = ".$ilDB->quote($a_obj_id);
272 
273  $res = $ilDB->query($query);
274  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
275  {
276  return $row->meta_meta_data_id;
277  }
278  return false;
279  }
280 }
281 ?>