ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
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)
 
 getCreatableSuffixes (bool $with_templates=false)
 Templates such as dotx are left out unless asked for: the editnew action of a template creates a file with another extension (newext). More...
 
 getCreatableFormats (bool $with_templates=false)
 
 getTemplateSuffixes ()
 
 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)
 
 getCreatableSuffixes (bool $with_templates=false)
 
 getCreatableFormats (bool $with_templates=false)
 
 getTemplateSuffixes ()
 
 clearSuperfluous (Action ... $actions)
 
 store (Action $action, App $for_app)
 
 clear ()
 

Private Member Functions

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

Private Attributes

const TABLE_NAME = 'wopi_action'
 
array $edit_actions = [ActionTarget::EDIT, ActionTarget::EMBED_EDIT]
 
array $view_actions = [ActionTarget::EMBED_VIEW, ActionTarget::VIEW]
 The order is the preference order of getViewActionForSuffix(). More...
 

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 45 of file ActionDBRepository.php.

47 {
48 }

Member Function Documentation

◆ clear()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 270 of file ActionDBRepository.php.

270 : void
271 {
272 $query = 'DELETE FROM ' . self::TABLE_NAME;
273 $this->db->manipulate($query);
274 }

◆ clearSuperfluous()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 276 of file ActionDBRepository.php.

276 : void
277 {
278 $collected_ids = array_map(
279 static fn(Action $act): int => $act->getId(),
280 $actions
281 );
282 $query = 'DELETE FROM ' . self::TABLE_NAME . ' WHERE ' . $this->db->in('id', $collected_ids, true, 'integer');
283 $this->db->manipulate($query);
284 }

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 258 of file ActionDBRepository.php.

258 : Action
259 {
260 return new Action(
261 (int) $row['id'],
262 (string) $row['name'],
263 (string) $row['ext'],
264 new URI((string) $row['urlsrc']),
265 empty($row['url_appendix']) ? null : (string) $row['url_appendix'],
266 empty($row['target_ext']) ? null : (string) $row['target_ext']
267 );
268 }

◆ getActionForSuffix()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 95 of file ActionDBRepository.php.

98 : ?Action {
99 if (!$this->hasActionForSuffix($suffix, $action_target)) {
100 return null;
101 }
102
103 $query = 'SELECT * FROM '
104 . self::TABLE_NAME
105 . ' WHERE ext = %s AND name = %s';
106
107 $result = $this->db->queryF($query, ['text', 'text'], [strtolower($suffix), $action_target->value]);
108 $row = $this->db->fetchAssoc($result);
109 return $this->fromDBRow($row);
110 }
hasActionForSuffix(string $suffix, ActionTarget ... $action_target)

◆ getActions()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 134 of file ActionDBRepository.php.

134 : array
135 {
136 $actions = [];
137 $query = 'SELECT * FROM ' . self::TABLE_NAME;
138 $result = $this->db->query($query);
139 while ($row = $this->db->fetchAssoc($result)) {
140 $actions[] = $this->fromDBRow($row);
141 }
142 return $actions;
143 }

◆ getActionsForApp()

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

Definition at line 247 of file ActionDBRepository.php.

247 : array
248 {
249 $actions = [];
250 $query = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE app_id = %s';
251 $result = $this->db->queryF($query, ['integer'], [$app->getId()]);
252 while ($row = $this->db->fetchAssoc($result)) {
253 $actions[] = $this->fromDBRow($row);
254 }
255 return $actions;
256 }

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 145 of file ActionDBRepository.php.

145 : array
146 {
147 $query = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE name = %s';
148 $result = $this->db->queryF($query, ['text'], [$action_target->value]);
149 $actions = [];
150 while ($row = $this->db->fetchAssoc($result)) {
151 $actions[] = $this->fromDBRow($row);
152 }
153 return $actions;
154 }

◆ getActionsForTargets()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 156 of file ActionDBRepository.php.

156 : array
157 {
158 $actions = [];
159 foreach ($action_target as $target) {
160 $actions[] = $this->getActionsForTarget($target);
161 }
162 return array_merge(...$actions);
163 }
getActionsForTarget(ActionTarget $action_target)

References ILIAS\Scripts\PHPStan\$target.

◆ getCreatableFormats()

