ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
31 include_once 'class.ilMDBase.php';
32 
33 class ilMDLanguage extends ilMDBase
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 
89  if ($this->db->insert('il_meta_language', $fields)) {
90  $this->setMetaId($next_id);
91  return $this->getMetaId();
92  }
93  return false;
94  }
95 
96  public function update()
97  {
98  global $DIC;
99 
100  $ilDB = $DIC['ilDB'];
101 
102  if ($this->getMetaId()) {
103  if ($this->db->update(
104  'il_meta_language',
105  $this->__getFields(),
106  array("meta_language_id" => array('integer',$this->getMetaId()))
107  )) {
108  return true;
109  }
110  }
111  return false;
112  }
113 
114  public function delete()
115  {
116  global $DIC;
117 
118  $ilDB = $DIC['ilDB'];
119 
120  if ($this->getMetaId()) {
121  $query = "DELETE FROM il_meta_language " .
122  "WHERE meta_language_id = " . $ilDB->quote($this->getMetaId(), 'integer');
123  $res = $ilDB->manipulate($query);
124 
125  return true;
126  }
127  return false;
128  }
129 
130 
131  public function __getFields()
132  {
133  return array('rbac_id' => array('integer',$this->getRBACId()),
134  'obj_id' => array('integer',$this->getObjId()),
135  'obj_type' => array('text',$this->getObjType()),
136  'parent_type' => array('text',$this->getParentType()),
137  'parent_id' => array('integer',$this->getParentId()),
138  'language' => array('text',$this->getLanguageCode()));
139  }
140 
141  public function read()
142  {
143  global $DIC;
144 
145  $ilDB = $DIC['ilDB'];
146 
147  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
148 
149  if ($this->getMetaId()) {
150  $query = "SELECT * FROM il_meta_language " .
151  "WHERE meta_language_id = " . $ilDB->quote($this->getMetaId(), 'integer');
152 
153  $res = $this->db->query($query);
154  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
155  $this->setRBACId($row->rbac_id);
156  $this->setObjId($row->obj_id);
157  $this->setObjType($row->obj_type);
158  $this->setParentId($row->parent_id);
159  $this->setParentType($row->parent_type);
160  $this->setLanguage(new ilMDLanguageItem($row->language));
161  }
162  }
163  return true;
164  }
165 
166  /*
167  * XML Export of all meta data
168  * @param object (xml writer) see class.ilMD2XML.php
169  *
170  */
171  public function toXML(&$writer)
172  {
173  $writer->xmlElement(
174  'Language',
175  array('Language' => $this->getLanguageCode() ?
176  $this->getLanguageCode() :
177  'en'),
178  $this->getLanguage()
179  );
180  }
181 
182 
183  // STATIC
184  public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
185  {
186  global $DIC;
187 
188  $ilDB = $DIC['ilDB'];
189 
190  $query = "SELECT meta_language_id FROM il_meta_language " .
191  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
192  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
193  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
194  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
195 
196  $res = $ilDB->query($query);
197  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
198  $ids[] = $row->meta_language_id;
199  }
200  return $ids ? $ids : array();
201  }
202 }
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
setObjType($a_type)
global $DIC
Definition: saml.php:7
setLanguage(&$lng_obj)
static _lookupFirstLanguage($a_rbac_id, $a_obj_id, $a_obj_type)
Lookup first language.
setMetaId($a_meta_id, $a_read_data=true)
foreach($_POST as $key=> $value) $res
setObjId($a_id)
setRBACId($a_id)
$query
setParentId($a_id)
$row
global $ilDB
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
setParentType($a_parent_type)