ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilECSDataMappingSetting.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2006 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 
33 {
34 
35  const MAPPING_EXPORT = 1;
36  const MAPPING_IMPORT_CRS = 2;
38 
39  private $server_id = 0;
40  private $mapping_type = 0;
41  private $ecs_field = 0;
42  private $advmd_id = 0;
43 
44 
50  public function __construct($a_server_id = 0,$mapping_type = 0,$ecs_field = '')
51  {
52  $this->setServerId($a_server_id);
54  $this->setECSField($ecs_field);
55  }
56 
61  public function setServerId($a_server_id)
62  {
63  $this->server_id = $a_server_id;
64  }
65 
69  public function getServerId()
70  {
71  return $this->server_id;
72  }
73 
78  public function setECSField($ecs_field)
79  {
80  $this->ecs_field = $ecs_field;
81  }
82 
86  public function getECSField()
87  {
88  return $this->ecs_field;
89  }
90 
95  public function setMappingType($mapping_type)
96  {
97  $this->mapping_type = $mapping_type;
98  }
99 
103  public function getMappingType()
104  {
105  return $this->mapping_type;
106  }
107 
108 
113  public function getAdvMDId()
114  {
115  return $this->advmd_id;
116  }
117 
118  public function setAdvMDId($a_id)
119  {
120  $this->advmd_id = $a_id;
121  }
122 
128  public function save()
129  {
130  global $ilDB;
131 
132  $query = 'SELECT * FROM ecs_data_mapping '.
133  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
134  'AND mapping_type = '.$ilDB->quote($this->getMappingType(),'integer').' '.
135  'AND ecs_field = '.$ilDB->quote($this->getECSField(),'text');
136  $res = $ilDB->query($query);
137  if($res->numRows())
138  {
139  $this->update();
140  }
141  else
142  {
143  $this->create();
144  }
145  }
146 
151  protected function update()
152  {
153  global $ilDB;
154 
155  $query = 'UPDATE ecs_data_mapping '.
156  'SET advmd_id = '.$ilDB->db->quote($this->getAdvMDId(),'integer').' '.
157  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
158  'AND mapping_type = '.$ilDB->quote($this->getMappingType(),'integer').' '.
159  'AND ecs_field = '.$ilDB->quote($this->getECSField(),'text');
160  $ilDB->manipulate($query);
161  }
162 
163  protected function create()
164  {
165  global $ilDB;
166 
167  $query = 'INSERT INTO ecs_data_mapping (sid,mapping_type,ecs_field,advmd_id) '.
168  'VALUES('.
169  $ilDB->quote($this->getServerId(), 'integer') . ', ' .
170  $ilDB->quote($this->getMappingType(),'integer').', '.
171  $ilDB->quote($this->getECSField(),'text').', '.
172  $ilDB->quote($this->getAdvMDId(),'integer').' ) ';
173  $res = $ilDB->manipulate($query);
174  return true;
175  }
176 
177 
184  private function read()
185  {
186  global $ilDB;
187 
188  if($this->getServerId() and $this->getMappingType() and $this->getECSField())
189  {
190  $query = 'SELECT * FROM ecs_data_mapping '.
191  'WHERE sid = '.$ilDB->quote($this->getServerId(),'integer').' '.
192  'AND mapping_type = '.$ilDB->quote($this->getMappingType(),'integer').' '.
193  'AND ecs_field = '.$ilDB->quote($this->getECSField(),'text');
194  $res = $ilDB->query($query);
195  while($row = $res->fetchRow(DB_FETCHMODE_OBJECT))
196  {
197  $this->setAdvMDId($row->advmd_id);
198  }
199  }
200  }
201 
202  public static function deleteByServerId($a_server_id)
203  {
204  global $ilDB;
205 
206  $query = 'DELETE FROM ecs_data_mapping'.
207  ' WHERE sid = '.$ilDB->quote($a_server_id,'integer');
208  $ilDB->manipulate($query);
209  return true;
210  }
211 }
212 ?>