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