18 declare(strict_types=1);
35 "title" => [
'text', $policy->
getTitle()],
37 "audience" => [
'text', json_encode($policy->
getAudience(), JSON_THROW_ON_ERROR)],
40 "active" => [
'integer', $policy->
isActive()],
50 if (null !== ($policy_id = $policy->
getPolicyId()) && null !== $this->
get($policy_id)) {
55 [
"policy_id" => [
'integer', $policy_id]]
59 $data_for_storage[
"policy_id"] = [
'integer', $this->db->nextId(
"il_upload_policy")];
62 $this->db->insert(
"il_upload_policy", $data_for_storage);
68 $query =
"SELECT * FROM il_upload_policy WHERE policy_id = %s";
69 $result = $this->db->queryF($query, [
'integer'], [$policy_id]);
70 if (null !== ($dataset = $this->db->fetchObject($result))) {
82 $query =
"SELECT * FROM il_upload_policy";
83 $result = $this->db->query($query);
85 $upload_policies = [];
86 while (null !== ($dataset = $this->db->fetchObject($result))) {
90 return $upload_policies;
95 if (null === ($policy_id = $policy->getPolicyId())) {
99 $query =
"DELETE FROM il_upload_policy WHERE policy_id = %s";
100 $this->db->manipulateF($query, [
'integer'], [$policy_id]);
110 $valid_from = (null !== ($from = $dataset?->valid_from)) ? $this->
getDateObject((
string) $from) : null;
111 $valid_until = (null !== ($until = $dataset?->valid_until)) ? $this->
getDateObject((
string) $until) : null;
116 $dataset->upload_limit_in_mb ?? $this->missingRequiredField(
'upload_limit_in_mb'),
117 json_decode((
string) $audience_json,
true, 512, JSON_THROW_ON_ERROR),
135 return $date->format(self::MYSQL_DATE_FORMAT);
145 (DateTimeImmutable::createFromFormat(self::MYSQL_DATETIME_FORMAT, $date_string .
' 00:00:00')) ?:
146 throw new LogicException(
"Could not create DateTimeImmutable from '$date_string'.");
151 return $date_time->format(self::MYSQL_DATETIME_FORMAT);
157 (DateTimeImmutable::createFromFormat(self::MYSQL_DATETIME_FORMAT, $date_time_string)) ?:
158 throw new LogicException(
"Could not create DateTimeImmutable from '$date_time_string'.");
166 throw new LogicException(
"Could not retrieve data for required field '$field_name'.");
transformToDtoOrAbort(stdClass $dataset)
getDateTimeString(DateTimeImmutable $date_time)
getDateString(DateTimeImmutable $date)
__construct(protected readonly ilDBInterface $db)
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)
const MYSQL_DATETIME_FORMAT
store(UploadPolicy $policy)
missingRequiredField(string $field_name)