ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilAdvancedMDRecordScope.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
27 private int $scope_id;
28 private int $record_id;
29 private int $ref_id;
30
31 protected ilDBInterface $db;
32 protected ilLogger $logger;
33
34 public function __construct(int $a_scope_id = 0)
35 {
36 global $DIC;
37
38 $this->db = $DIC->database();
40 $this->logger = $DIC->logger()->amet();
41
42 $this->scope_id = $a_scope_id;
43 $this->read();
44 }
45
46 public function setRecordId(int $a_record_id): void
47 {
48 $this->record_id = $a_record_id;
49 }
50
51 public function getRecordId(): int
52 {
53 return $this->record_id;
54 }
55
56 public function setScopeId(int $a_scope_id): void
57 {
58 $this->scope_id = $a_scope_id;
59 }
60
61 public function getScopeId(): int
62 {
63 return $this->scope_id;
64 }
65
66 public function setRefId(int $a_ref_id): void
67 {
68 $this->ref_id = $a_ref_id;
69 }
70
71 public function getRefId(): int
72 {
73 return $this->ref_id;
74 }
75
76 public function save(): void
77 {
78 // create
79 $this->scope_id = $this->db->nextId('adv_md_record_scope');
80 $query = 'INSERT INTO adv_md_record_scope (scope_id, record_id, ref_id) ' .
81 'VALUES ( ' .
82 $this->db->quote($this->scope_id, 'integer') . ', ' .
83 $this->db->quote($this->record_id, 'integer') . ', ' .
84 $this->db->quote($this->ref_id, 'integer') .
85 ')';
86 $this->db->manipulate($query);
87 }
88
89 public function update(): void
90 {
91 $this->logger->debug('Update entry.');
92 // update (update of record ids not supported)
93 $query = 'UPDATE adv_md_record_scope ' .
94 'SET ref_id = ' . $this->db->quote($this->ref_id, 'integer') . ' ' .
95 'WHERE scope_id = ' . $this->db->quote($this->scope_id, 'integer');
96 $this->db->manipulate($query);
97 }
98
99 public function delete(): void
100 {
101 $query = 'DELETE FROM adv_md_record_scope ' .
102 'WHERE scope_id = ' . $this->db->quote($this->scope_id, 'integer');
103 $this->db->manipulate($query);
104 }
105
106 public static function deleteByRecordId(int $a_record_id): void
107 {
108 global $DIC;
109 $db = $DIC->database();
110
111 $query = 'DELETE FROM adv_md_record_scope ' .
112 'WHERE record_id = ' . $db->quote($a_record_id, 'integer');
113 $db->manipulate($query);
114 }
115
116 protected function read(): void
117 {
118 if (!$this->scope_id) {
119 return;
120 }
121 $query = 'SELECT * FROM adv_md_record_scope ' .
122 'WHERE scope_id = ' . $this->db->quote($this->scope_id, 'integer');
123 $res = $this->db->query($query);
124 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
125 $this->record_id = (int) $row->record_id;
126 $this->ref_id = (int) $row->ref_id;
127 }
128 }
129}
Scope restrictions for advanced md records.
static deleteByRecordId(int $a_record_id)
Component logger with individual log levels by component id.
Interface ilDBInterface.
quote($value, string $type)
manipulate(string $query)
Run a (write) Query on the database.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26