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