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