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