ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilMDDescription.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
33class ilMDDescription extends ilMDBase
34{
35 function ilMDDescription($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 setDescription($a_description)
44 {
45 $this->description = $a_description;
46 }
47 function getDescription()
48 {
49 return $this->description;
50 }
51 function setDescriptionLanguage(&$lng_obj)
52 {
53 if(is_object($lng_obj))
54 {
55 $this->description_language = $lng_obj;
56 }
57 }
59 {
60 return is_object($this->description_language) ? $this->description_language : false;
61 }
63 {
64 return is_object($this->description_language) ? $this->description_language->getLanguageCode() : false;
65 }
66
67 function save()
68 {
69 if($this->db->autoExecute('il_meta_description',
70 $this->__getFields(),
71 DB_AUTOQUERY_INSERT))
72 {
73 $this->setMetaId($this->db->getLastInsertId());
74
75 return $this->getMetaId();
76 }
77 return false;
78 }
79
80 function update()
81 {
82 global $ilDB;
83
84 if($this->getMetaId())
85 {
86 if($this->db->autoExecute('il_meta_description',
87 $this->__getFields(),
88 DB_AUTOQUERY_UPDATE,
89 "meta_description_id = ".$ilDB->quote($this->getMetaId())))
90 {
91 return true;
92 }
93 }
94 return false;
95 }
96
97 function delete()
98 {
99 global $ilDB;
100
101 if($this->getMetaId())
102 {
103 $query = "DELETE FROM il_meta_description ".
104 "WHERE meta_description_id = ".$ilDB->quote($this->getMetaId());
105
106 $this->db->query($query);
107
108 return true;
109 }
110 return false;
111 }
112
113
114 function __getFields()
115 {
116 return array('rbac_id' => $this->getRBACId(),
117 'obj_id' => $this->getObjId(),
118 'obj_type' => ilUtil::prepareDBString($this->getObjType()),
119 'parent_type' => $this->getParentType(),
120 'parent_id' => $this->getParentId(),
121 'description' => ilUtil::prepareDBString($this->getDescription()),
122 'description_language' => ilUtil::prepareDBString($this->getDescriptionLanguageCode()));
123 }
124
125 function read()
126 {
127 global $ilDB;
128
129 include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
130
131 if($this->getMetaId())
132 {
133 $query = "SELECT * FROM il_meta_description ".
134 "WHERE meta_description_id = ".$ilDB->quote($this->getMetaId());
135
136 $res = $this->db->query($query);
137 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
138 {
139 $this->setRBACId($row->rbac_id);
140 $this->setObjId($row->obj_id);
141 $this->setObjType($row->obj_type);
142 $this->setParentId($row->parent_id);
143 $this->setParentType($row->parent_type);
144 $this->setDescription(ilUtil::stripSlashes($row->description));
145 $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
146 }
147 }
148 return true;
149 }
150
151 /*
152 * XML Export of all meta data
153 * @param object (xml writer) see class.ilMD2XML.php
154 *
155 */
156 function toXML(&$writer)
157 {
158 $writer->xmlElement('Description',array('Language' => $this->getDescriptionLanguageCode()),$this->getDescription());
159 }
160
161
162 // STATIC
163 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
164 {
165 global $ilDB;
166
167 $query = "SELECT meta_description_id FROM il_meta_description ".
168 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
169 "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
170 "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
171 "AND parent_type = ".$ilDB->quote($a_parent_type)." ".
172 "ORDER BY meta_description_id";
173
174 $res = $ilDB->query($query);
175 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
176 {
177 $ids[] = $row->meta_description_id;
178 }
179 return $ids ? $ids : array();
180 }
181}
182?>
const DB_FETCHMODE_OBJECT
Definition: class.ilDB.php:11
setObjId($a_id)
setParentId($a_id)
setMetaId($a_meta_id, $a_read_data=true)
setObjType($a_type)
setRBACId($a_id)
setParentType($a_parent_type)
_getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
ilMDDescription($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
setDescriptionLanguage(&$lng_obj)
setDescription($a_description)
static prepareDBString($a_str)
prepare a string for db writing (insert/update)
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
global $ilDB