ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSDataMappingSetting.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const MAPPING_EXPORT = 1;
27 public const MAPPING_IMPORT_CRS = 2;
28 public const MAPPING_IMPORT_RCRS = 3;
29
31
32 private int $server_id = 0;
33 private int $mapping_type = 0;
34 private string $ecs_field = '';
35 private int $advmd_id = 0;
36
37 public function __construct(int $a_server_id = 0, int $mapping_type = 0, string $ecs_field = '')
38 {
39 global $DIC;
40
41 $this->db = $DIC->database();
42
43 $this->setServerId($a_server_id);
44 $this->setMappingType($mapping_type);
45 $this->setECSField($ecs_field);
46 }
47
51 public function setServerId(int $a_server_id): void
52 {
53 $this->server_id = $a_server_id;
54 }
55
59 public function getServerId(): int
60 {
61 return $this->server_id;
62 }
63
64 public function setECSField(string $ecs_field): void
65 {
66 $this->ecs_field = $ecs_field;
67 }
68
72 public function getECSField(): string
73 {
74 return $this->ecs_field;
75 }
76
80 public function setMappingType(int $mapping_type): void
81 {
82 $this->mapping_type = $mapping_type;
83 }
84
88 public function getMappingType(): int
89 {
91 }
92
93 public function getAdvMDId(): int
94 {
95 return $this->advmd_id;
96 }
97
98 public function setAdvMDId(int $a_id): void
99 {
100 $this->advmd_id = $a_id;
101 }
102
106 public function save(): void
107 {
108 $query = 'SELECT * FROM ecs_data_mapping ' .
109 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ' .
110 'AND mapping_type = ' . $this->db->quote($this->getMappingType(), 'integer') . ' ' .
111 'AND ecs_field = ' . $this->db->quote($this->getECSField(), 'text');
112 $res = $this->db->query($query);
113 if ($res->numRows()) {
114 $this->update();
115 } else {
116 $this->create();
117 }
118 }
119
123 protected function update(): void
124 {
125 $query = 'UPDATE ecs_data_mapping ' .
126 'SET advmd_id = ' . $this->db->quote($this->getAdvMDId(), 'integer') . ' ' .
127 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ' .
128 'AND mapping_type = ' . $this->db->quote($this->getMappingType(), 'integer') . ' ' .
129 'AND ecs_field = ' . $this->db->quote($this->getECSField(), 'text');
130 $this->db->manipulate($query);
131 }
132
133 protected function create(): bool
134 {
135 $query = 'INSERT INTO ecs_data_mapping (sid,mapping_type,ecs_field,advmd_id) ' .
136 'VALUES(' .
137 $this->db->quote($this->getServerId(), 'integer') . ', ' .
138 $this->db->quote($this->getMappingType(), 'integer') . ', ' .
139 $this->db->quote($this->getECSField(), 'text') . ', ' .
140 $this->db->quote($this->getAdvMDId(), 'integer') . ' ) ';
141 $this->db->manipulate($query);
142 return true;
143 }
144
145
149 private function read(): void
150 {
151 if ($this->getServerId() || $this->getMappingType() || $this->getECSField()) {
152 $query = 'SELECT * FROM ecs_data_mapping ' .
153 'WHERE sid = ' . $this->db->quote($this->getServerId(), 'integer') . ' ' .
154 'AND mapping_type = ' . $this->db->quote($this->getMappingType(), 'integer') . ' ' .
155 'AND ecs_field = ' . $this->db->quote($this->getECSField(), 'text');
156 $res = $this->db->query($query);
157 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
158 $this->setAdvMDId($row->advmd_id);
159 }
160 }
161 }
162}
setMappingType(int $mapping_type)
Set mapping type.
__construct(int $a_server_id=0, int $mapping_type=0, string $ecs_field='')
setServerId(int $a_server_id)
set server id
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26