ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  const MAPPING_EXPORT = 1;
35  const MAPPING_IMPORT_CRS = 2;
37 
38  private $server_id = 0;
39  private $mapping_type = 0;
40  private $ecs_field = 0;
41  private $advmd_id = 0;
42 
43 
49  public function __construct($a_server_id = 0, $mapping_type = 0, $ecs_field = '')
50  {
51  $this->setServerId($a_server_id);
53  $this->setECSField($ecs_field);
54  }
55 
60  public function setServerId($a_server_id)
61  {
62  $this->server_id = $a_server_id;
63  }
64 
68  public function getServerId()
69  {
70  return $this->server_id;
71  }
72 
77  public function setECSField($ecs_field)
78  {
79  $this->ecs_field = $ecs_field;
80  }
81 
85  public function getECSField()
86  {
87  return $this->ecs_field;
88  }
89 
94  public function setMappingType($mapping_type)
95  {
96  $this->mapping_type = $mapping_type;
97  }
98 
102  public function getMappingType()
103  {
104  return $this->mapping_type;
105  }
106 
107 
112  public function getAdvMDId()
113  {
114  return $this->advmd_id;
115  }
116 
117  public function setAdvMDId($a_id)
118  {
119  $this->advmd_id = $a_id;
120  }
121 
127  public function save()
128  {
129  global $DIC;
130 
131  $ilDB = $DIC['ilDB'];
132 
133  $query = 'SELECT * FROM ecs_data_mapping ' .
134  'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ' .
135  'AND mapping_type = ' . $ilDB->quote($this->getMappingType(), 'integer') . ' ' .
136  'AND ecs_field = ' . $ilDB->quote($this->getECSField(), 'text');
137  $res = $ilDB->query($query);
138  if ($res->numRows()) {
139  $this->update();
140  } else {
141  $this->create();
142  }
143  }
144 
149  protected function update()
150  {
151  global $DIC;
152 
153  $ilDB = $DIC['ilDB'];
154 
155  $query = 'UPDATE ecs_data_mapping ' .
156  'SET advmd_id = ' . $ilDB->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 $DIC;
166 
167  $ilDB = $DIC['ilDB'];
168 
169  $query = 'INSERT INTO ecs_data_mapping (sid,mapping_type,ecs_field,advmd_id) ' .
170  'VALUES(' .
171  $ilDB->quote($this->getServerId(), 'integer') . ', ' .
172  $ilDB->quote($this->getMappingType(), 'integer') . ', ' .
173  $ilDB->quote($this->getECSField(), 'text') . ', ' .
174  $ilDB->quote($this->getAdvMDId(), 'integer') . ' ) ';
175  $res = $ilDB->manipulate($query);
176  return true;
177  }
178 
179 
186  private function read()
187  {
188  global $DIC;
189 
190  $ilDB = $DIC['ilDB'];
191 
192  if ($this->getServerId() and $this->getMappingType() and $this->getECSField()) {
193  $query = 'SELECT * FROM ecs_data_mapping ' .
194  'WHERE sid = ' . $ilDB->quote($this->getServerId(), 'integer') . ' ' .
195  'AND mapping_type = ' . $ilDB->quote($this->getMappingType(), 'integer') . ' ' .
196  'AND ecs_field = ' . $ilDB->quote($this->getECSField(), 'text');
197  $res = $ilDB->query($query);
198  while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
199  $this->setAdvMDId($row->advmd_id);
200  }
201  }
202  }
203 
204  public static function deleteByServerId($a_server_id)
205  {
206  global $DIC;
207 
208  $ilDB = $DIC['ilDB'];
209 
210  $query = 'DELETE FROM ecs_data_mapping' .
211  ' WHERE sid = ' . $ilDB->quote($a_server_id, 'integer');
212  $ilDB->manipulate($query);
213  return true;
214  }
215 }
update()
Update setting ilDB $ilDB.
global $DIC
Definition: saml.php:7
setMappingType($mapping_type)
Set mapping type.
setServerId($a_server_id)
set server id
foreach($_POST as $key=> $value) $res
$query
$row
global $ilDB
__construct($a_server_id=0, $mapping_type=0, $ecs_field='')
constructor public