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
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
51 public static function _lookupFirstLanguage($a_rbac_id,$a_obj_id,$a_obj_type)
52 {
53 global $ilDB;
54
55 $lang = '';
56 $query = "SELECT language FROM il_meta_language ".
57 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
58 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
59 "AND obj_type = ".$ilDB->quote($a_obj_type ,'text')." ".
60 "AND parent_type = 'meta_general' ".
61 "ORDER BY meta_language_id ";
62 $ilDB->setLimit(1);
63 $res = $ilDB->query($query);
64 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
65 {
66 $lang = $row->language;
67 }
68 return $lang;
69 }
70
71 // SET/GET
72 function setLanguage(&$lng_obj)
73 {
74 if(is_object($lng_obj))
75 {
76 $this->language =& $lng_obj;
77 }
78 }
79 function &getLanguage()
80 {
81 return is_object($this->language) ? $this->language : false;
82 }
83 function getLanguageCode()
84 {
85 return is_object($this->language) ? $this->language->getLanguageCode() : false;
86 }
87
88 function save()
89 {
90 global $ilDB;
91
92 $fields = $this->__getFields();
93 $fields['meta_language_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_language'));
94
95 if($this->db->insert('il_meta_language',$fields))
96 {
97 $this->setMetaId($next_id);
98 return $this->getMetaId();
99 }
100 return false;
101 }
102
103 function update()
104 {
105 global $ilDB;
106
107 if($this->getMetaId())
108 {
109 if($this->db->update('il_meta_language',
110 $this->__getFields(),
111 array("meta_language_id" => array('integer',$this->getMetaId()))))
112 {
113 return true;
114 }
115 }
116 return false;
117 }
118
119 function delete()
120 {
121 global $ilDB;
122
123 if($this->getMetaId())
124 {
125 $query = "DELETE FROM il_meta_language ".
126 "WHERE meta_language_id = ".$ilDB->quote($this->getMetaId() ,'integer');
127 $res = $ilDB->manipulate($query);
128
129 return true;
130 }
131 return false;
132 }
133
134
135 function __getFields()
136 {
137 return array('rbac_id' => array('integer',$this->getRBACId()),
138 'obj_id' => array('integer',$this->getObjId()),
139 'obj_type' => array('text',$this->getObjType()),
140 'parent_type' => array('text',$this->getParentType()),
141 'parent_id' => array('integer',$this->getParentId()),
142 'language' => array('text',$this->getLanguageCode()));
143 }
144
145 function read()
146 {
147 global $ilDB;
148
149 include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
150
151 if($this->getMetaId())
152 {
153 $query = "SELECT * FROM il_meta_language ".
154 "WHERE meta_language_id = ".$ilDB->quote($this->getMetaId() ,'integer');
155
156 $res = $this->db->query($query);
157 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
158 {
159 $this->setRBACId($row->rbac_id);
160 $this->setObjId($row->obj_id);
161 $this->setObjType($row->obj_type);
162 $this->setParentId($row->parent_id);
163 $this->setParentType($row->parent_type);
164 $this->setLanguage(new ilMDLanguageItem($row->language));
165 }
166 }
167 return true;
168 }
169
170 /*
171 * XML Export of all meta data
172 * @param object (xml writer) see class.ilMD2XML.php
173 *
174 */
175 function toXML(&$writer)
176 {
177 $writer->xmlElement('Language',array('Language' => $this->getLanguageCode() ?
178 $this->getLanguageCode() :
179 'en'),
180 $this->getLanguage());
181 }
182
183
184 // STATIC
185 function _getIds($a_rbac_id,$a_obj_id,$a_parent_id,$a_parent_type)
186 {
187 global $ilDB;
188
189 $query = "SELECT meta_language_id FROM il_meta_language ".
190 "WHERE rbac_id = ".$ilDB->quote($a_rbac_id ,'integer')." ".
191 "AND obj_id = ".$ilDB->quote($a_obj_id ,'integer')." ".
192 "AND parent_id = ".$ilDB->quote($a_parent_id ,'integer')." ".
193 "AND parent_type = ".$ilDB->quote($a_parent_type ,'text');
194
195 $res = $ilDB->query($query);
196 while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
197 {
198 $ids[] = $row->meta_language_id;
199 }
200 return $ids ? $ids : array();
201 }
202}
203?>
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)
static _lookupFirstLanguage($a_rbac_id, $a_obj_id, $a_obj_type)
Lookup first language.
setLanguage(&$lng_obj)
ilMDLanguage($a_rbac_id=0, $a_obj_id=0, $a_obj_type='')
global $ilDB