-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
107 lines (91 loc) · 3.24 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php declare(strict_types=1);
namespace Diva;
if (!class_exists(\Generic\AbstractModule::class)) {
require file_exists(dirname(__DIR__) . '/Generic/AbstractModule.php')
? dirname(__DIR__) . '/Generic/AbstractModule.php'
: __DIR__ . '/src/Generic/AbstractModule.php';
}
use Generic\AbstractModule;
use Laminas\EventManager\Event;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\MvcEvent;
use Omeka\Module\Exception\ModuleCannotInstallException;
use Omeka\Module\Manager as ModuleManager;
class Module extends AbstractModule
{
const NAMESPACE = __NAMESPACE__;
public function onBootstrap(MvcEvent $event): void
{
parent::onBootstrap($event);
$acl = $this->getServiceLocator()->get('Omeka\Acl');
$acl->allow(null, ['Diva\Controller\Player']);
}
protected function preInstall(): void
{
$js = __DIR__ . '/asset/vendor/diva/diva.js';
if (!file_exists($js)) {
$t = $this->getServiceLocator()->get('MvcTranslator');
throw new ModuleCannotInstallException(
$t->translate('The Diva library should be installed.') // @translate
. ' ' . $t->translate('See module’s installation documentation.') // @translate
);
}
}
public function attachListeners(SharedEventManagerInterface $sharedEventManager): void
{
/*
$sharedEventManager->attach(
'Omeka\Controller\Site\Item',
'view.browse.after',
[$this, 'handleViewBrowseAfterItem']
);
$sharedEventManager->attach(
'Omeka\Controller\Site\ItemSet',
'view.browse.after',
[$this, 'handleViewBrowseAfterItemSet']
);
*/
$sharedEventManager->attach(
'Omeka\Controller\Site\Item',
'view.show.after',
[$this, 'handleViewShowAfterItem']
);
}
public function handleViewBrowseAfterItem(Event $event): void
{
$view = $event->getTarget();
$services = $this->getServiceLocator();
// Note: there is no item-set show, but a special case for items browse.
$isItemSetShow = (bool) $services->get('Application')
->getMvcEvent()->getRouteMatch()->getParam('item-set-id');
if ($isItemSetShow) {
echo $view->diva($view->itemSet);
} elseif ($this->iiifServerIsActive()) {
echo $view->diva($view->items);
}
}
public function handleViewBrowseAfterItemSet(Event $event): void
{
if (!$this->iiifServerIsActive()) {
return;
}
$view = $event->getTarget();
echo $view->diva($view->itemSets);
}
public function handleViewShowAfterItem(Event $event): void
{
$view = $event->getTarget();
echo $view->diva($view->item);
}
protected function iiifServerIsActive()
{
static $iiifServerIsActive;
if (is_null($iiifServerIsActive)) {
$module = $this->getServiceLocator()
->get('Omeka\ModuleManager')
->getModule('IiifServer');
$iiifServerIsActive = $module && $module->getState() === ModuleManager::STATE_ACTIVE;
}
return $iiifServerIsActive;
}
}