ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilLearningSequenceActivationDB.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 public const TABLE_NAME = 'lso_activation';
27
29
31 {
32 $this->database = $database;
33 }
34
36 {
37 $data = $this->select($ref_id);
38 if (count($data) == 0) {
39 $settings = $this->buildActivationSettings($ref_id);
40 $this->insert($settings);
41 } else {
42 if ($data['activation_start_ts']) {
43 $start = new \DateTime();
44 $start->setTimestamp((int) $data['activation_start_ts']);
45 } else {
46 $start = null;
47 }
48
49 if ($data['activation_end_ts']) {
50 $end = new \DateTime();
51 $end->setTimestamp((int) $data['activation_end_ts']);
52 } else {
53 $end = null;
54 }
55
56 $settings = $this->buildActivationSettings(
57 (int) $data['ref_id'],
58 (bool) $data['online'],
59 (bool) $data['effective_online'],
60 $start,
61 $end
62 );
63 }
64
65 return $settings;
66 }
67
68 public function deleteForRefId(int $ref_id): void
69 {
70 $query = "DELETE FROM " . static::TABLE_NAME . PHP_EOL
71 . "WHERE ref_id = " . $this->database->quote($ref_id, "integer") . PHP_EOL
72 ;
73 $this->database->manipulate($query);
74 }
75
76 public function store(ilLearningSequenceActivation $settings): void
77 {
78 $where = [
79 "ref_id" => ["integer", $settings->getRefId()]
80 ];
81
82 $start = $settings->getActivationStart();
83 $end = $settings->getActivationEnd();
84
85 if ($start) {
86 $start = $start->getTimestamp();
87 }
88
89 if ($end) {
90 $end = $end->getTimestamp();
91 }
92
93 $values = [
94 "online" => ["integer", $settings->getIsOnline()],
95 "activation_start_ts" => ["integer", $start],
96 "activation_end_ts" => ["integer", $end]
97 ];
98
99 $this->database->update(static::TABLE_NAME, $values, $where);
100 }
101
102 protected function insert(ilLearningSequenceActivation $settings): void
103 {
104 $start = $settings->getActivationStart();
105 $end = $settings->getActivationEnd();
106
107 if ($start) {
108 $start = $start->getTimestamp();
109 }
110
111 if ($end) {
112 $end = $end->getTimestamp();
113 }
114
115 $values = [
116 "ref_id" => ["integer", $settings->getRefId()],
117 "online" => ["integer", $settings->getIsOnline()],
118 "effective_online" => ["integer", $settings->getEffectiveOnlineStatus()],
119 "activation_start_ts" => ["integer", $start],
120 "activation_end_ts" => ["integer", $end]
121 ];
122
123 $this->database->insert(static::TABLE_NAME, $values);
124 }
125
129 protected function select(int $ref_id): array
130 {
131 $ret = [];
132 $query =
133 "SELECT ref_id, online, effective_online, activation_start_ts, activation_end_ts" . PHP_EOL
134 . "FROM " . static::TABLE_NAME . PHP_EOL
135 . "WHERE ref_id = " . $this->database->quote($ref_id, "integer") . PHP_EOL
136 ;
137
138 $result = $this->database->query($query);
139
140 if ($this->database->numRows($result) !== 0) {
141 $ret = $this->database->fetchAssoc($result);
142 }
143
144 return $ret;
145 }
146
147 protected function buildActivationSettings(
148 int $ref_id,
149 bool $online = false,
150 bool $effective_online = false,
151 ?\DateTime $activation_start = null,
152 ?\DateTime $activation_end = null
155 $ref_id,
156 $online,
157 $effective_online,
158 $activation_start,
159 $activation_end
160 );
161 }
162
163 public function setEffectiveOnlineStatus(int $ref_id, bool $status): void
164 {
165 $where = ["ref_id" => ["integer", $ref_id]];
166 $values = ["effective_online" => ["integer", $status]];
167
168 $this->database->update(static::TABLE_NAME, $values, $where);
169 }
170}
Persistence for online/activation period.
buildActivationSettings(int $ref_id, bool $online=false, bool $effective_online=false, ?\DateTime $activation_start=null, ?\DateTime $activation_end=null)
insert(ilLearningSequenceActivation $settings)
store(ilLearningSequenceActivation $settings)
return['delivery_method'=> 'php',]
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
$ref_id
Definition: ltiauth.php:66