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