ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  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  global $ilDB;
70 
71  $fields = $this->__getFields();
72  $fields['meta_description_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_description'));
73 
74  if($this->db->insert('il_meta_description',$fields))
75  {
76  $this->setMetaId($next_id);
77  return $this->getMetaId();
78  }
79  return false;
80  }
81 
82  function update()
83  {
84  global $ilDB;
85 
86  if($this->getMetaId())
87  {
88  if($this->db->update('il_meta_description',
89  $this->__getFields(),
90  array("meta_description_id" => array('integer',$this->getMetaId()))))
91  {
92  return true;
93  }
94  }
95  return false;
96  }
97 
98  function delete()
99  {
100  global $ilDB;
101 
102  if($this->getMetaId())
103  {
104  $query = "DELETE FROM il_meta_description ".
105  "WHERE meta_description_id = ".$ilDB->quote($this->getMetaId() ,'integer');
106  $res = $ilDB->manipulate($query);
107 
108  return true;
109  }
110  return false;
111  }
112 
113 
114  function __getFields()
115  {
116  return array('rbac_id' => array('integer',$this->getRBACId()),
117  'obj_id' => array('integer',$this->getObjId()),
118  'obj_type' => array('text',$this->getObjType()),
119  'parent_type' => array('text',$this->getParentType()),
120  'parent_id' => array('integer',$this->getParentId()),
121  'description' => array('clob',$this->getDescription()),
122  'description_language' => array('text',$this->getDescriptionLanguageCode()));
123  }
124 
125  function read()
126  {
127  global $ilDB;
128 
129  include_once 'Services/MetaData/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() ,'integer');
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($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() ?
159  $this->getDescriptionLanguageCode() :
160  'en'),
161  $this->getDescription());
162  }
163 
164 
165  // STATIC
166  function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
167  {
168  global $ilDB;
169 
170  $query = "SELECT meta_description_id FROM il_meta_description ".
171  "WHERE rbac_id = ".$ilDB->quote($a_rbac_id)." ".
172  "AND obj_id = ".$ilDB->quote($a_obj_id)." ".
173  "AND parent_id = ".$ilDB->quote($a_parent_id)." ".
174  "AND parent_type = ".$ilDB->quote($a_parent_type)." ".
175  "ORDER BY meta_description_id";
176 
177  $res = $ilDB->query($query);
178  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
179  {
180  $ids[] = $row->meta_description_id;
181  }
182  return $ids ? $ids : array();
183  }
184 }
185 ?>