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

Refactoring pour la prise en compte des plages matin / après-midi sur les réservations

parent 030c0d5a
Branches
Tags
No related merge requests found
......@@ -28,8 +28,9 @@ Rajouter erreurs:
**** TODO Remplacer le getDays qui retourne la liste des coches par les ouvertures récurentes de la bib cf [[file:application/modules/opac/controllers/AbonneController.php::if%20(-1%20%3D%3D%20$.inArray(date.getDay(),%20%5B'%20.%20$location->getDays()%20.%20'%5D))%20{][$location->getDays()]]
**** TODO Si le bidouilleux mets une date bidon dans l'url, l'écran suivant ne proposera pas d'heure de départ. Donc faire la vérification pour ne pas changer d'écran et afficher message erreur
*** TODO [[file:tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php::class%20AbonneControllerMultimediaHoldHoursTest%20extends%20AbonneControllerMultimediaHoldTestCase%20{][3ème écran choix de l'heure]] [0/1]
**** TODO Brancher getMin/MaxTimeForDate aux ouvertures [[file:application/modules/opac/controllers/AbonneController.php::if%20($start%20<%20$location->getMinTimeForDate($bean->day)][vérification créneau ouverture]]
*** TODO [[file:tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php::class%20AbonneControllerMultimediaHoldHoursTest%20extends%20AbonneControllerMultimediaHoldTestCase%20{][3ème écran choix de l'heure]] [1/1]
**** DONE Brancher getMin/MaxTimeForDate aux ouvertures [[file:application/modules/opac/controllers/AbonneController.php::if%20($start%20<%20$location->getMinTimeForDate($bean->day)][vérification créneau ouverture]]
CLOSED: [2012-08-07 Tue 09:51]
*** TODO [[file:tests/application/modules/opac/controllers/AbonneControllerMultimediaTest.php::class%20AbonneControllerMultimediaHoldDeviceTest%20extends%20AbonneControllerMultimediaHoldTestCase%20{][4ème écran choix du poste]] [0/1]
......
......@@ -155,19 +155,51 @@ class Class_Multimedia_Device extends Storm_Model_Abstract {
* @return Class_Multimedia_DeviceHold
*/
public function autoHoldByUser($user, $current_hold) {
if (!$this->canCreateHoldGivenCurrentHold($current_hold))
return null;
// si je n'ai pas de début de créneau, on sort
if (null == ($start = $this->getPreviousStartTime()))
return null;
$end = $this->findHoldEndForTodayFrom($start);
if ($end <= $start)
return null;
$hold = Class_Multimedia_DeviceHold::getLoader()
->newInstance()
->setDevice($this)
->setUser($user)
->setStart($start)
->setEnd($end);
$hold->save();
return $hold;
}
/**
* @param Class_Multimedia_DeviceHold $current_hold
* @return boolean
*/
public function canCreateHoldGivenCurrentHold($current_hold) {
// pas de résa auto, on sort
if (!$this->isAutoholdEnabled())
return null;
return false;
// une résa courante et on est dans le délai d'auth, on sort
if (null !== $current_hold
and $this->getCurrentTime() <= ($current_hold->getStart() + (60 * $this->getAuthDelay())))
return null;
return false;
return true;
}
// si je n'ai pas de début de créneau, on sort
if (null == ($start = $this->getPreviousStartTime()))
return null;
/**
* @param timestamp $starrt
* @return timestamp
*/
public function findHoldEndForTodayFrom($start) {
// fin de créneau par défaut selon config
$end = $start + (60 * $this->getAutoholdSlotsMax() * $this->getSlotSize());
......@@ -179,18 +211,7 @@ class Class_Multimedia_Device extends Storm_Model_Abstract {
if (null != ($next_start = $this->getNextHoldStart())
and $end > $next_start)
$end = $next_start;
if ($end <= $start)
return null;
$hold = Class_Multimedia_DeviceHold::getLoader()
->newInstance()
->setDevice($this)
->setUser($user)
->setStart($start)
->setEnd($end);
$hold->save();
return $hold;
return $end;
}
......
......@@ -174,8 +174,11 @@ class Class_Multimedia_Location extends Storm_Model_Abstract {
/** @return int */
public function getPreviousStartTime() {
$current = $this->getCurrentTime();
$times = $this->getLoader()->getPossibleTimes($this->getSlotSize());
$time_source = self::getTimeSource();
$current = $time_source->time();
$times = $this->getLoader()->getPossibleTimes($this->getSlotSize(),
$time_source->date(),
$time_source->nextDate());
if (0 == count($times))
return null;
......
......@@ -28,5 +28,17 @@ class Class_TimeSource {
public function time() {
return time();
}
public function date() {
$time = $this->time();
return mktime(0, 0, 0, date('n', $time), date('j', $time), date('Y', $time));
}
public function nextDate() {
$time = $this->time();
return mktime(0, 0, 0, date('n', $time), date('j', $time) + 1, date('Y', $time));
}
}
?>
\ No newline at end of file
......@@ -35,12 +35,15 @@
;; (add-hook 'php-mode-hook 'my-php-mode)
(defvar opac3-phpunit-config "~/dev/afi/afi-opac3/tests/phpunit.xml" "phpunit.xml path")
(setq opac3-phpunit-command "phpunit")
(setq opac3-mode-hook '(opac3-php-mode))
(defun opac3-php-mode()
(require 'geben)
(require 'phpunit)
(auto-complete-mode)
(imenu-add-menubar-index)
(setq
tab-width 2
indent-tabs-mode t
......@@ -67,8 +70,7 @@
(save-buffer)
(let
((command-filter (if params (concat " --filter " params) " "))
(debug-mode (if debug "XDEBUG_CONFIG=1 " ""))
phpunit-command)
(debug-mode (if debug "XDEBUG_CONFIG=1 " "")))
(if debug (progn (geben 1)
(window-configuration-to-register 'g)
......@@ -83,13 +85,21 @@
)
)
(setq phpunit-command
(setq opac3-phpunit-command
(concat debug-mode "phpunit -c " opac3-phpunit-config command-filter))
(compile phpunit-command)
(compile opac3-phpunit-command)
)
)
(defun opac3-run-last-phpunit-command()
"Run last phpunit command"
(interactive)
(compile opac3-phpunit-command)
)
(defun opac3-cur-file ()
"Return the filename (without directory) of the current buffer"
(file-name-nondirectory (buffer-file-name (current-buffer)))
......@@ -103,6 +113,13 @@
)
(defun opac3-run-phpunit-filtered-class()
"Run phpunit on this class"
(interactive)
(opac3-compile-phpunit (phpunit-class-ap))
)
(defun opac3-run-phpunit-filtered-function()
"Run phpunit on this function"
(interactive)
......@@ -136,7 +153,7 @@
(defun opac3-strftime(start end)
(interactive "r")
(let ((selected-text (buffer-substring start end)))
(geben-eval-expression (concat "strftime('%Y-%M-%d %H:%M:%S', " selected-text " )")))
(geben-eval-expression (concat "strftime('%Y-%m-%d %H:%M:%S', " selected-text " )")))
)
......@@ -152,9 +169,11 @@
:lighter " opac3"
:keymap
'(("\C-crf" . opac3-run-phpunit-filtered-function)
("\C-crc" . opac3-run-phpunit-filtered-file)
("\C-crc" . opac3-run-phpunit-filtered-class)
("\C-cra" . opac3-run-phpunit-filtered-file)
("\C-crm" . opac3-run-phpunit-filtered-custom)
("\C-cra" . opac3-run-phpunit)
("\C-crl" . opac3-run-last-phpunit-command)
("\C-crp" . opac3-run-phpunit)
("\C-crd" . opac3-debug-phpunit-function))
:after-hook 'opac3-mode-hook)
......
......@@ -175,6 +175,7 @@ class AbonneControllerMultimediaAuthenticateLaurentTest extends AbonneController
$this->onLoaderOfModel('Class_Multimedia_Location')
->whenCalled('findByIdOrigine')
->answers(Class_Multimedia_Location::newInstanceWithId(1));
$this->onLoaderOfModel('Class_Multimedia_Device')
->whenCalled('findByIdOrigineAndLocation')
......@@ -316,7 +317,8 @@ abstract class AbonneControllerMultimediaHoldTestCase extends AbstractController
Class_Bib::newInstanceWithId(3)
->setLibelle('Antibes');
Class_Multimedia_Location::newInstanceWithId(123)
->setIdSite(3)
->setLibelle('Antibes')
......
......@@ -20,6 +20,23 @@
*/
require_once 'ModelTestCase.php';
class TimesSourceForTest extends Class_TimeSource {
protected $_time;
public function setTime($time) {
$this->_time = $time;
return $this;
}
public function time() {
return $this->_time;
}
}
abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase {
/** @var Class_Multimedia_Device */
protected $_device;
......@@ -33,6 +50,8 @@ abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase {
protected $_time;
/** @var Class_Bib */
protected $_bib_antibes;
/** @var Storm_Test_ObjectWrapper */
protected $_time_source;
public function setUp() {
parent::setUp();
......@@ -49,13 +68,11 @@ abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase {
$this->_device = Class_Multimedia_Device::newInstanceWithId(2)
->setGroup($this->_group);
$this->_time = strtotime('today');
$time_source = Storm_Test_ObjectWrapper::mock()
->whenCalled('time')
->answers($this->_time);
Class_Multimedia_Device::setTimeSource($time_source);
Class_Multimedia_Location::setTimeSource($time_source);
$time = strtotime('today');
$this->_time_source = (new TimesSourceForTest())->setTime($time);
Class_Multimedia_Device::setTimeSource($this->_time_source);
Class_Multimedia_Location::setTimeSource($this->_time_source);
}
......@@ -68,6 +85,8 @@ abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase {
}
class Multimedia_DeviceCurrentHoldForUserHavingHoldTest extends Multimedia_DeviceCurrentHoldTestCase {
public function setUp() {
parent::setUp();
......@@ -75,7 +94,7 @@ class Multimedia_DeviceCurrentHoldForUserHavingHoldTest extends Multimedia_Devic
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time)
->with($this->_device, $this->_time_source->time())
->answers(Class_Multimedia_DeviceHold::getLoader()->newInstanceWithId(123)
->setIdUser(7));
......@@ -90,15 +109,17 @@ class Multimedia_DeviceCurrentHoldForUserHavingHoldTest extends Multimedia_Devic
}
class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndNoAutoholdTest extends Multimedia_DeviceCurrentHoldTestCase {
public function setUp() {
parent::setUp();
$this->_location->setAutohold(0);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time)
->answers(null);
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time_source->time())
->answers(null);
$this->_hold = $this->_device->getCurrentHoldForUser(Class_Users::getLoader()->newInstanceWithId(7));
}
......@@ -111,20 +132,23 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndNoAutoholdTest extends Mu
}
class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndAnotherValidHoldTest extends Multimedia_DeviceCurrentHoldTestCase {
public function setUp() {
parent::setUp();
$this->_location
->setAuthDelay(10)
->setAutohold(1)
->setSlotSize(15);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time)
->answers(Class_Multimedia_DeviceHold::getLoader()->newInstanceWithId(123)
->setIdUser(5)
->setStart($this->_time - 60));
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time_source->time())
->answers(Class_Multimedia_DeviceHold::getLoader()->newInstanceWithId(123)
->setIdUser(5)
->setStart($this->_time_source->time() - 60));
$this->_hold = $this->_device->getCurrentHoldForUser(Class_Users::getLoader()->newInstanceWithId(7));
}
......@@ -137,6 +161,8 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndAnotherValidHoldTest exte
}
class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndNoStartTimeTest extends Multimedia_DeviceCurrentHoldTestCase {
public function setUp() {
parent::setUp();
......@@ -146,9 +172,9 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndNoStartTimeTest extends M
->setSlotSize(15);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time)
->answers(null);
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time_source->time())
->answers(null);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_Location')
->whenCalled('getPossibleTimes')
......@@ -165,22 +191,27 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndNoStartTimeTest extends M
}
class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndMaxSlotsAfterCloseHoursTest extends Multimedia_DeviceCurrentHoldTestCase {
public function setUp() {
parent::setUp();
$this->_time_source->setTime(strtotime('2012-09-09 09:00:00'));
$this->_location
->setAuthDelay(10)
->setAutohold(1)
->setSlotSize(15)
->setAutoholdSlotsMax(600)
->addOuverture(Class_Ouverture::newInstanceWithId(5)
->setJourSemaine(date('w'))
->setJourSemaine(date('w', $this->_time_source->time()))
->setBib($this->_bib_antibes)
->setHoraires(['08:00', '10:00', '10:00', '10:00']));
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
->whenCalled('getHoldOnDeviceAtTime')
->with($this->_device, $this->_time)
->with($this->_device, $this->_time_source->time())
->answers(null)
->whenCalled('getFirstHoldOnDeviceBetweenTimes')
......@@ -188,7 +219,7 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndMaxSlotsAfterCloseHoursTe
->whenCalled('save')
->answers(true);
xdebug_break();
$this->_hold = $this->_device->getCurrentHoldForUser(Class_Users::getLoader()->newInstanceWithId(7));
}
......@@ -206,6 +237,8 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndMaxSlotsAfterCloseHoursTe
}
class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndMaxSlotsAfterNextHoldStartTest extends Multimedia_DeviceCurrentHoldTestCase {
/** @var int */
protected $_nextStartTime;
......@@ -222,7 +255,7 @@ class Multimedia_DeviceCurrentHoldForUserWithoutHoldAndMaxSlotsAfterNextHoldStar
->setJourSemaine(date('w'))
->setHoraires(['08:00', '12:00', '14:00', '23:00']));
$this->_nextStartTime = $this->_time + (60 * 60);
$this->_nextStartTime = $this->_time_source->time() + (60 * 60);
Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold')
->whenCalled('getHoldOnDeviceAtTime')
->answers(null)
......
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