◆ __construct()
UploadPolicyDBRepository::__construct |
( |
protected readonly ilDBInterface |
$db | ) |
|
◆ delete()
Definition at line 94 of file UploadPolicyDBRepository.php.
94 : void
95 {
96 if (
null === ($policy_id = $policy->
getPolicyId())) {
97 return;
98 }
99
100 $query = "DELETE FROM il_upload_policy WHERE policy_id = %s";
101 $this->db->manipulateF($query, ['integer'], [$policy_id]);
102 }
◆ get()
UploadPolicyDBRepository::get |
( |
int |
$policy_id | ) |
|
Definition at line 67 of file UploadPolicyDBRepository.php.
68 {
69 $query = "SELECT * FROM il_upload_policy WHERE policy_id = %s";
70 $result = $this->db->queryF($query, ['integer'], [$policy_id]);
71 if (null !== ($dataset = $this->db->fetchObject($result))) {
73 }
74
75 return null;
76 }
transformToDtoOrAbort(stdClass $dataset)
References transformToDtoOrAbort().
◆ getAll()
UploadPolicyDBRepository::getAll |
( |
| ) |
|
- Returns
- UploadPolicy[]
Definition at line 81 of file UploadPolicyDBRepository.php.
81 : array
82 {
83 $query = "SELECT * FROM il_upload_policy";
84 $result = $this->db->query($query);
85
86 $upload_policies = [];
87 while (null !== ($dataset = $this->db->fetchObject($result))) {
89 }
90
91 return $upload_policies;
92 }
References transformToDtoOrAbort().
◆ getDateObject()
UploadPolicyDBRepository::getDateObject |
( |
string |
$date_string | ) |
|
|
protected |
Returns a datetime object with '00:00:00' as H:i:s to avoid comparison errors because PHP will use the current time automatically otherwise.
Definition at line 143 of file UploadPolicyDBRepository.php.
143 : DateTimeImmutable
144 {
145 return
146 (DateTimeImmutable::createFromFormat(self::MYSQL_DATETIME_FORMAT, $date_string . ' 00:00:00')) ?:
147 throw new LogicException("Could not create DateTimeImmutable from '$date_string'.");
148 }
Referenced by transformToDtoOrAbort().
◆ getDateString()
UploadPolicyDBRepository::getDateString |
( |
DateTimeImmutable |
$date | ) |
|
|
protected |
◆ getDateTimeObject()
UploadPolicyDBRepository::getDateTimeObject |
( |
string |
$date_time_string | ) |
|
|
protected |
Definition at line 155 of file UploadPolicyDBRepository.php.
155 : DateTimeImmutable
156 {
157 return
158 (DateTimeImmutable::createFromFormat(self::MYSQL_DATETIME_FORMAT, $date_time_string)) ?:
159 throw new LogicException("Could not create DateTimeImmutable from '$date_time_string'.");
160 }
Referenced by transformToDtoOrAbort().
◆ getDateTimeString()
UploadPolicyDBRepository::getDateTimeString |
( |
DateTimeImmutable |
$date_time | ) |
|
|
protected |
◆ missingRequiredField()
UploadPolicyDBRepository::missingRequiredField |
( |
string |
$field_name | ) |
|
|
protected |
◆ store()
Definition at line 33 of file UploadPolicyDBRepository.php.
33 : void
34 {
35 $data_for_storage = [
36 "title" => [
'text', $policy->
getTitle()],
38 "audience" => [
'text', json_encode($policy->
getAudience(), JSON_THROW_ON_ERROR)],
41 "active" => [
'integer', $policy->
isActive()],
43 "valid_until" => [
44 'date',
45 (null !== ($until = $policy->getValidUntil())) ? $this->
getDateString($until) : null
46 ],
47 "owner" => ['integer', $policy->getOwnerId()],
48 "last_update" => [
'timestamp', $this->
getDateTimeString($policy->getLastUpdate())]
49 ];
50
51 if (
null !== ($policy_id = $policy->
getPolicyId()) &&
null !== $this->get($policy_id)) {
52
53 $this->db->update(
54 "il_upload_policy",
55 $data_for_storage,
56 ["policy_id" => ['integer', $policy_id]]
57 );
58 } else {
59
60 $data_for_storage["policy_id"] = ['integer', $this->db->nextId("il_upload_policy")];
62
63 $this->db->insert("il_upload_policy", $data_for_storage);
64 }
65 }
getDateString(DateTimeImmutable $date)
getDateTimeString(DateTimeImmutable $date_time)
References UploadPolicy\getAudience(), UploadPolicy\getAudienceType(), UploadPolicy\getCreateDate(), getDateString(), getDateTimeString(), UploadPolicy\getLastUpdate(), UploadPolicy\getOwnerId(), UploadPolicy\getPolicyId(), UploadPolicy\getScopeDefinition(), UploadPolicy\getTitle(), UploadPolicy\getUploadLimitInMB(), UploadPolicy\getValidFrom(), UploadPolicy\getValidUntil(), and UploadPolicy\isActive().
◆ transformToDtoOrAbort()
UploadPolicyDBRepository::transformToDtoOrAbort |
( |
stdClass |
$dataset | ) |
|
|
protected |
- Exceptions
-
LogicException | if required data is missing |
Definition at line 107 of file UploadPolicyDBRepository.php.
108 {
110
111 $valid_from = (
null !== ($from = $dataset?->valid_from)) ? $this->
getDateObject((
string) $from) : null;
112 $valid_until = (
null !== ($until = $dataset?->valid_until)) ? $this->
getDateObject((
string) $until) : null;
113
117 $dataset->upload_limit_in_mb ?? $this->missingRequiredField('upload_limit_in_mb'),
118 json_decode((string) $audience_json, true, 512, JSON_THROW_ON_ERROR),
122 $valid_from,
123 $valid_until,
127 ),
130 )
131 );
132 }
getDateObject(string $date_string)
Returns a datetime object with '00:00:00' as H:i:s to avoid comparison errors because PHP will use th...
getDateTimeObject(string $date_time_string)
missingRequiredField(string $field_name)
References getDateObject(), getDateTimeObject(), and missingRequiredField().
Referenced by get(), and getAll().
◆ MYSQL_DATE_FORMAT
const UploadPolicyDBRepository::MYSQL_DATE_FORMAT = 'Y-m-d' |
|
protected |
◆ MYSQL_DATETIME_FORMAT
const UploadPolicyDBRepository::MYSQL_DATETIME_FORMAT = 'Y-m-d H:i:s' |
|
protected |
The documentation for this class was generated from the following file: