ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\WOPI\Discovery\ActionDBRepository Class Reference
+ Inheritance diagram for ILIAS\WOPI\Discovery\ActionDBRepository:
+ Collaboration diagram for ILIAS\WOPI\Discovery\ActionDBRepository:

Public Member Functions

 __construct (private \ilDBInterface $db)
 
 hasActionForSuffix (string $suffix, ActionTarget ... $action_target)
 
 hasEditActionForSuffix (string $suffix)
 
 hasViewActionForSuffix (string $suffix)
 
 getActionForSuffix (string $suffix, ActionTarget $action_target)
 
 getEditActionForSuffix (string $suffix)
 
 getViewActionForSuffix (string $suffix)
 
 getActions ()
 
 getActionsForTarget (ActionTarget $action_target)
 
 getActionsForTargets (ActionTarget ... $action_target)
 
 getSupportedSuffixes (ActionTarget ... $action_target)
 
 getActionsForApp (App $app)
 
 clear ()
 
 clearSuperfluous (Action ... $actions)
 
 store (Action $action, App $for_app)
 
 hasEditActionForSuffix (string $suffix)
 
 hasViewActionForSuffix (string $suffix)
 
 hasActionForSuffix (string $suffix, ActionTarget ... $action_target)
 
 getActionForSuffix (string $suffix, ActionTarget $action_target)
 
 getEditActionForSuffix (string $suffix)
 
 getViewActionForSuffix (string $suffix)
 
 getActions ()
 
 getActionsForTarget (ActionTarget $action_target)
 
 getActionsForTargets (ActionTarget ... $action_target)
 
 getSupportedSuffixes (ActionTarget ... $action_target)
 
 clearSuperfluous (Action ... $actions)
 
 store (Action $action, App $for_app)
 
 clear ()
 

Private Member Functions

 implodeTargets (ActionTarget ... $targets)
 
 fromDBRow (array $row)
 

Private Attributes

const TABLE_NAME = 'wopi_action'
 
array $edit_actions = [ActionTarget::EDIT, ActionTarget::EMBED_EDIT]
 
array $view_actions = [ActionTarget::VIEW, ActionTarget::EMBED_VIEW]
 

Detailed Description

Author
Fabian Schmid fabia.nosp@m.n@sr.nosp@m..solu.nosp@m.tion.nosp@m.s

Definition at line 28 of file ActionDBRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\WOPI\Discovery\ActionDBRepository::__construct ( private \ilDBInterface  $db)

Definition at line 37 of file ActionDBRepository.php.

39 {
40 }

Member Function Documentation

◆ clear()

ILIAS\WOPI\Discovery\ActionDBRepository::clear ( )

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 193 of file ActionDBRepository.php.

193 : void
194 {
195 $query = 'DELETE FROM ' . self::TABLE_NAME;
196 $this->db->manipulate($query);
197 }

◆ clearSuperfluous()

ILIAS\WOPI\Discovery\ActionDBRepository::clearSuperfluous ( Action ...  $actions)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 199 of file ActionDBRepository.php.

199 : void
200 {
201 $collected_ids = array_map(
202 static fn(Action $act): int => $act->getId(),
203 $actions
204 );
205 $query = 'DELETE FROM ' . self::TABLE_NAME . ' WHERE ' . $this->db->in('id', $collected_ids, true, 'integer');
206 $this->db->manipulate($query);
207 }

References ILIAS\WOPI\Discovery\Action\getId().

+ Here is the call graph for this function:

◆ fromDBRow()

ILIAS\WOPI\Discovery\ActionDBRepository::fromDBRow ( array  $row)
private

Definition at line 181 of file ActionDBRepository.php.

181 : Action
182 {
183 return new Action(
184 (int) $row['id'],
185 (string) $row['name'],
186 (string) $row['ext'],
187 new URI((string) $row['urlsrc']),
188 empty($row['url_appendix']) ? null : (string) $row['url_appendix'],
189 empty($row['target_text']) ? null : (string) $row['target_text']
190 );
191 }

◆ getActionForSuffix()

ILIAS\WOPI\Discovery\ActionDBRepository::getActionForSuffix ( string  $suffix,
ActionTarget  $action_target 
)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 87 of file ActionDBRepository.php.

90 : ?Action {
91 if (!$this->hasActionForSuffix($suffix, $action_target)) {
92 return null;
93 }
94
95 $query = 'SELECT * FROM '
96 . self::TABLE_NAME
97 . ' WHERE ext = %s AND name = %s';
98
99 $result = $this->db->queryF($query, ['text', 'text'], [strtolower($suffix), $action_target->value]);
100 $row = $this->db->fetchAssoc($result);
101 return $this->fromDBRow($row);
102 }
hasActionForSuffix(string $suffix, ActionTarget ... $action_target)

