19declare(strict_types=1);
34 private array
$edit_actions = [ActionTarget::EDIT, ActionTarget::EMBED_EDIT];
43 private array
$view_actions = [ActionTarget::EMBED_VIEW, ActionTarget::VIEW];
69 if (isset($cache[$suffix][$implode_targets])) {
70 return $cache[$suffix][$implode_targets];
73 $query =
'SELECT * FROM '
75 .
' WHERE ext = %s AND name IN(' . $implode_targets .
')';
77 $result = $this->db->queryF(
82 return $cache[$suffix][$implode_targets] = $result->numRows() > 0;
87 return $this->hasActionForSuffix($suffix, ...$this->edit_actions);
92 return $this->hasActionForSuffix($suffix, ...$this->view_actions);
99 if (!$this->hasActionForSuffix($suffix, $action_target)) {
103 $query =
'SELECT * FROM '
105 .
' WHERE ext = %s AND name = %s';
107 $result = $this->db->queryF($query, [
'text',
'text'], [strtolower($suffix), $action_target->value]);
108 $row = $this->db->fetchAssoc($result);
109 return $this->fromDBRow($row);
114 foreach ($this->edit_actions as $action_target) {
115 $action = $this->getActionForSuffix($suffix, $action_target);
116 if ($action !==
null) {
125 foreach ($this->view_actions as $action_target) {
126 $action = $this->getActionForSuffix($suffix, $action_target);
127 if ($action !==
null) {
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);
147 $query =
'SELECT * FROM ' . self::TABLE_NAME .
' WHERE name = %s';
148 $result = $this->db->queryF($query, [
'text'], [$action_target->value]);
150 while ($row = $this->db->fetchAssoc($result)) {
151 $actions[] = $this->fromDBRow($row);
159 foreach ($action_target as
$target) {
160 $actions[] = $this->getActionsForTarget(
$target);
162 return array_merge(...$actions);
167 $query =
'SELECT ext FROM '
169 .
' WHERE name IN (' . $this->implodeTargets(...$action_target) .
')';
170 $result = $this->db->query($query);
172 while ($row = $this->db->fetchAssoc($result)) {
173 $suffixes[] = $row[
'ext'];
184 $suffixes = array_keys($this->getCreatableFormats($with_templates));
193 foreach ($this->getEditNewFormats() as $suffix => $format) {
194 if ($with_templates || !$format[
'template']) {
195 $formats[$suffix] = $format[
'app'];
200 static fn(
string $a,
string $b):
int => strnatcasecmp($formats[
$a] .
' ' .
$a, $formats[
$b] .
' ' .
$b)
208 $suffixes = array_keys(
210 $this->getEditNewFormats(),
211 static fn(array $format):
bool => $format[
'template']
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]);
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']);
235 if (isset($formats[$suffix]) && ($template || !$formats[$suffix][
'template'])) {
238 $formats[$suffix] = [
239 'app' => (string) ($row[
'app_name'] ??
''),
240 'template' => $template,
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);
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']
272 $query =
'DELETE FROM ' . self::TABLE_NAME;
273 $this->db->manipulate($query);
278 $collected_ids = array_map(
282 $query =
'DELETE FROM ' . self::TABLE_NAME .
' WHERE ' . $this->db->in(
'id', $collected_ids,
true,
'integer');
283 $this->db->manipulate($query);
295 $query =
'SELECT * FROM ' . self::TABLE_NAME .
' WHERE name = %s AND ext = %s';
296 $types = [
'text',
'text'];
299 $query .=
' AND target_ext IS NULL';
301 $query .=
' AND target_ext = %s';
305 $result = $this->db->queryF($query, $types, $values);
307 if ($this->db->numRows($result) > 0) {
308 $row = $this->db->fetchAssoc($result);
309 $action = $action->
withId((
int) $row[
'id']);
312 if ($this->db->queryF(
313 'SELECT * FROM ' . self::TABLE_NAME .
' WHERE id = %s',
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()],
323 'app_id' => [
'integer', $for_app->
getId()],
327 $action = $action->
withId($next_id);
329 $this->db->update(self::TABLE_NAME, [
330 'name' => [
'text', $action->
getName()],
333 'app_id' => [
'integer', $for_app->
getId()],
337 'id' => [
'integer', $action->
getId()],
The scope of this class is split ilias-conform URI's into components.
getEditActionForSuffix(string $suffix)
getActionsForApp(App $app)
hasViewActionForSuffix(string $suffix)
getActionForSuffix(string $suffix, ActionTarget $action_target)
clearSuperfluous(Action ... $actions)
getCreatableSuffixes(bool $with_templates=false)
Templates such as dotx are left out unless asked for: the editnew action of a template creates a file...
getViewActionForSuffix(string $suffix)
getActionsForTarget(ActionTarget $action_target)
store(Action $action, App $for_app)
array $view_actions
The order is the preference order of getViewActionForSuffix().
hasActionForSuffix(string $suffix, ActionTarget ... $action_target)
__construct(private \ilDBInterface $db)
implodeTargets(ActionTarget ... $targets)
getCreatableFormats(bool $with_templates=false)
getActionsForTargets(ActionTarget ... $action_target)
hasEditActionForSuffix(string $suffix)
getSupportedSuffixes(ActionTarget ... $action_target)
ActionTarget
Officialy supported action targets, see https://learn.microsoft.com/en-us/openspecs/office_protocols/...
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
if(!file_exists('../ilias.ini.php'))