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
25/**
26* Meta Data class (element language)
27*
28* @package ilias-core
29* @version $Id$
30*/
31include_once 'class.ilMDBase.php';
32
33class ilMDLanguage extends ilMDBase
34{
35    // SET/GET
36    public function setLanguage(&$lng_obj)
37    {
38        if (is_object($lng_obj)) {
39            $this->language = &$lng_obj;
40        }
41    }
42    public function &getLanguage()
43    {
44        return is_object($this->language) ? $this->language : false;
45    }
46    public function getLanguageCode()
47    {
48        return is_object($this->language) ? $this->language->getLanguageCode() : false;
49    }
50
51    public function save()
52    {
53        if ($this->db->autoExecute(
54            'il_meta_language',
55            $this->__getFields(),
56            ilDBConstants::AUTOQUERY_INSERT
57        )) {
58            $this->setMetaId($this->db->getLastInsertId());
59
60            return $this->getMetaId();
61        }
62        return false;
63    }
64
65    public function update()
66    {
67        global $ilDB;
68
69        if ($this->getMetaId()) {
70            if ($this->db->autoExecute(
71                'il_meta_language',
72                $this->__getFields(),
73                ilDBConstants::AUTOQUERY_UPDATE,
74                "meta_language_id = " . $ilDB->quote($this->getMetaId())
75            )) {
76                return true;
77            }
78        }
79        return false;
80    }
81
82    public function delete()
83    {
84        global $ilDB;
85
86        if ($this->getMetaId()) {
87            $query = "DELETE FROM il_meta_language " .
88                "WHERE meta_language_id = " . $ilDB->quote($this->getMetaId());
89
90            $this->db->query($query);
91
92            return true;
93        }
94        return false;
95    }
96
97
98    public function __getFields()
99    {
100        return array('rbac_id' => $this->getRBACId(),
101                     'obj_id' => $this->getObjId(),
102                     'obj_type' => ilUtil::prepareDBString($this->getObjType()),
103                     'parent_type' => $this->getParentType(),
104                     'parent_id' => $this->getParentId(),
105                     'language' => ilUtil::prepareDBString($this->getLanguageCode()));
106    }
107
108    public function read()
109    {
110        global $ilDB;
111
112        include_once 'Services/Migration/DBUpdate_426/classes/class.ilMDLanguageItem.php';
113
114        if ($this->getMetaId()) {
115            $query = "SELECT * FROM il_meta_language " .
116                "WHERE meta_language_id = " . $ilDB->quote($this->getMetaId());
117
118            $res = $this->db->query($query);
119            while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
120                $this->setRBACId($row->rbac_id);
121                $this->setObjId($row->obj_id);
122                $this->setObjType($row->obj_type);
123                $this->setParentId($row->parent_id);
124                $this->setParentType($row->parent_type);
125                $this->setLanguage(new ilMDLanguageItem($row->language));
126            }
127        }
128        return true;
129    }
130
131    /*
132     * XML Export of all meta data
133     * @param object (xml writer) see class.ilMD2XML.php
134     *
135     */
136    public function toXML(&$writer)
137    {
138        $writer->xmlElement('Language', array('Language' => $this->getLanguageCode()), $this->getLanguage());
139    }
140
141
142    // STATIC
143    public function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
144    {
145        global $ilDB;
146
147        $query = "SELECT meta_language_id FROM il_meta_language " .
148            "WHERE rbac_id = " . $ilDB->quote($a_rbac_id) . " " .
149            "AND obj_id = " . $ilDB->quote($a_obj_id) . " " .
150            "AND parent_id = " . $ilDB->quote($a_parent_id) . " " .
151            "AND parent_type = " . $ilDB->quote($a_parent_type);
152
153        $res = $ilDB->query($query);
154        while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
155            $ids[] = $row->meta_language_id;
156        }
157        return $ids ? $ids : array();
158    }
159}
160