From b072beed888f992c1d26dffadcf2cf4c8f5daab3 Mon Sep 17 00:00:00 2001 From: buttle Date: Sun, 24 Oct 2021 12:01:37 +0200 Subject: [PATCH 1/7] puts route/controller structure in place --- config/module.config.php | 22 ++++++++++++++++++-- src/Controller/ArchiveSiteMetaController.php | 13 ++++++++++++ view/archiveSiteMeta/collections/index.phtml | 0 view/collections/index.phtml | 0 4 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/Controller/ArchiveSiteMetaController.php create mode 100644 view/archiveSiteMeta/collections/index.phtml create mode 100644 view/collections/index.phtml diff --git a/config/module.config.php b/config/module.config.php index 077878a..581fcce 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -1,16 +1,34 @@ [ + 'routes' => [ + 'archiveSiteMeta' => [ + 'type' => \Laminas\Router\Http\Literal::class, + 'options' => [ + 'route' => '/collections', + 'defaults' => [ + 'controller' => Controller\ArchiveSiteMeta::class, + 'action' => 'index', + ], + ], + ], + ], + ], 'view_manager' => [ 'template_path_stack' => [ dirname(__DIR__) . '/view', ], 'template_map' => [ + // used to remove available blocks when editing a page + 'omeka/site-admin/page/edit' => __DIR__ . '/../../../themes/archive/view/omeka/site-admin/page/edit.phtml', + //'layout/layout' => __DIR__ . '/../../../themes/archive/view/layout/layout.phtml', //'omeka/index/index' => __DIR__ . '/../../../themes/archive/view/omeka/site/index/index.phtml', - 'omeka/search/results' => __DIR__ . '/../../../themes/archive/view/omeka/search/results.phtml', - 'omeka/site-admin/page/edit' => __DIR__ . '/../../../themes/archive/view/omeka/site-admin/page/edit.phtml', + //'omeka/search/results' => __DIR__ . '/../../../themes/archive/view/omeka/search/results.phtml', //'common/site-list-entry' => __DIR__ . '/../../../themes/archive/view/common/site-list-entry.phtml', ], ], diff --git a/src/Controller/ArchiveSiteMetaController.php b/src/Controller/ArchiveSiteMetaController.php new file mode 100644 index 0000000..d4a48d0 --- /dev/null +++ b/src/Controller/ArchiveSiteMetaController.php @@ -0,0 +1,13 @@ + Date: Sun, 24 Oct 2021 22:42:03 +0200 Subject: [PATCH 2/7] controller resolves template map --- config/module.config.php | 10 ++++++++-- src/Controller/ArchiveSiteMetaController.php | 8 ++++++++ view/archiveSiteMeta/collections/index.phtml | 0 view/collections/index.phtml | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) delete mode 100644 view/archiveSiteMeta/collections/index.phtml diff --git a/config/module.config.php b/config/module.config.php index 581fcce..7f103b9 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -11,13 +11,19 @@ return [ 'options' => [ 'route' => '/collections', 'defaults' => [ - 'controller' => Controller\ArchiveSiteMeta::class, + '__NAMESPACE__' => 'ArchiveSiteMeta\Controller', + 'controller' => Controller\ArchiveSiteMetaController::class, 'action' => 'index', ], ], ], ], ], + 'controllers' => [ + 'invokables' => [ + Controller\ArchiveSiteMetaController::class => Controller\ArchiveSiteMetaController::class, + ], + ], 'view_manager' => [ 'template_path_stack' => [ dirname(__DIR__) . '/view', @@ -25,7 +31,7 @@ return [ 'template_map' => [ // used to remove available blocks when editing a page 'omeka/site-admin/page/edit' => __DIR__ . '/../../../themes/archive/view/omeka/site-admin/page/edit.phtml', - + 'archive-site-meta/archive-site-meta/index' => __DIR__ . '/../view/collections/index.phtml', //'layout/layout' => __DIR__ . '/../../../themes/archive/view/layout/layout.phtml', //'omeka/index/index' => __DIR__ . '/../../../themes/archive/view/omeka/site/index/index.phtml', //'omeka/search/results' => __DIR__ . '/../../../themes/archive/view/omeka/search/results.phtml', diff --git a/src/Controller/ArchiveSiteMetaController.php b/src/Controller/ArchiveSiteMetaController.php index d4a48d0..9fcf529 100644 --- a/src/Controller/ArchiveSiteMetaController.php +++ b/src/Controller/ArchiveSiteMetaController.php @@ -6,8 +6,16 @@ use Laminas\View\Model\ViewModel; class ArchiveSiteMetaController extends AbstractActionController { + + public function __construct() + { + + } + public function indexAction() { + $view = new ViewModel; + return $view; } } diff --git a/view/archiveSiteMeta/collections/index.phtml b/view/archiveSiteMeta/collections/index.phtml deleted file mode 100644 index e69de29..0000000 diff --git a/view/collections/index.phtml b/view/collections/index.phtml index e69de29..fd4d315 100644 --- a/view/collections/index.phtml +++ b/view/collections/index.phtml @@ -0,0 +1,3 @@ + + + -- 2.39.5 From dffeb3ff33efee2565268223a3a02fe9f68c14e7 Mon Sep 17 00:00:00 2001 From: buttle Date: Sun, 24 Oct 2021 23:55:07 +0200 Subject: [PATCH 3/7] returns json --- config/module.config.php | 5 ++++- src/Controller/ArchiveSiteMetaController.php | 13 ++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/config/module.config.php b/config/module.config.php index 7f103b9..d0b4af5 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -28,10 +28,13 @@ return [ 'template_path_stack' => [ dirname(__DIR__) . '/view', ], + 'strategies' => [ + 'ViewJsonStrategy', + ], 'template_map' => [ // used to remove available blocks when editing a page 'omeka/site-admin/page/edit' => __DIR__ . '/../../../themes/archive/view/omeka/site-admin/page/edit.phtml', - 'archive-site-meta/archive-site-meta/index' => __DIR__ . '/../view/collections/index.phtml', + //'archive-site-meta/archive-site-meta/index' => __DIR__ . '/../view/collections/index.phtml', //'layout/layout' => __DIR__ . '/../../../themes/archive/view/layout/layout.phtml', //'omeka/index/index' => __DIR__ . '/../../../themes/archive/view/omeka/site/index/index.phtml', //'omeka/search/results' => __DIR__ . '/../../../themes/archive/view/omeka/search/results.phtml', diff --git a/src/Controller/ArchiveSiteMetaController.php b/src/Controller/ArchiveSiteMetaController.php index 9fcf529..4afb211 100644 --- a/src/Controller/ArchiveSiteMetaController.php +++ b/src/Controller/ArchiveSiteMetaController.php @@ -2,7 +2,8 @@ namespace ArchiveSiteMeta\Controller; use Laminas\Mvc\Controller\AbstractActionController; -use Laminas\View\Model\ViewModel; +#use Laminas\View\Model\ViewModel; +use Laminas\View\Model\JsonModel; class ArchiveSiteMetaController extends AbstractActionController { @@ -14,8 +15,14 @@ class ArchiveSiteMetaController extends AbstractActionController public function indexAction() { - $view = new ViewModel; - return $view; + return new JsonModel([ + 'status' => 'SUCCESS', + 'message'=>'Here is your data', + 'data' => [ + 'full_name' => 'John Doe', + 'address' => '51 Middle st.' + ] + ]); } } -- 2.39.5 From ea5e33d0a204f7f2cf65fe0dc2e870ad5462fc57 Mon Sep 17 00:00:00 2001 From: buttle Date: Wed, 3 Nov 2021 21:43:15 +0100 Subject: [PATCH 4/7] returns weighted search results --- config/module.config.php | 5 +- src/Controller/ArchiveSiteMetaController.php | 63 ++++++++++++++++---- 2 files changed, 56 insertions(+), 12 deletions(-) diff --git a/config/module.config.php b/config/module.config.php index d0b4af5..ac72a0e 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -7,9 +7,12 @@ return [ 'router' => [ 'routes' => [ 'archiveSiteMeta' => [ + //'type' => \Laminas\Router\Http\Segment::class, 'type' => \Laminas\Router\Http\Literal::class, 'options' => [ - 'route' => '/collections', + //'route' => '/collections[/:action]', + //'route' => '/collections', + 'route' => '/collections/search', 'defaults' => [ '__NAMESPACE__' => 'ArchiveSiteMeta\Controller', 'controller' => Controller\ArchiveSiteMetaController::class, diff --git a/src/Controller/ArchiveSiteMetaController.php b/src/Controller/ArchiveSiteMetaController.php index 4afb211..c8cf267 100644 --- a/src/Controller/ArchiveSiteMetaController.php +++ b/src/Controller/ArchiveSiteMetaController.php @@ -2,7 +2,6 @@ namespace ArchiveSiteMeta\Controller; use Laminas\Mvc\Controller\AbstractActionController; -#use Laminas\View\Model\ViewModel; use Laminas\View\Model\JsonModel; class ArchiveSiteMetaController extends AbstractActionController @@ -12,17 +11,59 @@ class ArchiveSiteMetaController extends AbstractActionController { } - public function indexAction() { - return new JsonModel([ - 'status' => 'SUCCESS', - 'message'=>'Here is your data', - 'data' => [ - 'full_name' => 'John Doe', - 'address' => '51 Middle st.' - ] - ]); - } + $query = [ + 'limit' => 10, + //'in_sites' => true, + 'fulltext_search' => $this->params()->fromQuery('fulltext_search'), + ]; + $resources = [ + 'site_pages' => [ + 'action' => 'site-pages', + 'query' => $query, + 'response' => null, + ], + 'items' => [ + 'action' => 'items', + 'query' => array_merge($query, ['in_sites' => true]), + 'response' => null, + ], + /* + 'item_sets' => [ + 'action' => 'item-sets', + 'query' => array_merge($query, ['in_sites' => true]), + 'response' => null, + ], + */ + ]; + + $resourceNames = ['site_pages', 'items']; + + //$ids = $this->api()->search('site_pages', $query)->getContent(); + //$ids = $this->api()->search('site_pages', $query, ['return' => 'site'])->getContent(); + //$ids = $this->api()->search('site_pages', $query, ['returnScalar' => 'site'])->getContent(); + + $query_results = array(); + $items = $this->api()->search('items', $resources['items']['query'])->getContent(); + foreach($items as $item) { + foreach($item->sites() as $site){ + array_push($query_results, $site->id()); + } + } + $pages = $this->api()->search('site_pages', $resources['site_pages']['query'], ['returnScalar' => 'site'])->getContent(); + foreach($pages as $page) { + array_push($query_results, (int)$page); + } + $search_results = []; + foreach($query_results as $site_id) { + if (array_key_exists($site_id, $search_results)) { + $search_results[$site_id] = $search_results[$site_id] + 1; + } else { + $search_results[$site_id] = 1; + } + } + return new JsonModel($search_results); + } } -- 2.39.5 From 52c86af842af625594e7d6088797146e77adc885 Mon Sep 17 00:00:00 2001 From: buttle Date: Thu, 4 Nov 2021 12:12:41 +0100 Subject: [PATCH 5/7] adds collections search api endpoint --- config/module.config.php | 4 +--- src/Controller/ArchiveSiteMetaController.php | 4 +++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/config/module.config.php b/config/module.config.php index ac72a0e..020b8b3 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -10,9 +10,7 @@ return [ //'type' => \Laminas\Router\Http\Segment::class, 'type' => \Laminas\Router\Http\Literal::class, 'options' => [ - //'route' => '/collections[/:action]', - //'route' => '/collections', - 'route' => '/collections/search', + 'route' => '/api/collections/search', 'defaults' => [ '__NAMESPACE__' => 'ArchiveSiteMeta\Controller', 'controller' => Controller\ArchiveSiteMetaController::class, diff --git a/src/Controller/ArchiveSiteMetaController.php b/src/Controller/ArchiveSiteMetaController.php index c8cf267..9980ef9 100644 --- a/src/Controller/ArchiveSiteMetaController.php +++ b/src/Controller/ArchiveSiteMetaController.php @@ -52,7 +52,9 @@ class ArchiveSiteMetaController extends AbstractActionController array_push($query_results, $site->id()); } } - $pages = $this->api()->search('site_pages', $resources['site_pages']['query'], ['returnScalar' => 'site'])->getContent(); + $pages = $this->api()->search('site_pages', + $resources['site_pages']['query'], + ['returnScalar' => 'site'])->getContent(); foreach($pages as $page) { array_push($query_results, (int)$page); } -- 2.39.5 From 82d895d7e769d4676b1683276be13b54dbc9ef5c Mon Sep 17 00:00:00 2001 From: buttle Date: Wed, 24 Nov 2021 12:12:48 +0100 Subject: [PATCH 6/7] loads collection list with human readable collection name --- src/View/Helper/ArchiveSiteMetaViewHelper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/View/Helper/ArchiveSiteMetaViewHelper.php b/src/View/Helper/ArchiveSiteMetaViewHelper.php index c4ba4e1..b19ca2f 100644 --- a/src/View/Helper/ArchiveSiteMetaViewHelper.php +++ b/src/View/Helper/ArchiveSiteMetaViewHelper.php @@ -119,6 +119,9 @@ class ArchiveSiteMetaViewHelper extends AbstractHelper $view = $this->getView(); return isset($view->site) ? $view->site - : $view->getHelperPluginManager()->get('Laminas\View\Helper\ViewModel')->getRoot()->getVariable('site'); + : $view->getHelperPluginManager() + ->get('Laminas\View\Helper\ViewModel') + ->getRoot() + ->getVariable('site'); } } -- 2.39.5 From faa9eda4856a84f98f547f2a6ac7c9cd64c7c8ea Mon Sep 17 00:00:00 2001 From: buttle Date: Wed, 15 Dec 2021 10:45:33 +0100 Subject: [PATCH 7/7] Fixes CrossSiteSearch api permissions --- Module.php | 12 ++++++++++++ config/module.config.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Module.php b/Module.php index 73eed2c..0aaa643 100644 --- a/Module.php +++ b/Module.php @@ -138,4 +138,16 @@ class Module extends AbstractModule return true; } + /** + * Code to run when first using the module. + * + * @param MvcEvent $event + */ + public function onBootstrap(MvcEvent $event): void + { + parent::onBootstrap($event); + + $acl = $this->getServiceLocator()->get('Omeka\Acl'); + $acl->allow(null, 'Controller\ArchiveSiteMetaController'); + } } diff --git a/config/module.config.php b/config/module.config.php index 020b8b3..9d1e2b6 100644 --- a/config/module.config.php +++ b/config/module.config.php @@ -22,7 +22,7 @@ return [ ], 'controllers' => [ 'invokables' => [ - Controller\ArchiveSiteMetaController::class => Controller\ArchiveSiteMetaController::class, + 'Controller\ArchiveSiteMetaController' => Controller\ArchiveSiteMetaController::class ], ], 'view_manager' => [ -- 2.39.5