Skip to content

Commit

Permalink
Finish basic wiring.
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Jul 5, 2024
1 parent 3d2b359 commit f609352
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
14 changes: 12 additions & 2 deletions module/GeebyDeeby/src/GeebyDeeby/Controller/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
28 changes: 27 additions & 1 deletion module/GeebyDeeby/src/GeebyDeeby/Db/Table/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*
Expand All @@ -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.
*
Expand Down

0 comments on commit f609352

Please sign in to comment.