ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilMDAnnotation.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 ilMDAnnotation extends ilMDBase
34 {
35  function ilMDAnnotation($a_rbac_id = 0,$a_obj_id = 0,$a_obj_type = '')
36  {
37  parent::ilMDBase($a_rbac_id,
38  $a_obj_id,
39  $a_obj_type);
40  }
41 
42  // SET/GET
43  function setEntity($a_entity)
44  {
45  $this->entity = $a_entity;
46  }
47  function getEntity()
48  {
49  return $this->entity;
50  }
51  function setDate($a_date)
52  {
53  $this->date = $a_date;
54  }
55  function getDate()
56  {
57  return $this->date;
58  }
59  function setDescription($a_desc)
60  {
61  $this->description = $a_desc;
62  }
63  function getDescription()
64  {
65  return $this->description;
66  }
67  function setDescriptionLanguage($lng_obj)
68  {
69  if(is_object($lng_obj))
70  {
71  $this->description_language =& $lng_obj;
72  }
73  }
75  {
76  return $this->description_language;
77  }
79  {
80  if(is_object($this->description_language))
81  {
82  return $this->description_language->getLanguageCode();
83  }
84  return false;
85  }
86 
87  function save()
88  {
89  global $ilDB;
90 
91  $fields = $this->__getFields();
92  $fields['meta_annotation_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_annotation'));
93 
94  if($this->db->insert('il_meta_annotation',$fields))
95  {
96  $this->setMetaId($next_id);
97  return $this->getMetaId();
98  }
99  return false;
100  }
101 
102  function update()
103  {
104  global $ilDB;
105 
106  if($this->getMetaId())
107  {
108  if($this->db->update('il_meta_annotation',
109  $this->__getFields(),
110  array("meta_annotation_id" => array('integer',$this->getMetaId()))))
111  {
112  return true;
113  }
114  }
115  return false;
116  }
117 
118  function delete()
119  {
120  global $ilDB;
121 
122  if($this->getMetaId())
123  {
124  $query = "DELETE FROM il_meta_annotation ".
125  "WHERE meta_annotation_id = ".$ilDB->quote($this->getMetaId() ,'integer');
126  $res = $ilDB->manipulate($query);
127 
128  return true;
129  }
130  return false;
131  }
132 
133 
134  function __getFields()
135  {
136  return array('rbac_id' => array('integer',$this->getRBACId()),
137  'obj_id' => array('integer',$this->getObjId()),
138  'obj_type' => array('text',$this->getObjType()),
139  'entity' => array('clob',$this->getEntity()),
140  'a_date' => array('clob',$this->getDate()),
141  'description' => array('clob',$this->getDescription()),
142  'description_language' => array('text',$this->getDescriptionLanguageCode()));
143  }
144 
145  function read()
146  {
147  global $ilDB;
148 
149  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
150 
151  if($this->getMetaId())
152  {
153  $query = "SELECT * FROM il_meta_annotation ".
154  "WHERE meta_annotation_id = ".$ilDB->quote($this->getMetaId() ,'integer');
155 
156  $res = $this->db->query($query);
157  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
158  {
159  $this->setRBACId($row->rbac_id);
160  $this->setObjId($row->obj_id);
161  $this->setObjType($row->obj_type);
162  $this->setEntity($row->entity);
163  $this->setDate($row->a_date);
164  $this->setDescription($row->description);
165  $this->description_language =& new ilMDLanguageItem($row->description_language);
166  }
167  }
168  return true;
169  }
170 
171  /*
172  * XML Export of all meta data
173  * @param object (xml writer) see class.ilMD2XML.php
174  *
175  */
176  function toXML(&$writer)
177  {
178  $writer->xmlStartTag('Annotation');
179  $writer->xmlElement('Entity',null,$this->getEntity());
180  $writer->xmlElement('Date',null,$this->getDate());
181  $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()
182  ? $this->getDescriptionLanguageCode()
183  : 'en'),
184  $this->getDescription());
185  $writer->xmlEndTag('Annotation');
186  }
187 
188 
189 
190  // STATIC
191  function _getIds($a_rbac_id,$a_obj_id)
192  {
193  global $ilDB;
194 
195  $query = "SELECT meta_annotation_id FROM il_meta_annotation ".
196  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
197  "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer');
198 
199 
200  $res = $ilDB->query($query);
201  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
202  {
203  $ids[] = $row->meta_annotation_id;
204  }
205  return $ids ? $ids : array();
206  }
207 }
208 ?>