ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
31include_once 'class.ilMDBase.php';
32
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 }
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/MetaData/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()
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}
An exception for terminatinating execution or to throw for unit testing.
setDescriptionLanguage($lng_obj)
static _getIds($a_rbac_id, $a_obj_id)
setObjId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
$query
foreach($_POST as $key=> $value) $res
global $ilDB
$DIC
Definition: xapitoken.php:46