ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLTIProviderObjectSetting.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
29 private ?\ilLogger $log = null;
30
31 private ?\ilDBInterface $db = null;
32
33 private int $ref_id = 0;
34 private int $consumer_id = 0;
35 private int $admin = 0;
36 private int $tutor = 0;
37 private int $member = 0;
38
42 public function __construct(int $a_ref_id, int $a_ext_consumer_id)
43 {
44 global $DIC;
45
46 $this->log = ilLoggerFactory::getLogger('ltis');
47 $this->db = $DIC->database();
48
49 $this->ref_id = $a_ref_id;
50 $this->consumer_id = $a_ext_consumer_id;
51
52 $ok = $this->read();
53 if (!$ok) {
54 $this->log->warning("no ref_id set");
55 }
56 }
57
58
59 public function setAdminRole(int $a_role): void
60 {
61 $this->admin = $a_role;
62 }
63
64 public function getAdminRole(): int
65 {
66 return $this->admin;
67 }
68
69 public function setTutorRole(int $a_role): void
70 {
71 $this->tutor = $a_role;
72 }
73
74 public function getTutorRole(): int
75 {
76 return $this->tutor;
77 }
78
79 public function setMemberRole(int $a_role): void
80 {
81 $this->member = $a_role;
82 }
83
84 public function getMemberRole(): int
85 {
86 return $this->member;
87 }
88
92 public function setConsumerId(int $a_consumer_id): void
93 {
94 $this->consumer_id = $a_consumer_id;
95 }
96
97 public function getConsumerId(): int
98 {
99 return $this->consumer_id;
100 }
101
102
106 public function delete(): void
107 {
108 $query = 'DELETE FROM lti_int_provider_obj ' .
109 'WHERE ref_id = ' . $this->db->quote($this->ref_id, 'integer') . ' ' .
110 'AND ext_consumer_id = ' . $this->db->quote($this->getConsumerId(), 'integer');
111 $this->db->manipulate($query);
112 }
113
114 public function save(): void
115 {
116 $this->delete();
117
118 $query = 'INSERT INTO lti_int_provider_obj ' .
119 '(ref_id,ext_consumer_id,admin,tutor,member) VALUES( ' .
120 $this->db->quote($this->ref_id, 'integer') . ', ' .
121 $this->db->quote($this->getConsumerId(), 'integer') . ', ' .
122 $this->db->quote($this->getAdminRole(), 'integer') . ', ' .
123 $this->db->quote($this->getTutorRole(), 'integer') . ', ' .
124 $this->db->quote($this->getMemberRole(), 'integer') .
125 ' )';
126 $this->db->manipulate($query);
127 }
128
132 protected function read(): bool
133 {
134 if (!$this->ref_id) {
135 return false;
136 }
137
138 $query = 'SELECT * FROM lti_int_provider_obj ' .
139 'WHERE ref_id = ' . $this->db->quote($this->ref_id, 'integer') . ' ' .
140 'AND ext_consumer_id = ' . $this->db->quote($this->getConsumerId(), 'integer');
141
142 $res = $this->db->query($query);
143 while ($row = $res->fetchObject()) {
144 $this->ref_id = (int) $row->ref_id;
145 $this->consumer_id = (int) $row->ext_consumer_id;
146 $this->setAdminRole((int) $row->admin);
147 $this->setTutorRole((int) $row->tutor);
148 $this->setMemberRole((int) $row->member);
149 }
150 return true;
151 }
152}
setConsumerId(int $a_consumer_id)
Set consumer id.
__construct(int $a_ref_id, int $a_ext_consumer_id)
Constructor.
static getLogger(string $a_component_id)
Get component logger.
Component logger with individual log levels by component id.
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26