diff --git a/library/Class/Catalogue.php b/library/Class/Catalogue.php index 146c2732354375f9619350f41f31bc32dd29ab93..0c31d85ae0eede25f4ec3803afea4819e2e60d7e 100644 --- a/library/Class/Catalogue.php +++ b/library/Class/Catalogue.php @@ -73,6 +73,9 @@ class CatalogueLoader extends Storm_Model_Loader { if ($new = $this->nouveauteClauseFor($catalogue)) $conditions[] = $new; + if ($fromUntil = $this->fromUntilClauseFor($catalogue)) + $conditions[] = $fromUntil; + if (0 == count($conditions)) return ''; @@ -165,6 +168,21 @@ class CatalogueLoader extends Storm_Model_Loader { return 'date_creation >= \'' . date('Y-m-d') . '\''; } + + + public function fromUntilClauseFor($catalogue) { + $clauses = array(); + if ($start = $catalogue->getFrom()) + $clauses[] = "date_maj >= '" . $start . "'"; + + if($end = $catalogue->getUntil()) + $clauses[] = "date_maj <= '" . $end . "'"; + + if (0 == count($clauses)) + return ''; + + return implode(' and ', $clauses); + } } @@ -194,6 +212,9 @@ class Class_Catalogue extends Storm_Model_Abstract { 'cote_fin' => '', 'nouveaute' => ''); + protected $_from; + protected $_until; + public static function getLoader() { return self::getLoaderFor(__CLASS__); } @@ -538,6 +559,28 @@ class Class_Catalogue extends Storm_Model_Abstract { "La spec OAI ne peut contenir que les caractères suivants: de a à z, 0 à 9, - _ ."); } + + + public function setFrom($from) { + $this->_from = $from; + return $this; + } + + + public function getFrom() { + return $this->_from; + } + + + public function setUntil($until) { + $this->_until = $until; + return $this; + } + + + public function getUntil() { + return $this->_until; + } } diff --git a/library/Class/WebService/OAI/Request/ListIdentifiers.php b/library/Class/WebService/OAI/Request/ListIdentifiers.php index bb336e50d23f7684c36be9c0b22dd1abf916696e..0c5c7b06c024987723e81a0986c94b4a44ebbcd6 100644 --- a/library/Class/WebService/OAI/Request/ListIdentifiers.php +++ b/library/Class/WebService/OAI/Request/ListIdentifiers.php @@ -90,6 +90,11 @@ class Class_WebService_OAI_Request_ListIdentifiers { if ($this->_token) $this->_token->save(); + if ($this->_from) + $this->_catalogue->setFrom(substr($this->_from, 0, 10)); + if ($this->_until) + $this->_catalogue->setUntil(substr($this->_until, 0, 10)); + $this->_notices = $this->_catalogue->getNotices($page_number, self::IDENTIFIERS_BY_PAGE); } diff --git a/tests/library/Class/CatalogueTest.php b/tests/library/Class/CatalogueTest.php index 94491b945a3ba00b960e2242397083cf5bda3ffe..63c53a69ef87a575b41cf779d394a6720eadf419 100644 --- a/tests/library/Class/CatalogueTest.php +++ b/tests/library/Class/CatalogueTest.php @@ -235,6 +235,22 @@ class CatalogueTestGetPagedNotices extends ModelTestCase { } + /** @test */ + public function withFromShouldQueryOnDateMaj() { + $this->_catalogue->setFrom('2011-03-05'); + $this->_expectNoticeFindAllBy('date_maj >= \'2011-03-05\''); + Class_Catalogue::getLoader()->loadNoticesFor($this->_catalogue); + } + + + /** @test */ + public function withUntilShouldQueryOnDateMaj() { + $this->_catalogue->setUntil('2011-03-05'); + $this->_expectNoticeFindAllBy('date_maj <= \'2011-03-05\''); + Class_Catalogue::getLoader()->loadNoticesFor($this->_catalogue); + } + + /** @test */ public function forFirstPageShouldLimitFromZero() { $this->_catalogue->setBibliotheque('77');