◆ getActions()

ILIAS\WOPI\Discovery\ActionDBRepository::getActions ( )
Returns
Action[]

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 126 of file ActionDBRepository.php.

126 : array
127 {
128 $actions = [];
129 $query = 'SELECT * FROM ' . self::TABLE_NAME;
130 $result = $this->db->query($query);
131 while ($row = $this->db->fetchAssoc($result)) {
132 $actions[] = $this->fromDBRow($row);
133 }
134 return $actions;
135 }

◆ getActionsForApp()

ILIAS\WOPI\Discovery\ActionDBRepository::getActionsForApp ( App  $app)

Definition at line 170 of file ActionDBRepository.php.

170 : array
171 {
172 $actions = [];
173 $query = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE app_id = %s';
174 $result = $this->db->queryF($query, ['integer'], [$app->getId()]);
175 while ($row = $this->db->fetchAssoc($result)) {
176 $actions[] = $this->fromDBRow($row);
177 }
178 return $actions;
179 }

References ILIAS\WOPI\Discovery\App\getId().

+ Here is the call graph for this function:

◆ getActionsForTarget()

ILIAS\WOPI\Discovery\ActionDBRepository::getActionsForTarget ( ActionTarget  $action_target)
Returns
Action[]

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 137 of file ActionDBRepository.php.

137 : array
138 {
139 $query = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE name = %s';
140 $result = $this->db->queryF($query, ['text'], [$action_target->value]);
141 $actions = [];
142 while ($row = $this->db->fetchAssoc($result)) {
143 $actions[] = $this->fromDBRow($row);
144 }
145 return $actions;
146 }

◆ getActionsForTargets()

ILIAS\WOPI\Discovery\ActionDBRepository::getActionsForTargets ( ActionTarget ...  $action_target)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 148 of file ActionDBRepository.php.

148 : array
149 {
150 $actions = [];
151 foreach ($action_target as $target) {
152 $actions += $this->getActionsForTarget($target);
153 }
154 return $actions;
155 }
getActionsForTarget(ActionTarget $action_target)

◆ getEditActionForSuffix()

ILIAS\WOPI\Discovery\ActionDBRepository::getEditActionForSuffix ( string  $suffix)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 104 of file ActionDBRepository.php.

104 : ?Action
105 {
106 foreach ($this->edit_actions as $action_target) {
107 $action = $this->getActionForSuffix($suffix, $action_target);
108 if ($action !== null) {
109 return $action;
110 }
111 }
112 return null;
113 }
getActionForSuffix(string $suffix, ActionTarget $action_target)

◆ getSupportedSuffixes()

ILIAS\WOPI\Discovery\ActionDBRepository::getSupportedSuffixes ( ActionTarget ...  $action_target)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 157 of file ActionDBRepository.php.

157 : array
158 {
159 $query = 'SELECT ext FROM '
160 . self::TABLE_NAME
161 . ' WHERE name IN (' . $this->implodeTargets(...$action_target) . ')';
162 $result = $this->db->query($query);
163 $suffixes = [];
164 while ($row = $this->db->fetchAssoc($result)) {
165 $suffixes[] = $row['ext'];
166 }
167 return $suffixes;
168 }
implodeTargets(ActionTarget ... $targets)

◆ getViewActionForSuffix()

ILIAS\WOPI\Discovery\ActionDBRepository::getViewActionForSuffix ( string  $suffix)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 115 of file ActionDBRepository.php.

115 : ?Action
116 {
117 foreach ($this->view_actions as $action_target) {
118 $action = $this->getActionForSuffix($suffix, $action_target);
119 if ($action !== null) {
120 return $action;
121 }
122 }
123 return null;
124 }

◆ hasActionForSuffix()

ILIAS\WOPI\Discovery\ActionDBRepository::hasActionForSuffix ( string  $suffix,
ActionTarget ...  $action_target 
)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 53 of file ActionDBRepository.php.

56 : bool {
57 static $cache = [];
58
59 $implode_targets = $this->implodeTargets(...$action_target);
60
61 if (isset($cache[$suffix][$implode_targets])) {
62 return $cache[$suffix][$implode_targets];
63 }
64
65 $query = 'SELECT * FROM '
66 . self::TABLE_NAME
67 . ' WHERE ext = %s AND name IN(' . $implode_targets . ')';
68
69 $result = $this->db->queryF(
70 $query,
71 ['text'],
72 [strtolower($suffix)]
73 );
74 return $cache[$suffix][$implode_targets] = $result->numRows() > 0;
75 }

