ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilMDLocation.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 ilMDLocation extends ilMDBase
34 {
35  // SET/GET
36  public function setLocation($a_location)
37  {
38  $this->location = $a_location;
39  }
40  public function getLocation()
41  {
42  return $this->location;
43  }
44  public function setLocationType($a_location_type)
45  {
46  $this->location_type = $a_location_type;
47  }
48  public function getLocationType()
49  {
50  return $this->location_type;
51  }
52 
53  public function save()
54  {
55  global $ilDB;
56 
57  $fields = $this->__getFields();
58  $fields['meta_location_id'] = array('integer',$next_id = $ilDB->nextId('il_meta_location'));
59 
60  if ($this->db->insert('il_meta_location', $fields)) {
61  $this->setMetaId($next_id);
62  return $this->getMetaId();
63  }
64  return false;
65  }
66 
67  public function update()
68  {
69  global $ilDB;
70 
71  if ($this->getMetaId()) {
72  if ($this->db->update(
73  'il_meta_location',
74  $this->__getFields(),
75  array("meta_location_id" => array('integer',$this->getMetaId()))
76  )) {
77  return true;
78  }
79  }
80  return false;
81  }
82 
83  public function delete()
84  {
85  global $ilDB;
86 
87  if ($this->getMetaId()) {
88  $query = "DELETE FROM il_meta_location " .
89  "WHERE meta_location_id = " . $ilDB->quote($this->getMetaId(), 'integer');
90  $res = $ilDB->manipulate($query);
91 
92  return true;
93  }
94  return false;
95  }
96 
97 
98  public function __getFields()
99  {
100  return array('rbac_id' => array('integer',$this->getRBACId()),
101  'obj_id' => array('integer',$this->getObjId()),
102  'obj_type' => array('text',$this->getObjType()),
103  'parent_type' => array('text',$this->getParentType()),
104  'parent_id' => array('integer',$this->getParentId()),
105  'location' => array('text',$this->getLocation()),
106  'location_type' => array('text',$this->getLocationType()));
107  }
108 
109  public function read()
110  {
111  global $ilDB;
112 
113  include_once 'Services/MetaData/classes/class.ilMDLanguageItem.php';
114 
115  if ($this->getMetaId()) {
116  $query = "SELECT * FROM il_meta_location " .
117  "WHERE meta_location_id = " . $ilDB->quote($this->getMetaId(), 'integer');
118 
119  $res = $this->db->query($query);
120  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
121  $this->setRBACId($row->rbac_id);
122  $this->setObjId($row->obj_id);
123  $this->setObjType($row->obj_type);
124  $this->setParentId($row->parent_id);
125  $this->setParentType($row->parent_type);
126  $this->setLocation($row->location);
127  $this->setLocationType($row->location_type);
128  }
129  }
130  return true;
131  }
132 
133  /*
134  * XML Export of all meta data
135  * @param object (xml writer) see class.ilMD2XML.php
136  *
137  */
138  public function toXML(&$writer)
139  {
140  $writer->xmlElement(
141  'Location',
142  array('Type' => $this->getLocationType()
143  ? $this->getLocationType()
144  : 'LocalFile'),
145  $this->getLocation()
146  );
147  }
148 
149 
150  // STATIC
151  public static function _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)
152  {
153  global $ilDB;
154 
155  $query = "SELECT meta_location_id FROM il_meta_location " .
156  "WHERE rbac_id = " . $ilDB->quote($a_rbac_id, 'integer') . " " .
157  "AND obj_id = " . $ilDB->quote($a_obj_id, 'integer') . " " .
158  "AND parent_id = " . $ilDB->quote($a_parent_id, 'integer') . " " .
159  "AND parent_type = " . $ilDB->quote($a_parent_type, 'text');
160 
161  $res = $ilDB->query($query);
162  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
163  $ids[] = $row->meta_location_id;
164  }
165  return $ids ? $ids : array();
166  }
167 }
setObjType($a_type)
setLocationType($a_location_type)
$location
Definition: buildRTE.php:44
setLocation($a_location)
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)
static _getIds($a_rbac_id, $a_obj_id, $a_parent_id, $a_parent_type)