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