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