Skip to content
Snippets Groups Projects
Commit 5864de8a authored by pbarroca's avatar pbarroca
Browse files

OAI:Prise en compte des from et until

parent 5207cb77
Branches
Tags
No related merge requests found
......@@ -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;
}
}
......
......@@ -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);
}
......
......@@ -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');
......
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