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