ILIAS  release_8 Revision v8.24
class.ilECSDataMappingSettings.php
Go to the documentation of this file.
1<?php
2
18declare(strict_types=1);
19
24{
25 private static ?array $instances = null;
26
28 private array $mappings;
29
30 private ilDbInterface $db;
34 private function __construct(int $a_server_id)
35 {
36 global $DIC;
37 $this->db = $DIC->database();
38
39 $this->settings = ilECSSetting::getInstanceByServerId($a_server_id);
40 $this->read();
41 }
42
46 public static function getInstanceByServerId(int $a_server_id): ilECSDataMappingSettings
47 {
48 return self::$instances[$a_server_id] ?? (self::$instances[$a_server_id] = new ilECSDataMappingSettings($a_server_id));
49 }
50
54 public function delete(): void
55 {
56 $server_id = $this->settings->getServerId();
57 unset(self::$instances[$server_id]);
58
59 $query = 'DELETE from ecs_data_mapping ' .
60 'WHERE sid = ' . $this->db->quote($server_id, 'integer');
61 $this->db->manipulate($query);
62 }
63
67 public function getServer(): ilECSSetting
68 {
69 return $this->settings;
70 }
71
72
77 public function getMappings($a_mapping_type = ilECSDataMappingSetting::MAPPING_IMPORT_RCRS): array
78 {
79 return $this->mappings[$a_mapping_type];
80 }
81
82
91 public function getMappingByECSName(int $a_mapping_type, string $a_key): int
92 {
93 return $this->mappings[$a_mapping_type][$a_key] ?? 0;
94 }
95
96
97
102 private function read(): void
103 {
104 $this->mappings = array();
105
106 $query = 'SELECT * FROM ecs_data_mapping ' .
107 'WHERE sid = ' . $this->db->quote($this->getServer()->getServerId(), 'integer') . ' ';
108 $res = $this->db->query($query);
109 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
110 $this->mappings[$row->mapping_type][$row->ecs_field] = (int) $row->advmd_id;
111 }
112 }
113}
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.
global $DIC
Definition: feed.php:28
$res
Definition: ltiservices.php:69
$query