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