Skip to content
Snippets Groups Projects
Commit 23434510 authored by Demian Katz's avatar Demian Katz
Browse files

Refactored homeAction for clarity/simplicity.

parent 1f369259
No related merge requests found
...@@ -42,18 +42,40 @@ use Zend\Config\Config; ...@@ -42,18 +42,40 @@ use Zend\Config\Config;
class ChannelsController extends AbstractBase class ChannelsController extends AbstractBase
{ {
/** /**
* Generates static front page of channels. * Retrieve channel information for the Channels/Home page.
* *
* @return \Zend\View\Model\ViewModel * @param array $providers Array of channel providers
* @param string $searchClassId Search class ID
* @param string $token Channel token
*
* @return array
*/ */
public function homeAction() protected function getHomeChannels($providers, $searchClassId, $token)
{ {
$view = $this->createViewModel(); $callback = function ($runner, $params, $searchClassId) use ($providers) {
foreach ($providers as $provider) {
$provider->configureSearchParams($params);
}
};
$runner = $this->serviceLocator->get('VuFind\SearchRunner'); $runner = $this->serviceLocator->get('VuFind\SearchRunner');
$results = $runner->run([], $searchClassId, $callback);
// Send both GET and POST variables to search class: $channels = [];
$request = []; foreach ($providers as $provider) {
$channels = array_merge(
$channels, $provider->getFromSearch($results, $token)
);
}
return $channels;
}
/**
* Generates static front page of channels.
*
* @return \Zend\View\Model\ViewModel
*/
public function homeAction()
{
$config = $this->getConfig('channels'); $config = $this->getConfig('channels');
$defaultSearchClassId = isset($config->General->default_home_source) $defaultSearchClassId = isset($config->General->default_home_source)
? $config->General->default_home_source : DEFAULT_SEARCH_BACKEND; ? $config->General->default_home_source : DEFAULT_SEARCH_BACKEND;
...@@ -62,22 +84,9 @@ class ChannelsController extends AbstractBase ...@@ -62,22 +84,9 @@ class ChannelsController extends AbstractBase
? $config->{"source.$searchClassId"}->home->toArray() : []; ? $config->{"source.$searchClassId"}->home->toArray() : [];
$providers = $this->getChannelProviderArray($providerIds, $config); $providers = $this->getChannelProviderArray($providerIds, $config);
$callback = function ($runner, $params, $searchClassId) use ($providers) { $token = $this->params()->fromQuery('channelToken');
foreach ($providers as $provider) { $channels = $this->getHomeChannels($providers, $searchClassId, $token);
$provider->configureSearchParams($params); return $this->createViewModel(compact('token', 'channels'));
}
};
$view->results = $runner->run($request, $searchClassId, $callback);
$view->channels = [];
$view->token = $this->params()->fromQuery('channelToken');
foreach ($providers as $provider) {
$view->channels = array_merge(
$view->channels,
$provider->getFromSearch($view->results, $view->token)
);
}
return $view;
} }
/** /**
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment