ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  // SUBELEMENTS
36  function &getIdentifierIds()
37  {
38  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDIdentifier.php';
39 
40  return ilMDIdentifier::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
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_meta_data');
62 
63  return $ide;
64  }
65 
66  function &getContributeIds()
67  {
68  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDContribute.php';
69 
70  return ilMDContribute::_getIds($this->getRBACId(),$this->getObjId(),$this->getMetaId(),'meta_meta_data');
71  }
72  function &getContribute($a_contribute_id)
73  {
74  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDContribute.php';
75 
76  if(!$a_contribute_id)
77  {
78  return false;
79  }
80  $con = new ilMDContribute();
81  $con->setMetaId($a_contribute_id);
82 
83  return $con;
84  }
85  function &addContribute()
86  {
87  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDContribute.php';
88 
89  $con = new ilMDContribute($this->getRBACId(),$this->getObjId(),$this->getObjType());
90  $con->setParentId($this->getMetaId());
91  $con->setParentType('meta_meta_data');
92 
93  return $con;
94  }
95 
96 
97 
98  // SET/GET
99  function setMetaDataScheme($a_val)
100  {
101  $this->meta_data_scheme = $a_val;
102  }
103  function getMetaDataScheme()
104  {
105  // Fixed attribute
106  return 'LOM v 1.0';
107  }
108  function setLanguage(&$lng_obj)
109  {
110  if(is_object($lng_obj))
111  {
112  $this->language = $lng_obj;
113  }
114  }
115  function &getLanguage()
116  {
117  return is_object($this->language) ? $this->language : false;
118  }
119  function getLanguageCode()
120  {
121  return is_object($this->language) ? $this->language->getLanguageCode() : false;
122  }
123 
124 
125  function save()
126  {
127  if($this->db->autoExecute('il_meta_meta_data',
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_meta_data',
145  $this->__getFields(),
147  "meta_meta_data_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_meta_data ".
162  "WHERE meta_meta_data_id = ".$ilDB->quote($this->getMetaId());
163 
164  $this->db->query($query);
165 
166 
167  foreach($this->getIdentifierIds() as $id)
168  {
169  $ide = $this->getIdentifier($id);
170  $ide->delete();
171  }
172 
173  foreach($this->getContributeIds() as $id)
174  {
175  $con = $this->getContribute($id);
176  $con->delete();
177  }
178  return true;
179  }
180 
181  return false;
182  }
183 
184 
185  function __getFields()
186  {
187  return array('rbac_id' => $this->getRBACId(),
188  'obj_id' => $this->getObjId(),
189  'obj_type' => ilUtil::prepareDBString($this->getObjType()),
190  'meta_data_scheme' => ilUtil::prepareDBString($this->getMetaDataScheme()),
191  'language' => ilUtil::prepareDBString($this->getLanguageCode()));
192  }
193 
194  function read()
195  {
196  global $ilDB;
197 
198  include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
199 
200 
201  if($this->getMetaId())
202  {
203 
204  $query = "SELECT * FROM il_meta_meta_data ".
205  "WHERE meta_meta_data_id = ".$ilDB->quote($this->getMetaId());
206 
207 
208  $res = $this->db->query($query);
209  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
210  {
211  $this->setRBACId($row->rbac_id);
212  $this->setObjId($row->obj_id);
213  $this->setObjType($row->obj_type);
214  $this->setMetaDataScheme(ilUtil::stripSlashes($row->meta_data_scheme));
215  $this->setLanguage(new ilMDLanguageItem($row->language));
216  }
217  return true;
218  }
219  return false;
220  }
221 
222  /*
223  * XML Export of all meta data
224  * @param object (xml writer) see class.ilMD2XML.php
225  *
226  */
227  function toXML(&$writer)
228  {
229  if($this->getMigration/DBUpdate_426Scheme())
230  {
231  $attr['Metadata-Scheme'] = $this->getMigration/DBUpdate_426Scheme();
232  }
233  if($this->getLanguageCode())
234  {
235  $attr['Language'] = $this->getLanguageCode();
236  }
237  $writer->xmlStartTag('Meta-Metadata',$attr ? $attr : null);
238 
239  // ELEMENT IDENTIFIER
240  foreach($this->getIdentifierIds() as $id)
241  {
242  $ide =& $this->getIdentifier($id);
243  $ide->toXML($writer);
244  }
245 
246  // ELEMETN Contribute
247  foreach($this->getContributeIds() as $id)
248  {
249  $con =& $this->getContribute($id);
250  $con->toXML($writer);
251  }
252 
253  $writer->xmlEndTag('Meta-Metadata');
254  }
255 
256  // STATIC
257  function _getId($a_rbac_id,$a_obj_id)
258  {
259  global $ilDB;
260 
261  $query = "SELECT meta_meta_data_id FROM il_meta_meta_data ".
262  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
263  "AND obj_id = ".$ilDB->quote($a_obj_id);
264 
265  $res = $ilDB->query($query);
266  while($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT))
267  {
268  return $row->meta_meta_data_id;
269  }
270  return false;
271  }
272 }
273 ?>
setObjType($a_type)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
& getIdentifier($a_identifier_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjId($a_id)
setRBACId($a_id)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
& getContribute($a_contribute_id)
Create styles array
The data for the language used.
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
global $ilDB
_getId($a_rbac_id, $a_obj_id)