The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

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

Represent publication details as an object instead of a string.

- Resolves VUFIND-911
- Includes unit tests
parent 73cc3cc3
No related merge requests found
<?php
/**
* Class encapsulating publication details.
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package RecordDrivers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:record_drivers Wiki
*/
namespace VuFind\RecordDriver\Response;
use VuFind\Code\ISBN;
/**
* Class encapsulating publication details.
*
* @category VuFind2
* @package RecordDrivers
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:record_drivers Wiki
*/
class PublicationDetails
{
/**
* Place of publication
*
* @var string
*/
protected $place;
/**
* Name of publisher
*
* @var string
*/
protected $name;
/**
* Date of publication
*
* @var string
*/
protected $date;
/**
* Constructor
*
* @param string $place Place of publication
* @param string $name Name of publisher
* @param string $date Date of publication
*/
public function __construct($place, $name, $date)
{
$this->place = $place;
$this->name = $name;
$this->date = $date;
}
/**
* Get place of publication
*
* @return string
*/
public function getPlace()
{
return $this->place;
}
/**
* Get name of publisher
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Get date of publication
*
* @return string
*/
public function getDate()
{
return $this->date;
}
/**
* Represent object as a string
*
* @return string
*/
public function __toString()
{
return trim(
preg_replace(
'/\s+/', ' ',
implode(' ', array($this->place, $this->name, $this->date))
)
);
}
}
......@@ -859,15 +859,12 @@ class SolrDefault extends AbstractBase
$i = 0;
$retval = array();
while (isset($places[$i]) || isset($names[$i]) || isset($dates[$i])) {
// Put all the pieces together, and do a little processing to clean up
// unwanted whitespace.
$retval[] = trim(
str_replace(
' ', ' ',
((isset($places[$i]) ? $places[$i] . ' ' : '') .
(isset($names[$i]) ? $names[$i] . ' ' : '') .
(isset($dates[$i]) ? $dates[$i] : ''))
)
// Build objects to represent each set of data; these will
// transform seamlessly into strings in the view layer.
$retval[] = new Response\PublicationDetails(
isset($places[$i]) ? $places[$i] : '',
isset($names[$i]) ? $names[$i] : '',
isset($dates[$i]) ? $dates[$i] : ''
);
$i++;
}
......
<?php
/**
* SolrMarc Record Driver Test Class
*
* PHP version 5
*
* Copyright (C) Villanova University 2010.
*
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @category VuFind2
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @author Preetha Rao <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:unit_tests Wiki
*/
namespace VuFindTest\RecordDriver\Response;
use VuFind\RecordDriver\Response\PublicationDetails;
/**
* SolrMarc Record Driver Test Class
*
* @category VuFind2
* @package Tests
* @author Demian Katz <demian.katz@villanova.edu>
* @author David Maus <maus@hab.de>
* @author Preetha Rao <vufind-tech@lists.sourceforge.net>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link http://vufind.org/wiki/vufind2:unit_tests Wiki
*/
class PublicationDetailsTest extends \VuFindTest\Unit\TestCase
{
/**
* Test getters
*
* @return void
*/
public function testGetters()
{
$pd = new PublicationDetails('a', 'b', 'c');
$this->assertEquals('a', $pd->getPlace());
$this->assertEquals('b', $pd->getName());
$this->assertEquals('c', $pd->getDate());
}
/**
* Test __toString
*
* @return void
*/
public function testToString()
{
$pd = new PublicationDetails('a', 'b', 'c');
$this->assertEquals('a b c', $pd->__toString());
$pd = new PublicationDetails('a', ' ', 'c');
$this->assertEquals('a c', $pd->__toString());
$pd = new PublicationDetails('a', ' ', ' ');
$this->assertEquals('a', $pd->__toString());
$pd = new PublicationDetails(' ', 'b', ' ');
$this->assertEquals('b', $pd->__toString());
$pd = new PublicationDetails(' ', ' ', 'c');
$this->assertEquals('c', $pd->__toString());
$pd = new PublicationDetails(' a ', ' b ', ' c ');
$this->assertEquals('a b c', $pd->__toString());
}
}
\ No newline at end of file
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