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