ILIAS  release_7 Revision v7.30-3-g800a261c036
InformationDBRepository.php
Go to the documentation of this file.
1<?php declare(strict_types=1);
2
4
8
15{
16 const TABLE_NAME = 'il_resource_info';
17 const IDENTIFICATION = 'rid';
18
22 protected $db;
23
24 protected $cache = [];
25
29 public function __construct(\ilDBInterface $db)
30 {
31 $this->db = $db;
32 }
33
34 public function getNamesForLocking() : array
35 {
36 return [self::TABLE_NAME];
37 }
38
42 public function blank()
43 {
44 return new FileInformation();
45 }
46
50 public function store(Information $information, Revision $revision) : void
51 {
52 $rid = $revision->getIdentification()->serialize();
53 $r = $this->db->queryF(
54 "SELECT " . self::IDENTIFICATION . " FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
55 [
56 'text',
57 'integer'
58 ],
59 [
60 $rid,
61 $revision->getVersionNumber()
62 ]
63 );
64
65 if ($r->numRows() > 0) {
66 // UPDATE
67 $this->db->update(
68 self::TABLE_NAME,
69 [
70 'title' => ['text', $information->getTitle()],
71 'mime_type' => ['text', $information->getMimeType()],
72 'suffix' => ['text', $information->getSuffix()],
73 'size' => ['integer', $information->getSize()],
74 'creation_date' => ['integer', $information->getCreationDate()->getTimestamp()],
75 ],
76 [
77 self::IDENTIFICATION => ['text', $rid],
78 'version_number' => ['integer', $revision->getVersionNumber()]
79 ]
80 );
81 } else {
82 // CREATE
83 $this->db->insert(
84 self::TABLE_NAME,
85 [
86 self::IDENTIFICATION => ['text', $rid],
87 'version_number' => ['integer', $revision->getVersionNumber()],
88 'title' => ['text', $information->getTitle()],
89 'mime_type' => ['text', $information->getMimeType()],
90 'suffix' => ['text', $information->getSuffix()],
91 'size' => ['integer', $information->getSize()],
92 'creation_date' => ['integer', $information->getCreationDate()->getTimestamp()],
93 ]
94 );
95 }
96 $this->cache[$rid][$revision->getVersionNumber()] = $information;
97 }
98
102 public function get(Revision $revision) : Information
103 {
104 $rid = $revision->getIdentification()->serialize();
105 if (isset($this->cache[$rid][$revision->getVersionNumber()])) {
106 return $this->cache[$rid][$revision->getVersionNumber()];
107 }
108 $r = $this->db->queryF(
109 "SELECT * FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
110 [
111 'text',
112 'integer'
113 ],
114 [
115 $rid,
116 $revision->getVersionNumber()
117 ]
118 );
119
120 $d = $this->db->fetchAssoc($r);
122
123 $this->cache[$rid][$revision->getVersionNumber()] = $i;
124
125 return $i;
126 }
127
128 public function delete(Information $information, Revision $revision) : void
129 {
130 $rid = $revision->getIdentification()->serialize();
131 $this->db->manipulateF(
132 "DELETE FROM " . self::TABLE_NAME . " WHERE " . self::IDENTIFICATION . " = %s AND version_number = %s",
133 [
134 'text',
135 'integer'
136 ],
137 [
138 $rid,
139 $revision->getVersionNumber()
140 ]
141 );
142 unset($this->cache[$rid][$revision->getVersionNumber()]);
143 }
144
145 public function preload(array $identification_strings) : void
146 {
147 $r = $this->db->query(
148 "SELECT * FROM " . self::TABLE_NAME . " WHERE " . $this->db->in(self::IDENTIFICATION,
149 $identification_strings, false, 'text')
150 );
151
152 while ($d = $this->db->fetchAssoc($r)) {
153 $this->populateFromArray($d);
154 }
155 }
156
157 public function populateFromArray(array $data) : void
158 {
159 $this->cache[$data['rid']][$data['version_number']] = $this->getFileInfoFromArrayData($data);
160 }
161
163 {
164 $i = new FileInformation();
165 $i->setTitle((string) $data['title']);
166 $i->setSize((int) $data['size']);
167 $i->setMimeType((string) $data['mime_type']);
168 $i->setSuffix((string) $data['suffix']);
169 $i->setCreationDate((new \DateTimeImmutable())->setTimestamp((int) $data['creation_date'] ?? 0));
170
171 return $i;
172 }
173}
An exception for terminatinating execution or to throw for unit testing.
store(Information $information, Revision $revision)
@inheritDoc
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$i
Definition: metadata.php:24
$data
Definition: storeScorm.php:23