ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilECSDataMappingSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 private static ?array $instances = null;
27
29 private array $mappings;
30
31 private ilDbInterface $db;
35 private function __construct(int $a_server_id)
36 {
37 global $DIC;
38 $this->db = $DIC->database();
39
40 $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
41 $this->read();
42 }
43
47 public static function getInstanceByServerId(int $a_server_id): ilECSDataMappingSettings
48 {
49 return self::$instances[$a_server_id] ?? (self::$instances[$a_server_id] = new ilECSDataMappingSettings($a_server_id));
50 }
51
55 public function delete(): void
56 {
57 $server_id = $this->settings->getServerId();
58 unset(self::$instances[$server_id]);
59
60 $query = 'DELETE from ecs_data_mapping ' .
61 'WHERE sid = ' . $this->db->quote($server_id, 'integer');
62 $this->db->manipulate($query);
63 }
64
68 public function getServer(): ilECSSetting
69 {
70 return $this->settings;
71 }
72
73
78 public function getMappings($a_mapping_type = ilECSDataMappingSetting::MAPPING_IMPORT_RCRS): array
79 {
80 return $this->mappings[$a_mapping_type];
81 }
82
83
92 public function getMappingByECSName(int $a_mapping_type, string $a_key): int
93 {
94 return $this->mappings[$a_mapping_type][$a_key] ?? 0;
95 }
96
97
98
103 private function read(): void
104 {
105 $this->mappings = array();
106
107 $query = 'SELECT * FROM ecs_data_mapping ' .
108 'WHERE sid = ' . $this->db->quote($this->getServer()->getServerId(), 'integer') . ' ';
109 $res = $this->db->query($query);
110 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
111 $this->mappings[$row->mapping_type][$row->ecs_field] = (int) $row->advmd_id;
112 }
113 }
114}
getMappings($a_mapping_type=ilECSDataMappingSetting::MAPPING_IMPORT_RCRS)
get mappings
getMappingByECSName(int $a_mapping_type, string $a_key)
get mapping by key
static getInstanceByServerId(int $a_server_id)
Get singleton instance.
__construct(int $a_server_id)
Singleton Constructor.
static getInstanceByServerId(int $a_server_id)
Get singleton instance per server.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26