ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
34 {
35  public function getPossibleSubelements()
36  {
37  $subs['Identifier'] = 'meta_identifier';
38  $subs['Contribute'] = 'meta_contribute';
39 
40  return $subs;
41  }
42 
43 
44  // SUBELEMENTS
45  public function &getIdentifierIds()
46  {
47  include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
48 
49  return ilMDIdentifier::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_meta_data');
50  }
51  public function &getIdentifier($a_identifier_id)
52  {
53  include_once 'Services/MetaData/classes/class.ilMDIdentifier.php';
54 
55  if (!$a_identifier_id) {
56  return false;
57  }
58  $ide = new ilMDIdentifier();
59  $ide->setMetaId($a_identifier_id);
60 
61  return $ide;
62  }
63  public 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_meta_data');
70 
71  return $ide;
72  }
73 
74  public function &getContributeIds()
75  {
76  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
77 
78  return ilMDContribute::_getIds($this->getRBACId(), $this->getObjId(), $this->getMetaId(), 'meta_meta_data');
79  }
80  public function &getContribute($a_contribute_id)
81  {
82  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
83 
84  if (!$a_contribute_id) {
85  return false;
86  }
87  $con = new ilMDContribute();
88  $con->setMetaId($a_contribute_id);
89 
90  return $con;
91  }
92  public function &addContribute()
93  {
94  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
95 
96  $con = new ilMDContribute($this->getRBACId(), $this->getObjId(), $this->getObjType());
97  $con->setParentId($this->getMetaId());
98  $con->setParentType('meta_meta_data');
99 
100  return $con;
101  }
102 
103 
104 
105  // SET/GET
106  public function setMetaDataScheme($a_val)
107  {
108  $this->meta_data_scheme = $a_val;
109  }
110  public function getMetaDataScheme()
111  {
112  // Fixed attribute
113  return 'LOM v 1.0';
114  }
115  public function setLanguage(&$lng_obj)
116  {
117  if (is_object($lng_obj)) {
118  $this->language = $lng_obj;
119  }
120  }
121  public function &getLanguage()
122  {
123  return is_object($this->language) ? $this->language : false;
124  }
125  public function getLanguageCode()
126  {
127  return is_object($this->language) ? $this->language->getLanguageCode() : false;
128  }
129 
130 
131  public function save()
132  {
133  global $ilDB;
134 
135  $fields = $this->__getFields();
136  $fields['meta_meta_data_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_meta_data'));
137 
138  if ($this->db->insert('il_meta_meta_data', $fields)) {
139  $this->setMetaId($next_id);
140  return $this->getMetaId();
141  }
142  return false;
143  }
144 
145  public function update()
146  {
147  global $ilDB;
148 
149  if ($this->getMetaId()) {
150  if ($this->db->update(
151  'il_meta_meta_data',
152  $this->__getFields(),
153  array("meta_meta_data_id" => array('integer',$this->getMetaId()))
154  )) {
155  return true;
156  }
157  }
158  return false;
159  }
160 
161  public function delete()
162  {
163  global $ilDB;
164 
165  if ($this->getMetaId()) {
166  $query = "DELETE FROM il_meta_meta_data " .
167  "WHERE meta_meta_data_id = " . $ilDB->quote($this->getMetaId(), 'integer');
168  $res = $ilDB->manipulate($query);
169 
170 
171  foreach ($this->getIdentifierIds() as $id) {
172  $ide = $this->getIdentifier($id);
173  $ide->delete();
174  }
175 
176  foreach ($this->getContributeIds() as $id) {
177  $con = $this->getContribute($id);
178  $con->delete();
179  }
180  return true;
181  }
182 
183  return false;
184  }
185 
186 
187  public function __getFields()
188  {
189  return array('rbac_id' => array('integer',$this->getRBACId()),
190  'obj_id' => array('integer',$this->getObjId()),
191  'obj_type' => array('text',$this->getObjType()),
192  'meta_data_scheme' => array('text',$this->getMetaDataScheme()),
193  'language' => array('text',$this->getLanguageCode()));
194  }
195 
196  public function read()
197  {
198  global $ilDB;
199 
200  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
201 
202 
203  if ($this->getMetaId()) {
204  $query = "SELECT * FROM il_meta_meta_data " .
205  "WHERE meta_meta_data_id = " . $ilDB->quote($this->getMetaId(), 'integer');
206 
207 
208  $res = $this->db->query($query);
209  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
210  $this->setRBACId($row->rbac_id);
211  $this->setObjId($row->obj_id);
212  $this->setObjType($row->obj_type);
213  $this->setMetaDataScheme($row->meta_data_scheme);
214  $this->setLanguage(new ilMDLanguageItem($row->language));
215  }
216  return true;
217  }
218  return false;
219  }
220 
221  /*
222  * XML Export of all meta data
223  * @param object (xml writer) see class.ilMD2XML.php
224  *
225  */
226  public function toXML(&$writer)
227  {
228  if ($this->getMetaDataScheme()) {
229  $attr['MetadataScheme'] = $this->getMetaDataScheme();
230  }
231  if ($this->getLanguageCode()) {
232  $attr['Language'] = $this->getLanguageCode();
233  }
234  $writer->xmlStartTag('Meta-Metadata', $attr ? $attr : null);
235 
236  // ELEMENT IDENTIFIER
237  $identifiers = $this->getIdentifierIds();
238  foreach ($identifiers as $id) {
239  $ide =&$this->getIdentifier($id);
240  $ide->toXML($writer);
241  }
242  if (!count($identifiers)) {
243  include_once 'Services/Metadata/classes/class.ilMDIdentifier.php';
244  $ide = new ilMDIdentifier($this->getRBACId(), $this->getObjId());
245  $ide->toXML($writer);
246  }
247 
248  // ELEMETN Contribute
249  $contributes = $this->getContributeIds();
250  foreach ($contributes as $id) {
251  $con =&$this->getContribute($id);
252  $con->toXML($writer);
253  }
254  if (!count($contributes)) {
255  include_once 'Services/MetaData/classes/class.ilMDContribute.php';
256  $con = new ilMDContribute($this->getRBACId(), $this->getObjId());
257  $con->toXML($writer);
258  }
259 
260  $writer->xmlEndTag('Meta-Metadata');
261  }
262 
263  // STATIC
264  public static function _getId($a_rbac_id, $a_obj_id)
265  {
266  global $ilDB;
267 
268  $query = "SELECT meta_meta_data_id FROM il_meta_meta_data " .
269  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
270  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer');
271 
272  $res = $ilDB->query($query);
273  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
274  return $row->meta_meta_data_id;
275  }
276  return false;
277  }
278 }
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
static _getId($a_rbac_id, $a_obj_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
& getContribute($a_contribute_id)
Create styles array
The data for the language used.
global $ilDB