From bf160aa1f6237890acdd82a22d47c07c5e7ef6a7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andr=C3=A9=20Lahmann?= <lahmann@ub.uni-leipzig.de>
Date: Wed, 1 Jul 2015 16:05:33 +0200
Subject: [PATCH] * updating DAIA driver to latest version of
 finc/paia-driver->lahmann/paia-driver with proper date conversion support

---
 module/finc/config/module.config.php        |  6 +--
 module/finc/src/finc/ILS/Driver/DAIA.php    | 43 ++++++++++-----------
 module/finc/src/finc/ILS/Driver/Factory.php | 29 ++++++++++++++
 module/finc/src/finc/ILS/Driver/FincILS.php | 18 +++++++--
 4 files changed, 65 insertions(+), 31 deletions(-)

diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php
index 71a8d53f2d1..514810a7924 100644
--- a/module/finc/config/module.config.php
+++ b/module/finc/config/module.config.php
@@ -12,10 +12,8 @@ $config = [
             'ils_driver' => [
                 'factories' => [
                     'fincils' => 'finc\ILS\Driver\Factory::getFincILS',
-                ],
-                'invokables' => [
-                    'daia' => 'finc\ILS\Driver\DAIA',
-                    'paia' => 'finc\ILS\Driver\PAIA',
+                    'daia' => 'finc\ILS\Driver\Factory::getDAIA',
+                    'paia' => 'finc\ILS\Driver\Factory::getPAIA',
                 ],
             ],
             'recorddriver' => [
diff --git a/module/finc/src/finc/ILS/Driver/DAIA.php b/module/finc/src/finc/ILS/Driver/DAIA.php
index 14eef2fdacf..86646f832fd 100644
--- a/module/finc/src/finc/ILS/Driver/DAIA.php
+++ b/module/finc/src/finc/ILS/Driver/DAIA.php
@@ -99,6 +99,23 @@ class DAIA extends \VuFind\ILS\Driver\AbstractBase implements
         "json" => "application/json",
     ];
 
+    /**
+     * Date converter object
+     *
+     * @var \VuFind\Date\Converter
+     */
+    protected $dateConverter;
+
+    /**
+     * Constructor
+     *
+     * @param \VuFind\Date\Converter $converter Date converter
+     */
+    public function __construct(\VuFind\Date\Converter $converter)
+    {
+        $this->dateConverter = $converter;
+    }
+
     /**
      * Initialize the driver.
      *
@@ -186,10 +203,6 @@ class DAIA extends \VuFind\ILS\Driver\AbstractBase implements
      */
     public function getStatus($id)
     {
-        if ($this->checkForILSTestId($id)) {
-            return [];
-        }
-
         // let's retrieve the DAIA document by URI
         try {
             $rawResult = $this->doHTTPRequest($this->generateURI($id));
@@ -408,22 +421,6 @@ class DAIA extends \VuFind\ILS\Driver\AbstractBase implements
         return rtrim($multiURI, "|");
     }
 
-    /**
-     * Autoconfigure tests ILS with getStatus('1') - use this method if you don't
-     * have a record with id='1' but don't want Autoconfigure to fail on ILS test.
-     *
-     * @param string $id Record id to be tested
-     *
-     * @return bool
-     */
-    protected function checkForILSTestId($id)
-    {
-        if ($id === '1') {
-            return true;
-        }
-        return false;
-    }
-
     /**
      * Parse a DAIA document depending on its type.
      *
@@ -707,7 +704,8 @@ class DAIA extends \VuFind\ILS\Driver\AbstractBase implements
                 }
                 // attribute expected is mandatory for unavailable element
                 if (isset($unavailable["expected"])) {
-                    $duedate = $unavailable["expected"];
+                    $duedate = $this->dateConverter
+                        ->convertToDisplayDate("Y-m-d", $unavailable['expected']);
                 }
 
                 // attribute queue can be set
@@ -840,5 +838,4 @@ class DAIA extends \VuFind\ILS\Driver\AbstractBase implements
             }
         }
     }
-}
-
+}
\ No newline at end of file
diff --git a/module/finc/src/finc/ILS/Driver/Factory.php b/module/finc/src/finc/ILS/Driver/Factory.php
index a9c36c434de..2c7f3bf9d6d 100644
--- a/module/finc/src/finc/ILS/Driver/Factory.php
+++ b/module/finc/src/finc/ILS/Driver/Factory.php
@@ -50,9 +50,38 @@ class Factory
     public static function getFincILS(ServiceManager $sm)
     {
         return new FincILS(
+            $sm->getServiceLocator()->get('VuFind\DateConverter'),
             $sm->getServiceLocator()->get('VuFind\RecordLoader'),
             $sm->getServiceLocator()->get('VuFind\Config')->get('config')
         );
     }
 
+    /**
+     * Factory for DAIA driver.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return DAIA
+     */
+    public static function getDAIA(ServiceManager $sm)
+    {
+        return new DAIA(
+            $sm->getServiceLocator()->get('VuFind\DateConverter')
+        );
+    }
+
+    /**
+     * Factory for PAIA driver.
+     *
+     * @param ServiceManager $sm Service manager.
+     *
+     * @return PAIA
+     */
+    public static function getPAIA(ServiceManager $sm)
+    {
+        return new PAIA(
+            $sm->getServiceLocator()->get('VuFind\DateConverter')
+        );
+    }
+
 }
\ No newline at end of file
diff --git a/module/finc/src/finc/ILS/Driver/FincILS.php b/module/finc/src/finc/ILS/Driver/FincILS.php
index 9d1a6879b34..a06e9ee1360 100644
--- a/module/finc/src/finc/ILS/Driver/FincILS.php
+++ b/module/finc/src/finc/ILS/Driver/FincILS.php
@@ -70,6 +70,13 @@ class FincILS extends PAIA implements LoggerAwareInterface
      */
     protected $recordLoader;
 
+    /**
+     * Date converter object
+     *
+     * @var \VuFind\Date\Converter
+     */
+    protected $dateConverter;
+
     /**
      * Main Config
      *
@@ -80,12 +87,15 @@ class FincILS extends PAIA implements LoggerAwareInterface
     /**
      * Constructor
      *
-     * @param \VuFind\Record\Loader $loader     Record loader
-     * @param \Zend\Config\Config   $mainConfig VuFind main configuration (omit for
+     * @param \VuFind\Date\Converter $converter  Date converter
+     * @param \VuFind\Record\Loader  $loader     Record loader
+     * @param \Zend\Config\Config    $mainConfig VuFind main configuration (omit for
      * built-in defaults)
      */
-    public function __construct(\VuFind\Record\Loader $loader, $mainConfig = null)
-    {
+    public function __construct(\VuFind\Date\Converter $converter,
+        \VuFind\Record\Loader $loader, $mainConfig = null
+    ) {
+        $this->dateConverter = $converter;
         $this->recordLoader = $loader;
         $this->mainConfig = $mainConfig;
     }
-- 
GitLab