ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMDEntity.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 
32 include_once 'class.ilMDBase.php';
33 
34 class ilMDEntity extends ilMDBase
35 {
36  // SET/GET
37  public function setEntity($a_entity)
38  {
39  $this->entity = $a_entity;
40  }
41  public function getEntity()
42  {
43  return $this->entity;
44  }
45 
46  public function save()
47  {
48  global $ilDB;
49 
50  $fields = $this->__getFields();
51  $fields['meta_entity_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_entity'));
52 
53  if ($this->db->insert('il_meta_entity', $fields)) {
54  $this->setMetaId($next_id);
55  return $this->getMetaId();
56  }
57  return false;
58  }
59 
60  public function update()
61  {
62  global $ilDB;
63 
64  if ($this->getMetaId()) {
65  if ($this->db->update(
66  'il_meta_entity',
67  $this->__getFields(),
68  array("meta_entity_id" => array('integer',$this->getMetaId()))
69  )) {
70  return true;
71  }
72  }
73  return false;
74  }
75 
76  public function delete()
77  {
78  global $ilDB;
79 
80  if ($this->getMetaId()) {
81  $query = "DELETE FROM il_meta_entity " .
82  "WHERE meta_entity_id = " . $ilDB->quote($this->getMetaId(), 'integer');
83  $res = $ilDB->manipulate($query);
84 
85  $this->db->query($query);
86 
87  return true;
88  }
89  return false;
90  }
91 
92 
93  public function __getFields()
94  {
95  return array('rbac_id' => array('integer',$this->getRBACId()),
96  'obj_id' => array('integer',$this->getObjId()),
97  'obj_type' => array('text',$this->getObjType()),
98  'parent_type' => array('text',$this->getParentType()),
99  'parent_id' => array('integer',$this->getParentId()),
100  'entity' => array('text',$this->getEntity()));
101  }
102 
103  public function read()
104  {
105  global $ilDB;
106 
107  if ($this->getMetaId()) {
108  $query = "SELECT * FROM il_meta_entity " .
109  "WHERE meta_entity_id = " . $ilDB->quote($this->getMetaId(), 'integer');
110 
111  $res = $this->db->query($query);
112  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
113  $this->setRBACId($row->rbac_id);
114  $this->setObjId($row->obj_id);
115  $this->setObjType($row->obj_type);
116  $this->setParentId($row->parent_id);
117  $this->setParentType($row->parent_type);
118  $this->setEntity($row->entity);
119  }
120  }
121  return true;
122  }
123 
124  /*
125  * XML Export of all meta data
126  * @param object (xml writer) see class.ilMD2XML.php
127  *
128  */
129  public function toXML(&$writer)
130  {
131  $writer->xmlElement('Entity', null, $this->getEntity());
132  }
133 
134 
135  // STATIC
136  public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
137  {
138  global $ilDB;
139 
140  $query = "SELECT meta_entity_id FROM il_meta_entity " .
141  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
142  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
143  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
144  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text') . " " .
145  "ORDER BY meta_entity_id ";
146 
147  $res = $ilDB->query($query);
148  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
149  $ids[] = $row->meta_entity_id;
150  }
151  return $ids ? $ids : array();
152  }
153 }
setObjType($a_type)
toXML(&$writer)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
setMetaId($a_meta_id, $a_read_data=true)
foreach($_POST as $key=> $value) $res
setObjId($a_id)
setRBACId($a_id)
$query
Create styles array
The data for the language used.
setParentId($a_id)
global $ilDB
setParentType($a_parent_type)
setEntity($a_entity)