Skip to content
Snippets Groups Projects
GetBoss.php 2.77 KiB
Newer Older
Gregor Gawol's avatar
Gregor Gawol committed
<?php
/**
 * Copyright (C) Leipzig University Library 2019.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @author   Gregor Gawol <gawol@ub.uni-leipzig.de>
 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
 */
Gregor Gawol's avatar
Gregor Gawol committed
namespace finc\Boss\AjaxHandler;
Gregor Gawol's avatar
Gregor Gawol committed

use VuFind\ILS\Connection;
use finc\Dbis\Client\Client;
use Zend\Config\Config;
use Zend\Mvc\Controller\Plugin\Params;
use Zend\View\Renderer\RendererInterface;

class GetBoss extends \VuFind\AjaxHandler\AbstractBase
{

    /**
     * Top-level configuration
     *
     * @var Config
     */
    protected $config;

    /**
     * ILS connection
     *
     * @var Connection
     */
    protected $ils;

    /**
     * HTTP Service
     *
     * @var Client
     */
    protected $dbisClient;

    /**
     * View renderer
     *
     * @var RendererInterface
     */
    protected $renderer;

    /**
     * Constructor
     *
     * @param Client                $dbisClient     http client
     * @param Config                $config         Top-level configuration
     * @param Connection            $ils            ILS connection
     * @param RendererInterface     $renderer       view
     */
    public function __construct(
        Client $dbisClient,
        Config $config,
        Connection $ils,
        RendererInterface $renderer
    ) {
        $this->config = $config;
        $this->ils = $ils;
        $this->dbisClient = $dbisClient;
        $this->renderer = $renderer;
    }

    /**
     * Handle a request.
     *
     * @param Params $params Parameter helper from controller
     *
     * @return array [response data, HTTP status code]
     */
    public function handleRequest(Params $params)
    {
        $bibId = 'AAAAA';
        // Stop now if the user does not have valid catalog credentials available:
        if (is_array($this->ils)) {
            $bibId = isset($patron['homeLibrary']) ?
                $this->ils['homeLibrary'] : 'AAAAA';
        }

        $results = $this->dbisClient->getDbisList($bibId);
        $view = [
            'results' => $results
        ];
        $html = $this->renderer->render('ajax/dbis.phtml', $view);
        return $this->formatResponse(compact('html'));
    }
}