-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModule.php
62 lines (51 loc) · 2.74 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
<?php
namespace CatalogSearch;
use Omeka\Module\AbstractModule;
use Laminas\EventManager\SharedEventManagerInterface;
use Laminas\Mvc\Controller\AbstractController;
use Laminas\Mvc\MvcEvent;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\View\Renderer\PhpRenderer;
class Module extends AbstractModule
{
public function onBootstrap(MvcEvent $event)
{
parent::onBootstrap($event);
$serviceLocator = $this->getServiceLocator();
$acl = $serviceLocator->get('Omeka\Acl');
$acl->allow(null, Api\Adapter\CatalogAdapter::class, ['search', 'read']);
}
public function install(ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
$connection->executeStatement(<<<SQL
CREATE TABLE catalog_search_catalog (
id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(255) NOT NULL,
search_url LONGTEXT NOT NULL,
position INT DEFAULT 0 NOT NULL,
simple_query TINYINT(1) DEFAULT '0' NOT NULL,
enabled TINYINT(1) DEFAULT '0' NOT NULL,
PRIMARY KEY(id)
) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB
SQL);
$stmt = $connection->prepare('INSERT INTO catalog_search_catalog (name, search_url, position, simple_query, enabled) VALUES (?, ?, ?, ?, ?)');
$stmt->executeStatement(['Archive Grid', 'http://beta.worldcat.org/archivegrid/?q=%s', 0, 1, 1]);
$stmt->executeStatement(['Digital Public Library of America', 'http://dp.la/search?utf8=%E2%9C%93&q=%s', 1, 0, 1]);
$stmt->executeStatement(['Google Books', 'https://www.google.com/search?btnG=Search+Books&tbm=bks&tbo=1&q=%s', 2, 1, 1]);
$stmt->executeStatement(['Google Scholar', 'http://scholar.google.com/scholar?btnG=&as_sdt=1%2C22&as_sdtp=&q=%s', 3, 1, 1]);
$stmt->executeStatement(['Hathi Trust', 'http://catalog.hathitrust.org/Search/Home?lookfor=%s&searchtype=all&ft=&setft=false', 4, 0, 1]);
$stmt->executeStatement(['JSTOR', 'http://www.jstor.org/action/doBasicSearch?Query=%s', 5, 1, 1]);
$stmt->executeStatement(['Library of Congress', 'http://catalog.loc.gov/vwebv/search?searchArg=%s&searchCode=GKEY%5E*&searchType=0', 6, 0, 1]);
$stmt->executeStatement(['WorldCat', 'http://www.worldcat.org/search?qt=worldcat_org_all&q=%s', 7, 0, 1]);
}
public function uninstall(ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
$connection->executeStatement('DROP TABLE IF EXISTS catalog_search_catalog');
}
public function getConfig()
{
return require __DIR__ . '/config/module.config.php';
}
}