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