From f609352d3c516f53ddc8b7ce3fa5165018df9068 Mon Sep 17 00:00:00 2001 From: Demian Katz Date: Fri, 5 Jul 2024 09:20:58 -0400 Subject: [PATCH] Finish basic wiring. --- .../Controller/SearchController.php | 14 ++++++++-- .../src/GeebyDeeby/Db/Table/Person.php | 28 ++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/module/GeebyDeeby/src/GeebyDeeby/Controller/SearchController.php b/module/GeebyDeeby/src/GeebyDeeby/Controller/SearchController.php index 455ad26c..8a0beb5f 100644 --- a/module/GeebyDeeby/src/GeebyDeeby/Controller/SearchController.php +++ b/module/GeebyDeeby/src/GeebyDeeby/Controller/SearchController.php @@ -62,10 +62,20 @@ protected function tokenize($q) */ public function creatorAjaxAction() { + $nameHelper = $this->serviceLocator->get('ViewHelperManager')->get('showPerson'); $post = $this->params()->fromPost(); $ids = explode(',', $post['ids']); - foreach ($ids as $id) { - $response[$id] = "foo $id"; + $index = []; + foreach ($this->getDbTable('person')->getListForItemIds($ids) as $row) { + $index[$row['Item_ID']] ??= []; + $index[$row['Item_ID']][] = $row; + } + $formatPerson = function ($person) use ($nameHelper) { + return htmlspecialchars(($nameHelper)($person)); + }; + $response = []; + foreach ($index as $id => $data) { + $response[$id] = implode('; ', array_map($formatPerson, $data)); } return $this->jsonDie($response, true); } diff --git a/module/GeebyDeeby/src/GeebyDeeby/Db/Table/Person.php b/module/GeebyDeeby/src/GeebyDeeby/Db/Table/Person.php index 7512ecee..accc28da 100644 --- a/module/GeebyDeeby/src/GeebyDeeby/Db/Table/Person.php +++ b/module/GeebyDeeby/src/GeebyDeeby/Db/Table/Person.php @@ -62,7 +62,7 @@ public function __construct( } /** - * Get a list of categories. + * Get a list of people. * * @param bool $biosOnly Should we filter to only people with biographies? * @@ -79,6 +79,32 @@ public function getList($biosOnly = false) return $this->select($callback); } + /** + * Get people for item IDs. + * + * @param array $itemIds Item IDs to match. + * + * @return mixed + */ + public function getListForItemIds($itemIds) { + $callback = function ($select) use ($itemIds) { + $select->quantifier('DISTINCT'); + $select->join( + ['ec' => 'Editions_Credits'], + 'ec.Person_ID = People.Person_ID', + [] + ); + $select->join( + ['e' => 'Editions'], + 'ec.Edition_ID = e.Edition_ID', + ['Item_ID'] + ); + $select->where->in('Item_ID', $itemIds); + $select->order(['Last_Name', 'First_Name']); + }; + return $this->select($callback); + } + /** * Get autocomplete suggestions. *