-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathPreferences.php
More file actions
96 lines (81 loc) · 2.51 KB
/
Preferences.php
File metadata and controls
96 lines (81 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2020 Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Polls\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
/**
* @psalm-suppress UnusedProperty
* @method int getId()
* @method void setId(int $value)
* @method string getUserId()
* @method void setUserId(string $value)
* @method string getTimestamp()
* @method void setTimestamp(int $value)
* @method void setPreferences(string $value)
*/
class Preferences extends Entity implements JsonSerializable {
public const TABLE = 'polls_preferences';
public const DEFAULT = [
'useCommentsAlternativeStyling' => false,
'useAlternativeStyling' => false,
'calendarPeek' => false,
'checkCalendars' => [],
'checkCalendarsHoursBefore' => 0,
'checkCalendarsHoursAfter' => 0,
'defaultViewTextPoll' => 'table-view',
'defaultViewDatePoll' => 'table-view',
'performanceThreshold' => 1000,
'pollCombo' => [],
'relevantOffset' => 30,
];
// schema columns
public $id = 0;
protected string $userId = '';
protected int $timestamp = 0;
protected ?string $preferences = '';
public function __construct() {
$this->addType('timestamp', 'integer');
// initialize with default values
$this->setPreferences(json_encode(self::DEFAULT));
}
public function getPreferences(): string {
return $this->preferences ?? '';
}
public function getPreferences_decoded(): mixed {
return json_decode($this->getPreferences());
}
public function getCheckCalendarsHoursBefore(): int {
if (isset($this->getPreferences_decoded()->checkCalendarsHoursBefore)) {
return intval($this->getPreferences_decoded()->checkCalendarsHoursBefore);
}
// in case old property name is used, return the value
if (isset($this->getPreferences_decoded()->checkCalendarsBefore)) {
return intval($this->getPreferences_decoded()->checkCalendarsBefore);
}
return 0;
}
public function getCheckCalendarsHoursAfter(): int {
if (isset($this->getPreferences_decoded()->checkCalendarsHoursAfter)) {
return intval($this->getPreferences_decoded()->checkCalendarsHoursAfter);
}
// in case old property name is used, return the value
if (isset($this->getPreferences_decoded()->checkCalendarsAfter)) {
return intval($this->getPreferences_decoded()->checkCalendarsAfter);
}
return 0;
}
/**
* @return array
*
* @psalm-suppress PossiblyUnusedMethod
*/
public function jsonSerialize(): array {
return [
'preferences' => json_decode((string)$this->preferences),
];
}
}