ILIAS\WOPI\Discovery\ActionDBRepository::getCreatableFormats ( bool  $with_templates = false)
Returns
array<string, string> suffix => name of the app creating it, sorted by the name

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 190 of file ActionDBRepository.php.

190 : array
191 {
192 $formats = [];
193 foreach ($this->getEditNewFormats() as $suffix => $format) {
194 if ($with_templates || !$format['template']) {
195 $formats[$suffix] = $format['app'];
196 }
197 }
198 uksort(
199 $formats,
200 static fn(string $a, string $b): int => strnatcasecmp($formats[$a] . ' ' . $a, $formats[$b] . ' ' . $b)
201 );
202
203 return $formats;
204 }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References Vendor\Package\$a, and Vendor\Package\$b.

◆ getCreatableSuffixes()

ILIAS\WOPI\Discovery\ActionDBRepository::getCreatableSuffixes ( bool  $with_templates = false)

Templates such as dotx are left out unless asked for: the editnew action of a template creates a file with another extension (newext).

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 182 of file ActionDBRepository.php.

182 : array
183 {
184 $suffixes = array_keys($this->getCreatableFormats($with_templates));
185 sort($suffixes);
186
187 return $suffixes;
188 }
getCreatableFormats(bool $with_templates=false)

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ getEditActionForSuffix()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 112 of file ActionDBRepository.php.

112 : ?Action
113 {
114 foreach ($this->edit_actions as $action_target) {
115 $action = $this->getActionForSuffix($suffix, $action_target);
116 if ($action !== null) {
117 return $action;
118 }
119 }
120 return null;
121 }
getActionForSuffix(string $suffix, ActionTarget $action_target)

◆ getEditNewFormats()

ILIAS\WOPI\Discovery\ActionDBRepository::getEditNewFormats ( )
private
Returns
array<string, array{app: string, template: bool}> by lowercased extension; an extension which is offered as a regular format as well is not a template

Definition at line 223 of file ActionDBRepository.php.

223 : array
224 {
225 $query = 'SELECT a.ext, a.target_ext, p.name app_name FROM ' . self::TABLE_NAME . ' a'
226 . ' LEFT JOIN wopi_app p ON p.id = a.app_id'
227 . ' WHERE a.name = %s';
228 $result = $this->db->queryF($query, ['text'], [ActionTarget::EDIT_NEW->value]);
229
230 $formats = [];
231 while ($row = $this->db->fetchAssoc($result)) {
232 $suffix = strtolower((string) $row['ext']);
233 $target = empty($row['target_ext']) ? null : strtolower((string) $row['target_ext']);
234 $template = $target !== null && $target !== $suffix;
235 if (isset($formats[$suffix]) && ($template || !$formats[$suffix]['template'])) {
236 continue;
237 }
238 $formats[$suffix] = [
239 'app' => (string) ($row['app_name'] ?? ''),
240 'template' => $template,
241 ];
242 }
243
244 return $formats;
245 }

References ILIAS\Scripts\PHPStan\$target.

◆ getSupportedSuffixes()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 165 of file ActionDBRepository.php.

165 : array
166 {
167 $query = 'SELECT ext FROM '
168 . self::TABLE_NAME
169 . ' WHERE name IN (' . $this->implodeTargets(...$action_target) . ')';
170 $result = $this->db->query($query);
171 $suffixes = [];
172 while ($row = $this->db->fetchAssoc($result)) {
173 $suffixes[] = $row['ext'];
174 }
175 return $suffixes;
176 }
implodeTargets(ActionTarget ... $targets)

◆ getTemplateSuffixes()

ILIAS\WOPI\Discovery\ActionDBRepository::getTemplateSuffixes ( )
Returns
string[] suffixes of templates such as dotx a new document can be created for, sorted

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 206 of file ActionDBRepository.php.

206 : array
207 {
208 $suffixes = array_keys(
209 array_filter(
210 $this->getEditNewFormats(),
211 static fn(array $format): bool => $format['template']
212 )
213 );
214 sort($suffixes);
215
216 return $suffixes;
217 }

References ILIAS\UI\examples\Symbol\Glyph\Sort\sort().

+ Here is the call graph for this function:

◆ getViewActionForSuffix()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 123 of file ActionDBRepository.php.

123 : ?Action
124 {
125 foreach ($this->view_actions as $action_target) {
126 $action = $this->getActionForSuffix($suffix, $action_target);
127 if ($action !== null) {
128 return $action;
129 }
130 }
131 return null;
132 }

