Adds cross site api #4

Merged
chris merged 10 commits from develop into main 2021-12-15 10:51:55 +01:00
2 changed files with 56 additions and 12 deletions
Showing only changes of commit ea5e33d0a2 - Show all commits

View File

@ -7,9 +7,12 @@ return [
'router' => [ 'router' => [
'routes' => [ 'routes' => [
'archiveSiteMeta' => [ 'archiveSiteMeta' => [
//'type' => \Laminas\Router\Http\Segment::class,
'type' => \Laminas\Router\Http\Literal::class, 'type' => \Laminas\Router\Http\Literal::class,
'options' => [ 'options' => [
'route' => '/collections', //'route' => '/collections[/:action]',
//'route' => '/collections',
'route' => '/collections/search',
'defaults' => [ 'defaults' => [
'__NAMESPACE__' => 'ArchiveSiteMeta\Controller', '__NAMESPACE__' => 'ArchiveSiteMeta\Controller',
'controller' => Controller\ArchiveSiteMetaController::class, 'controller' => Controller\ArchiveSiteMetaController::class,

View File

@ -2,7 +2,6 @@
namespace ArchiveSiteMeta\Controller; namespace ArchiveSiteMeta\Controller;
use Laminas\Mvc\Controller\AbstractActionController; use Laminas\Mvc\Controller\AbstractActionController;
#use Laminas\View\Model\ViewModel;
use Laminas\View\Model\JsonModel; use Laminas\View\Model\JsonModel;
class ArchiveSiteMetaController extends AbstractActionController class ArchiveSiteMetaController extends AbstractActionController
@ -12,17 +11,59 @@ class ArchiveSiteMetaController extends AbstractActionController
{ {
} }
public function indexAction() 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);
}
} }