ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMDFormat.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 
32 include_once 'class.ilMDBase.php';
33 
34 class ilMDFormat extends ilMDBase
35 {
36  function ilMDFormat($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  // SET/GET
44  function setFormat($a_format)
45  {
46  $this->format = $a_format;
47  }
48  function getFormat()
49  {
50  return $this->format;
51  }
52 
53  function save()
54  {
55  global $ilDB;
56 
57  $fields = $this->__getFields();
58  $fields['meta_format_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_format'));
59 
60  if($this->db->insert('il_meta_format',$fields))
61  {
62  $this->setMetaId($next_id);
63  return $this->getMetaId();
64  }
65  return false;
66  }
67 
68  function update()
69  {
70  global $ilDB;
71 
72  if($this->getMetaId())
73  {
74  if($this->db->update('il_meta_format',
75  $this->__getFields(),
76  array("meta_format_id" => array('integer',$this->getMetaId()))))
77  {
78  return true;
79  }
80  }
81  return false;
82  }
83 
84  function delete()
85  {
86  global $ilDB;
87 
88  if($this->getMetaId())
89  {
90  $query = "DELETE FROM il_meta_format ".
91  "WHERE meta_format_id = ".$ilDB->quote($this->getMetaId() ,'integer');
92  $res = $ilDB->manipulate($query);
93 
94  return true;
95  }
96  return false;
97  }
98 
99 
100  function __getFields()
101  {
102  return array('rbac_id' => array('integer',$this->getRBACId()),
103  'obj_id' => array('integer',$this->getObjId()),
104  'obj_type' => array('text',$this->getObjType()),
105  'format' => array('text',$this->getFormat()));
106  }
107 
108  function read()
109  {
110  global $ilDB;
111 
112  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
113 
114  if($this->getMetaId())
115  {
116  $query = "SELECT * FROM il_meta_format ".
117  "WHERE meta_format_id = ".$ilDB->quote($this->getMetaId() ,'integer');
118 
119  $res = $this->db->query($query);
120  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
121  {
122  $this->setRBACId($row->rbac_id);
123  $this->setObjId($row->obj_id);
124  $this->setObjType($row->obj_type);
125  $this->setFormat($row->format);
126  }
127  }
128  return true;
129  }
130 
131  /*
132  * XML Export of all meta data
133  * @param object (xml writer) see class.ilMD2XML.php
134  *
135  */
136  function toXML(&$writer)
137  {
138  if($this->getFormat())
139  {
140  $writer->xmlElement('Format',null,$this->getFormat());
141  }
142  }
143 
144 
145  // STATIC
146  function _getIds($a_rbac_id,$a_obj_id)
147  {
148  global $ilDB;
149 
150  $query = "SELECT meta_format_id FROM il_meta_format ".
151  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
152  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
153 
154  $res = $ilDB->query($query);
155  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
156  {
157  $ids[] = $row->meta_format_id;
158  }
159  return $ids ? $ids : array();
160  }
161 }
162 ?>