◆ hasActionForSuffix()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 61 of file ActionDBRepository.php.

64 : bool {
65 static $cache = [];
66
67 $implode_targets = $this->implodeTargets(...$action_target);
68
69 if (isset($cache[$suffix][$implode_targets])) {
70 return $cache[$suffix][$implode_targets];
71 }
72
73 $query = 'SELECT * FROM '
74 . self::TABLE_NAME
75 . ' WHERE ext = %s AND name IN(' . $implode_targets . ')';
76
77 $result = $this->db->queryF(
78 $query,
79 ['text'],
80 [strtolower($suffix)]
81 );
82 return $cache[$suffix][$implode_targets] = $result->numRows() > 0;
83 }

◆ hasEditActionForSuffix()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 85 of file ActionDBRepository.php.

85 : bool
86 {
87 return $this->hasActionForSuffix($suffix, ...$this->edit_actions);
88 }

◆ hasViewActionForSuffix()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 90 of file ActionDBRepository.php.

90 : bool
91 {
92 return $this->hasActionForSuffix($suffix, ...$this->view_actions);
93 }

◆ implodeTargets()

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

Definition at line 50 of file ActionDBRepository.php.

50 : string
51 {
52 return implode(
53 ', ',
54 array_map(
55 fn(ActionTarget $target): string => $this->db->quote($target->value, 'text'),
56 $targets
57 )
58 );
59 }
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...

References ILIAS\Scripts\PHPStan\$target.

◆ store()

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

Implements ILIAS\WOPI\Discovery\ActionRepository.

Definition at line 286 of file ActionDBRepository.php.

286 : void
287 {
288 // store only actions with extensions
289 if (empty($action->getExtension())) {
290 return;
291 }
292
293 // check for existing action to update them
294 // most actions have no target extension, "target_ext = NULL" would never match them
295 $query = 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE name = %s AND ext = %s';
296 $types = ['text', 'text'];
297 $values = [$action->getName(), strtolower($action->getExtension())];
298 if ($action->getTargetExtension() === null) {
299 $query .= ' AND target_ext IS NULL';
300 } else {
301 $query .= ' AND target_ext = %s';
302 $types[] = 'text';
303 $values[] = $action->getTargetExtension();
304 }
305 $result = $this->db->queryF($query, $types, $values);
306
307 if ($this->db->numRows($result) > 0) {
308 $row = $this->db->fetchAssoc($result);
309 $action = $action->withId((int) $row['id']);
310 }
311
312 if ($this->db->queryF(
313 'SELECT * FROM ' . self::TABLE_NAME . ' WHERE id = %s',
314 ['integer'],
315 [$action->getId()]
316 )->numRows() === 0) {
317 $next_id = $this->db->nextId(self::TABLE_NAME);
318 $this->db->insert(self::TABLE_NAME, [
319 'id' => ['integer', $next_id],
320 'name' => ['text', $action->getName()],
321 'ext' => ['text', strtolower($action->getExtension())],
322 'urlsrc' => ['text', $action->getLauncherUrl()],
323 'app_id' => ['integer', $for_app->getId()],
324 'url_appendix' => ['text', $action->getUrlAppendix()],
325 'target_ext' => ['text', $action->getTargetExtension()],
326 ]);
327 $action = $action->withId($next_id);
328 } else {
329 $this->db->update(self::TABLE_NAME, [
330 'name' => ['text', $action->getName()],
331 'ext' => ['text', strtolower($action->getExtension())],
332 'urlsrc' => ['text', $action->getLauncherUrl()],
333 'app_id' => ['integer', $for_app->getId()],
334 'url_appendix' => ['text', $action->getUrlAppendix()],
335 'target_ext' => ['text', $action->getTargetExtension()],
336 ], [
337 'id' => ['integer', $action->getId()],
338 ]);
339 }
340 }

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::EMBED_VIEW, ActionTarget::VIEW]
private

The order is the preference order of getViewActionForSuffix().

The embedded viewer comes first on purpose: the content tab of a file object is a viewer and offers no way into edit mode, so the full viewer of the WOPI client - which advertises editing and then has to explain why it is not available - is the wrong experience here. Falls back to the regular view action where the discovery offers no embedded one.

Definition at line 43 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: