Skip to content
Snippets Groups Projects
Commit 23d205b7 authored by llaffont's avatar llaffont
Browse files

Le choix des heures de réservations prends en compte les coupures entre plages...

Le choix des heures de réservations prends en compte les coupures entre plages d'ouverture matin / après-midi
parent 2cc2e956
Branches
Tags
No related merge requests found
......@@ -70,7 +70,11 @@ class Multimedia_LocationLoader extends Storm_Model_Loader {
if ($from > $to)
return array();
return range($from, $to, 60 * $increment);
$times = range($from, $to, 60 * $increment);
if (end($times) == $to)
array_pop($times);
return $times;
}
......@@ -131,12 +135,25 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
* @return array
*/
public function getStartTimesForDate($date) {
$min_time = $this->getMinTimeForDate($date);
$start_times = $this->getLoader()->getPossibleHours($this->getSlotSize(),
$min_time,
$this->getMaxTimeForDate($date));
if (!$ouverture = $this->getOuvertureForDate($date))
return array();
$timestamp = function($hour) use ($date) {
return strtotime($date . ' ' . $hour .':00');
};
if ($min_time < ($current = $this->getCurrentTime())) {
$slots_for_interval = function($start, $end) use ($timestamp) {
return $this->getLoader()->getPossibleHours($this->getSlotSize(),
$timestamp($start),
$timestamp($end));
};
$start_times = array_merge($slots_for_interval($ouverture->getDebutMatin(),
$ouverture->getFinMatin()),
$slots_for_interval($ouverture->getDebutApresMidi(),
$ouverture->getFinApresMidi()));
if ($timestamp($ouverture->getDebutMatin()) < ($current = $this->getCurrentTime())) {
$hour = (int) date('H', $current);
$minute = (int) date('i', $current);
$i = 0;
......@@ -197,12 +214,26 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
}
public function getOuvertureForDate($date) {
$dow = (int)date('w', strtotime($date));
foreach($this->getOuvertures() as $ouverture) {
if ($ouverture->getJourSemaine() == $dow)
return $ouverture;
}
}
/**
* @param $date string (YYYY-MM-DD)
* @return int
*/
public function getMinTimeForDate($date) {
return strtotime($date . ' ' . $this->getOpenHour() . ':00');
if ($ouverture = $this->getOuvertureForDate($date))
return strtotime($date . ' ' . $ouverture->getDebutMatin() . ':00');
return strtotime($date . ' 00:00:00');
}
......@@ -211,7 +242,9 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
* @return int
*/
public function getMaxTimeForDate($date) {
return strtotime($date . ' ' . $this->getCloseHour() . ':00');
if ($ouverture = $this->getOuvertureForDate($date))
return strtotime($date . ' ' . $ouverture->getFinApresMidi() . ':00');
return strtotime($date . ' 00:00:00');
}
......
......@@ -78,7 +78,6 @@ class Class_Ouverture extends Storm_Model_Abstract {
return substr($this->_get($name), 0, 5);
}
public function getFormattedJour() {
return Class_Date::humanDate($this->getJour(), 'dd/MM/yyyy');
}
......
......@@ -22,11 +22,13 @@
require_once 'ModelTestCase.php';
class Multimedia_LocationTest extends Storm_Test_ModelTestCase {
protected $_location;
public function setUp() {
Class_Bib::newInstanceWithId(3)
->setLibelle('Bibliothèque Antibes');
$loc = Class_Multimedia_Location::newInstanceWithId(123)
$this->_location = Class_Multimedia_Location::newInstanceWithId(123)
->setIdSite(3)
->setLibelle('Antibes')
->setSlotSize(30)
......@@ -34,12 +36,13 @@ class Multimedia_LocationTest extends Storm_Test_ModelTestCase {
->setHoldDelayMin(0)
->setHoldDelayMax(60)
->setOuvertures([Class_Ouverture::chaqueMercredi('08:30', '12:00', '12:00', '17:45')->setId(3)->cache(),
Class_Ouverture::chaqueJeudi('08:30', '12:00', '12:00', '17:45')->setId(4)->cache()]);
Class_Ouverture::chaqueJeudi('10:00', '12:00', '14:00', '19:00')->setId(4)->cache()]);
}
/** @test */
public function bibShouldHaveOuvertureForMercredi() {
Class_Bib::find(3)->getOuvertures();
$this->assertEquals(Class_Ouverture::MERCREDI,
Class_Bib::find(3)->getOuvertures()[0]->getJourSemaine());
}
......@@ -57,6 +60,51 @@ class Multimedia_LocationTest extends Storm_Test_ModelTestCase {
$this->assertEquals('Bibliothèque Antibes',
Class_Ouverture::find(3)->getLibelleBib());
}
/** @test */
public function getMinTimeFor8Aug2012ShouldReturnDebutMatinOfMercredi() {
$this->assertEquals(strtotime('2012-08-08 08:30:00'),
$this->_location->getMinTimeForDate('2012-08-08'),
'getMinTimeForDate => '.strftime('%Y-%m-%d %H:%M:%S',
$this->_location->getMinTimeForDate('2012-08-08')));
}
/** @test */
public function getMaxTimeFor8Aug2012ShouldReturnFinApresMidiOfMercredi() {
$this->assertEquals(strtotime('2012-08-08 17:45:00'),
$this->_location->getMaxTimeForDate('2012-08-08'));
}
/** @test */
public function getMinTimeFor9Aug2012ShouldReturnDebutMatinOfJeudi() {
$this->assertEquals(strtotime('2012-08-09 10:00:00'),
$this->_location->getMinTimeForDate('2012-08-09'));
}
/** @test */
public function getStartTimesFor8AugShouldReturnAllHalfHoursFrom_0830_to_1730() {
$this->assertEquals(['08:30' => '08h30', '09:00' => '09h00', '09:30' => '09h30', '10:00' => '10h00', '10:30' => '10h30',
'11:00' => '11h00', '11:30' => '11h30', '12:00' => '12h00', '12:30' => '12h30', '13:00' => '13h00',
'13:30' => '13h30', '14:00' => '14h00', '14:30' => '14h30', '15:00' => '15h00', '15:30' => '15h30',
'16:00' => '16h00', '16:30' => '16h30', '17:00' => '17h00', '17:30' => '17h30'],
$this->_location->getStartTimesForDate('2012-08-08'));
}
/** @test */
public function getStartTimesFor9AugShouldReturnAllHalfHoursFrom_1000_to_1130_then_1400_to_1830() {
$this->assertEquals(['10:00' => '10h00', '10:30' => '10h30', '11:00' => '11h00', '11:30' => '11h30',
'14:00' => '14h00', '14:30' => '14h30', '15:00' => '15h00', '15:30' => '15h30',
'16:00' => '16h00', '16:30' => '16h30', '17:00' => '17h00', '17:30' => '17h30',
'18:00' => '18h00', '18:30' => '18h30', '19:00' => '19h00'],
$this->_location->getStartTimesForDate('2012-08-09'));
}
}
?>
\ 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