Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jajm committed Apr 29, 2016
0 parents commit d423b37
Show file tree
Hide file tree
Showing 37 changed files with 3,330 additions and 0 deletions.
517 changes: 517 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

120 changes: 120 additions & 0 deletions Module.php
@@ -0,0 +1,120 @@
<?php

/*
* Copyright BibLibre, 2016
*
* This software is governed by the CeCILL license under French law and abiding
* by the rules of distribution of free software. You can use, modify and/ or
* redistribute the software under the terms of the CeCILL license as circulated
* by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify
* and redistribute granted by the license, users are provided only with a
* limited warranty and the software's author, the holder of the economic
* rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with
* loading, using, modifying and/or developing or reproducing the software by
* the user in light of its specific status of free software, that may mean that
* it is complicated to manipulate, and that also therefore means that it is
* reserved for developers and experienced professionals having in-depth
* computer knowledge. Users are therefore encouraged to load and test the
* software's suitability as regards their requirements in conditions enabling
* the security of their systems and/or data to be ensured and, more generally,
* to use and operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/

namespace Search;

use Zend\Mvc\Controller\AbstractController;
use Zend\Mvc\MvcEvent;
use Zend\ServiceManager\ServiceLocatorInterface;
use Omeka\Module\AbstractModule;

class Module extends AbstractModule
{
public function getConfig()
{
return include __DIR__ . '/config/module.config.php';
}

public function onBootstrap(MvcEvent $event)
{
parent::onBootstrap($event);

$this->addRoutes();
}

public function install(ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
$sql = '
CREATE TABLE IF NOT EXISTS `search_index` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`adapter` varchar(255) NOT NULL,
`settings` text,
`created` datetime NOT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
';
$connection->exec($sql);
$sql = '
CREATE TABLE IF NOT EXISTS `search_page` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`path` varchar(255) NOT NULL,
`index_id` int(11) unsigned NOT NULL,
`form` varchar(255) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`),
FOREIGN KEY (`index_id`) REFERENCES `search_index` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
';
$connection->exec($sql);
}

public function uninstall(ServiceLocatorInterface $serviceLocator)
{
$connection = $serviceLocator->get('Omeka\Connection');
$sql = 'DROP TABLE IF EXISTS `search_page`';
$connection->exec($sql);
$sql = 'DROP TABLE IF EXISTS `search_index`';
$connection->exec($sql);
}

protected function addRoutes()
{
$serviceLocator = $this->getServiceLocator();
$settings = $serviceLocator->get('Omeka\Settings');
$router = $serviceLocator->get('Router');
$api = $serviceLocator->get('Omeka\ApiManager');

if (!$router instanceof \Zend\Mvc\Router\Http\TreeRouteStack) {
return;
}

$pages = $api->search('search_pages')->getContent();
foreach ($pages as $page) {
$path = $page->path();
$router->addRoute('search-' . $path, [
'type' => 'segment',
'options' => [
'route' => '/s/:site-slug/' . $path,
'defaults' => [
'__NAMESPACE__' => 'Search\Controller',
'__SITE__' => true,
'controller' => 'Index',
'action' => 'search',
'id' => $page->id(),
],
],
]);
}
}
}
131 changes: 131 additions & 0 deletions config/module.config.php
@@ -0,0 +1,131 @@
<?php
return [
'controllers' => [
'invokables' => [
'Search\Controller\Index' => 'Search\Controller\IndexController',
'Search\Controller\Admin\Index' => 'Search\Controller\Admin\IndexController',
'Search\Controller\Admin\SearchIndex' => 'Search\Controller\Admin\SearchIndexController',
'Search\Controller\Admin\SearchPage' => 'Search\Controller\Admin\SearchPageController',
],
],
'entity_manager' => [
'mapping_classes_paths' => [
__DIR__ . '/../src/Entity',
],
],
'api_adapters' => [
'invokables' => [
'search_indexes' => 'Search\Api\Adapter\SearchIndexAdapter',
'search_pages' => 'Search\Api\Adapter\SearchPageAdapter',
],
],
'navigation' => [
'admin' => [
[
'label' => 'Search',
'route' => 'admin/search',
'resource' => 'Search\Controller\Admin\Index',
'privilege' => 'browse',
'class' => 'o-icon-search',
],
],
],
'navigation_links' => [
'invokables' => [
'search-page' => 'Search\Site\Navigation\Link\SearchPage',
],
],
'router' =>[
'routes' => [
'admin' => [
'child_routes' => [
'search' => [
'type' => 'Segment',
'options' => [
'route' => '/search',
'defaults' => [
'__NAMESPACE__' => 'Search\Controller\Admin',
'controller' => 'Index',
'action' => 'browse',
],
],
'may_terminate' => true,
'child_routes' => [
'index' => [
'type' => 'Segment',
'options' => [
'route' => '/index/:action',
'defaults' => [
'__NAMESPACE__' => 'Search\Controller\Admin',
'controller' => 'SearchIndex',
],
'constraints' => [
'id' => '\d+',
],
],
],
'index-id' => [
'type' => 'Segment',
'options' => [
'route' => '/index/:id[/:action]',
'defaults' => [
'__NAMESPACE__' => 'Search\Controller\Admin',
'controller' => 'SearchIndex',
'action' => 'show',
],
'constraints' => [
'id' => '\d+',
],
],
],
'page' => [
'type' => 'Segment',
'options' => [
'route' => '/page/:action',
'defaults' => [
'__NAMESPACE__' => 'Search\Controller\Admin',
'controller' => 'SearchPage',
],
'constraints' => [
'id' => '\d+',
],
],
],
'page-id' => [
'type' => 'Segment',
'options' => [
'route' => '/page/:id[/:action]',
'defaults' => [
'__NAMESPACE__' => 'Search\Controller\Admin',
'controller' => 'SearchPage',
'action' => 'show',
],
'constraints' => [
'id' => '\d+',
],
],
],
],
],
],
],
],
],
'service_manager' => [
'factories' => [
'Search\AdapterManager' => 'Search\Service\AdapterManagerFactory',
'Search\FormManager' => 'Search\Service\FormManagerFactory',
],
],
'view_manager' => [
'template_path_stack' => [
__DIR__ . '/../view',
],
],
'search' => [
'adapters' => [],
'forms' => [
'basic' => 'Search\Form\BasicForm',
],
]
];
5 changes: 5 additions & 0 deletions config/module.ini
@@ -0,0 +1,5 @@
name="Search"
author="BibLibre"
description="Add search capabilities to Omeka S"
module_link="https://github.com/biblibre/omeka-s-module-Search"
version="0.1"
40 changes: 40 additions & 0 deletions src/Adapter/AdapterInterface.php
@@ -0,0 +1,40 @@
<?php

/*
* Copyright BibLibre, 2016
*
* This software is governed by the CeCILL license under French law and abiding
* by the rules of distribution of free software. You can use, modify and/ or
* redistribute the software under the terms of the CeCILL license as circulated
* by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify
* and redistribute granted by the license, users are provided only with a
* limited warranty and the software's author, the holder of the economic
* rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with
* loading, using, modifying and/or developing or reproducing the software by
* the user in light of its specific status of free software, that may mean that
* it is complicated to manipulate, and that also therefore means that it is
* reserved for developers and experienced professionals having in-depth
* computer knowledge. Users are therefore encouraged to load and test the
* software's suitability as regards their requirements in conditions enabling
* the security of their systems and/or data to be ensured and, more generally,
* to use and operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/

namespace Search\Adapter;

use Zend\ServiceManager\ServiceLocatorInterface;

interface AdapterInterface
{
public function getLabel();
public function getConfigForm(ServiceLocatorInterface $serviceLocator);
public function getIndexerClass();
public function getQuerierClass();
}
70 changes: 70 additions & 0 deletions src/Adapter/Manager.php
@@ -0,0 +1,70 @@
<?php

/*
* Copyright BibLibre, 2016
*
* This software is governed by the CeCILL license under French law and abiding
* by the rules of distribution of free software. You can use, modify and/ or
* redistribute the software under the terms of the CeCILL license as circulated
* by CEA, CNRS and INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify
* and redistribute granted by the license, users are provided only with a
* limited warranty and the software's author, the holder of the economic
* rights, and the successive licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with
* loading, using, modifying and/or developing or reproducing the software by
* the user in light of its specific status of free software, that may mean that
* it is complicated to manipulate, and that also therefore means that it is
* reserved for developers and experienced professionals having in-depth
* computer knowledge. Users are therefore encouraged to load and test the
* software's suitability as regards their requirements in conditions enabling
* the security of their systems and/or data to be ensured and, more generally,
* to use and operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/

namespace Search\Adapter;

class Manager
{
protected $config;

public function __construct($config)
{
$this->config = $config;
}

public function get($name)
{
if (!isset($this->config[$name])) {
return null;
}

$class = $this->config[$name];
if (!class_exists($class)) {
return null;
}

if (!in_array('Search\Adapter\AdapterInterface', class_implements($class))) {
return null;
}

return new $class;
}

public function getAll()
{
$adapters = [];
foreach ($this->config as $name => $class) {
$adapter = $this->get($name);
if ($adapter !== null) {
$adapters[$name] = $adapter;
}
}
return $adapters;
}
}

0 comments on commit d423b37

Please sign in to comment.