Skip to content
Snippets Groups Projects
Commit 6ff58f6f authored by Ere Maijala's avatar Ere Maijala Committed by Robert Lange
Browse files

KohaRest: Avoid hard dependency on SafeMoneyFormat.

This allows the driver to work in console utilities as well.
parent 3e742e4e
No related merge requests found
......@@ -77,7 +77,7 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements
/**
* Factory function for constructing the SessionContainer.
*
* @var Callable
* @var callable
*/
protected $sessionFactory;
......@@ -220,10 +220,10 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements
* @param \VuFind\Date\Converter $dateConverter Date converter object
* @param callable $sessionFactory Factory function returning
* SessionContainer object
* @param SafeMoneyFormat $safeMoneyFormat Money formatting view helper
* @param ?SafeMoneyFormat $safeMoneyFormat Money formatting view helper
*/
public function __construct(\VuFind\Date\Converter $dateConverter,
$sessionFactory, SafeMoneyFormat $safeMoneyFormat
$sessionFactory, ?SafeMoneyFormat $safeMoneyFormat
) {
$this->dateConverter = $dateConverter;
$this->sessionFactory = $sessionFactory;
......@@ -2422,11 +2422,9 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements
case 'Patron::Debt':
case 'Patron::DebtGuarantees':
$count = isset($details['current_outstanding'])
? $this->safeMoneyFormat->__invoke($details['current_outstanding'])
: '-';
? $this->formatMoney($details['current_outstanding']) : '-';
$limit = isset($details['max_outstanding'])
? $this->safeMoneyFormat->__invoke($details['max_outstanding'])
: '-';
? $this->formatMoney($details['max_outstanding']) : '-';
$params = [
'%%blockCount%%' => $count,
'%%blockLimit%%' => $limit,
......@@ -2435,4 +2433,19 @@ class KohaRest extends \VuFind\ILS\Driver\AbstractBase implements
}
return $this->translate($this->patronStatusMappings[$reason] ?? '', $params);
}
/**
* Helper function for formatting currency
*
* @param $amount Number to format
*
* @return string
*/
protected function formatMoney($amount)
{
if (null === $this->safeMoneyFormat) {
throw new \Exception('SafeMoneyFormat helper not available');
}
return ($this->safeMoneyFormat)($amount);
}
}
......@@ -67,9 +67,14 @@ class KohaRestFactory extends \VuFind\ILS\Driver\DriverWithDateConverterFactory
$manager = $container->get(\Laminas\Session\SessionManager::class);
return new \Laminas\Session\Container("KohaRest_$namespace", $manager);
};
$helper = $container->get('ViewHelperManager')->get('safeMoneyFormat');
// Create safeMoneyFormat helper conditionally to avoid hard dependency on
// themes (which otherwise could cause problems for command line tools that
// use the ILS driver when the theme system is not active).
$helperManager = $container->get('ViewHelperManager');
$safeMoneyFormat = $helperManager->has('safeMoneyFormat')
? $helperManager->get('safeMoneyFormat') : null;
return parent::__invoke(
$container, $requestedName, [$sessionFactory, $helper]
$container, $requestedName, [$sessionFactory, $safeMoneyFormat]
);
}
}
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