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  global $DIC;
62 
63  $ilDB = $DIC['ilDB'];
64 
65  $fields = $this->__getFields();
66  $fields['meta_description_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_description'));
67 
68  if ($this->db->insert('il_meta_description', $fields)) {
69  $this->setMetaId($next_id);
70  return $this->getMetaId();
71  }
72  return false;
73  }
74 
75  public function update()
76  {
77  global $DIC;
78 
79  $ilDB = $DIC['ilDB'];
80 
81  if ($this->getMetaId()) {
82  if ($this->db->update(
83  'il_meta_description',
84  $this->__getFields(),
85  array("meta_description_id" => array('integer',$this->getMetaId()))
86  )) {
87  return true;
88  }
89  }
90  return false;
91  }
92 
93  public function delete()
94  {
95  global $DIC;
96 
97  $ilDB = $DIC['ilDB'];
98 
99  if ($this->getMetaId()) {
100  $query = "DELETE FROM il_meta_description " .
101  "WHERE meta_description_id = " . $ilDB->quote($this->getMetaId(), 'integer');
102  $res = $ilDB->manipulate($query);
103 
104  return true;
105  }
106  return false;
107  }
108 
109 
110  public function __getFields()
111  {
112  return array('rbac_id' => array('integer',$this->getRBACId()),
113  'obj_id' => array('integer',$this->getObjId()),
114  'obj_type' => array('text',$this->getObjType()),
115  'parent_type' => array('text',$this->getParentType()),
116  'parent_id' => array('integer',$this->getParentId()),
117  'description' => array('clob',$this->getDescription()),
118  'description_language' => array('text',$this->getDescriptionLanguageCode()));
119  }
120 
121  public function read()
122  {
123  global $DIC;
124 
125  $ilDB = $DIC['ilDB'];
126 
127  include_once 'Services/Migration/DBUpdate_5295/classes/class.ilMDLanguageItem.php';
128 
129  if ($this->getMetaId()) {
130  $query = "SELECT * FROM il_meta_description " .
131  "WHERE meta_description_id = " . $ilDB->quote($this->getMetaId(), 'integer');
132 
133  $res = $this->db->query($query);
134  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
135  $this->setRBACId($row->rbac_id);
136  $this->setObjId($row->obj_id);
137  $this->setObjType($row->obj_type);
138  $this->setParentId($row->parent_id);
139  $this->setParentType($row->parent_type);
140  $this->setDescription($row->description);
141  $this->setDescriptionLanguage(new ilMDLanguageItem($row->description_language));
142  }
143  }
144  return true;
145  }
146 
147  /*
148  * XML Export of all meta data
149  * @param object (xml writer) see class.ilMD2XML.php
150  *
151  */
152  public function toXML(&$writer)
153  {
154  $writer->xmlElement(
155  'Description',
156  array('Language' => $this->getDescriptionLanguageCode() ?
157  $this->getDescriptionLanguageCode() :
158  'en'),
159  $this->getDescription()
160  );
161  }
162 
163 
164  // STATIC
165  public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
166  {
167  global $DIC;
168 
169  $ilDB = $DIC['ilDB'];
170 
171  $query = "SELECT meta_description_id FROM il_meta_description " .
172  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
173  "AND obj_id = " . $ilDB->quote($a_obj_id) . " " .
174  "AND parent_id = " . $ilDB->quote($a_parent_id) . " " .
175  "AND parent_type = " . $ilDB->quote($a_parent_type) . " " .
176  "ORDER BY meta_description_id";
177 
178  $res = $ilDB->query($query);
179  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
180  $ids[] = $row->meta_description_id;
181  }
182  return $ids ? $ids : array();
183  }
184 }
setObjType($a_type)
global $DIC
Definition: saml.php:7
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
setDescription($a_description)
setMetaId($a_meta_id, $a_read_data=true)
foreach($_POST as $key=> $value) $res
setObjId($a_id)
setRBACId($a_id)
$query
setDescriptionLanguage(&$lng_obj)
setParentId($a_id)
$row
global $ilDB
setParentType($a_parent_type)