◆ hasEditActionForSuffix()

ILIAS\WOPI\Discovery\ActionDBRepository::hasEditActionForSuffix ( string  $suffix)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 77 of file ActionDBRepository.php.

77 : bool
78 {
79 return $this->hasActionForSuffix($suffix, ...$this->edit_actions);
80 }

◆ hasViewActionForSuffix()

ILIAS\WOPI\Discovery\ActionDBRepository::hasViewActionForSuffix ( string  $suffix)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 82 of file ActionDBRepository.php.

82 : bool
83 {
84 return $this->hasActionForSuffix($suffix, ...$this->view_actions);
85 }

◆ implodeTargets()

ILIAS\WOPI\Discovery\ActionDBRepository::implodeTargets ( ActionTarget ...  $targets)
private

Definition at line 42 of file ActionDBRepository.php.

42 : string
43 {
44 return implode(
45 ', ',
46 array_map(
47 fn(ActionTarget $target): string => $this->db->quote($target->value, 'text'),
48 $targets
49 )
50 );
51 }
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...

◆ store()

ILIAS\WOPI\Discovery\ActionDBRepository::store ( Action  $action,
App  $for_app 
)

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 209 of file ActionDBRepository.php.

209 : void
210 {
211 // store only actions with extensions
212 if (empty($action->getExtension())) {
213 return;
214 }
215
216 // check for existing action to update them
217 $query = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE name = %s AND ext = %s AND target_ext = %s';
218 $result = $this->db->queryF(
219 $query,
220 ['text', 'text', 'text'],
221 [$action->getName(), $action->getExtension(), $action->getTargetExtension()]
222 );
223
224 if ($this->db->numRows($result) > 0) {
225 $row = $this->db->fetchAssoc($result);
226 $action = $action->withId((int) $row['id']);
227 }
228
229 if ($this->db->queryF(
230 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE id = %s',
231 ['integer'],
232 [$action->getId()]
233 )->numRows() === 0) {
234 $next_id = $this->db->nextId(self::TABLE_NAME);
235 $this->db->insert(self::TABLE_NAME, [
236 'id' => ['integer', $next_id],
237 'name' => ['text', $action->getName()],
238 'ext' => ['text', strtolower($action->getExtension())],
239 'urlsrc' => ['text', $action->getLauncherUrl()],
240 'app_id' => ['integer', $for_app->getId()],
241 'url_appendix' => ['text', $action->getUrlAppendix()],
242 'target_ext' => ['text', $action->getTargetExtension()],
243 ]);
244 $action = $action->withId($next_id);
245 } else {
246 $this->db->update(self::TABLE_NAME, [
247 'name' => ['text', $action->getName()],
248 'ext' => ['text', strtolower($action->getExtension())],
249 'urlsrc' => ['text', $action->getLauncherUrl()],
250 'app_id' => ['integer', $for_app->getId()],
251 'url_appendix' => ['text', $action->getUrlAppendix()],
252 'target_ext' => ['text', $action->getTargetExtension()],
253 ], [
254 'id' => ['integer', $action->getId()],
255 ]);
256 }
257 }

References ILIAS\WOPI\Discovery\Action\getExtension(), ILIAS\WOPI\Discovery\Action\getId(), ILIAS\WOPI\Discovery\App\getId(), ILIAS\WOPI\Discovery\Action\getLauncherUrl(), ILIAS\WOPI\Discovery\Action\getName(), ILIAS\WOPI\Discovery\Action\getTargetExtension(), ILIAS\WOPI\Discovery\Action\getUrlAppendix(), and ILIAS\WOPI\Discovery\Action\withId().

+ Here is the call graph for this function:

Field Documentation

◆ $edit_actions

array ILIAS\WOPI\Discovery\ActionDBRepository::$edit_actions = [ActionTarget::EDIT, ActionTarget::EMBED_EDIT]
private

Definition at line 34 of file ActionDBRepository.php.

◆ $view_actions

array ILIAS\WOPI\Discovery\ActionDBRepository::$view_actions = [ActionTarget::VIEW, ActionTarget::EMBED_VIEW]
private

Definition at line 35 of file ActionDBRepository.php.

◆ TABLE_NAME

const ILIAS\WOPI\Discovery\ActionDBRepository::TABLE_NAME = 'wopi_action'
private

Definition at line 33 of file ActionDBRepository.php.


The documentation for this class was generated from the following file: