diff --git a/.gitattributes b/.gitattributes index e82b1c03e6b2405561d7d6f034d7e3a3b035ff24..e7a19fdc8ec36f5f5114370525b89352cb736b6c 100644 --- a/.gitattributes +++ b/.gitattributes @@ -3755,6 +3755,7 @@ tests/library/Class/Systeme/ModulesAccueilTest.php -text tests/library/Class/Systeme/ModulesAppliTest.php -text tests/library/Class/Systeme/ModulesMenuTest.php -text tests/library/Class/Systeme/PergameServiceTest.php -text +tests/library/Class/TimeSourceForTest.php -text tests/library/Class/TypeDocTest.php -text tests/library/Class/UploadTest.php -text tests/library/Class/UserGroupTest.php -text diff --git a/application/modules/admin/views/scripts/multimedia/browse.phtml b/application/modules/admin/views/scripts/multimedia/browse.phtml index ed42341cc67f544dad034c21fd00af247126c318..bbdac2edc0ddf2ccf6f4eb6e86793a6b58719695 100644 --- a/application/modules/admin/views/scripts/multimedia/browse.phtml +++ b/application/modules/admin/views/scripts/multimedia/browse.phtml @@ -8,7 +8,7 @@ ['libelle', 'os'], [ ['action' => 'holds', 'content' => function($model) { - return $this->boutonIco('type=show').$model->numberOfHolds().' rés.'; + return $this->boutonIco('type=show').$model->numberOfNextHolds().' rés.'; }] ], 'multimedia_devices', diff --git a/application/modules/admin/views/scripts/multimedia/holds.phtml b/application/modules/admin/views/scripts/multimedia/holds.phtml index 0d2b2bfad0d855803a621d5e96687ae1290c99ef..4b0bdf21c13591f07caa57ac9d6bed59bfaf9dc3 100644 --- a/application/modules/admin/views/scripts/multimedia/holds.phtml +++ b/application/modules/admin/views/scripts/multimedia/holds.phtml @@ -1,7 +1,7 @@ <h2><?php echo $this->titre;?></h2> <?php echo $this->tagModelTable( - $this->device->getHolds(), + $this->device->getNextHolds(), [$this->_('Utilisateur'), $this->_('Début'), $this->_('Fin')], ['username', 'startHHMM', 'endHHMM'], [], diff --git a/library/Class/Multimedia/Device.php b/library/Class/Multimedia/Device.php index 67bd86f6aab4581e0b121eee0e7170d76e2ca8cd..4231aa5465d7e35487b1bd12345b72b69d102b40 100644 --- a/library/Class/Multimedia/Device.php +++ b/library/Class/Multimedia/Device.php @@ -320,4 +320,20 @@ class Class_Multimedia_Device extends Storm_Model_Abstract { public function getSlotSize() { return $this->getGroup()->getSlotSize(); } + + /** @return int */ + public function numberOfNextHolds() { + return Class_Multimedia_DeviceHold::countBy(['role' => 'device', + 'model' => $this, + 'where' => 'start>='.$this->getTimeSource()->date(), + 'order' => 'start']); + } + + /** @return array of DeviceHold */ + public function getNextHolds() { + return Class_Multimedia_DeviceHold::findAllBy(['role' => 'device', + 'model' => $this, + 'where' => 'start>='.$this->getTimeSource()->date(), + 'order' => 'start']); + } } \ No newline at end of file diff --git a/tests/application/modules/admin/controllers/MultimediaControllerTest.php b/tests/application/modules/admin/controllers/MultimediaControllerTest.php index 81b168867e181c3b9590717f7cc03168be83d5b1..431e98ab9b2375ddabbdc83ceda9040ea77716ff 100644 --- a/tests/application/modules/admin/controllers/MultimediaControllerTest.php +++ b/tests/application/modules/admin/controllers/MultimediaControllerTest.php @@ -19,6 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ require_once 'AdminAbstractControllerTestCase.php'; +require_once 'TimeSourceForTest.php'; abstract class Admin_MultimetiaControllerTestCase extends Admin_AbstractControllerTestCase { public function setUp() { @@ -209,9 +210,15 @@ class Admin_MultimediaControllerBrowseTest extends Admin_MultimetiaControllerTes ->setGroups(array($group)); + $time_source = (new TimeSourceForTest())->setTime(strtotime('today')); + Class_Multimedia_Device::setTimeSource($time_source); + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold') ->whenCalled('countBy') - ->with(['role' => 'device', 'model' => $device]) + ->with(['role' => 'device', + 'model' => $device, + 'where' => 'start>='.$time_source->date(), + 'order' => 'start']) ->answers(7); @@ -291,17 +298,30 @@ class Admin_MultimediaControllerHoldsTest extends Admin_MultimetiaControllerTest $device = Class_Multimedia_Device::getLoader()->newInstanceWithId(1) ->setLibelle('Poste 1') - ->setOs('Archlinux') - ->setHolds([ - Class_Multimedia_DeviceHold::newInstanceWithId(3) - ->setStart(strtotime('2012-09-12 15:00')) - ->setEnd(strtotime('2012-09-12 16:00')) - ->setUser(Class_Users::newInstanceWithId(3)->setPrenom('Laurent')), - - Class_Multimedia_DeviceHold::newInstanceWithId(4) - ->setStart(strtotime('2012-09-13 12:00')) - ->setEnd(strtotime('2012-09-13 13:00')) - ->setUser(Class_Users::newInstanceWithId(4)->setPrenom('Estelle'))]); + ->setOs('Archlinux'); + + + $time_source = (new TimeSourceForTest())->setTime(mktime(10, 10, 10, + 9, 12, 2012)); + Class_Multimedia_Device::setTimeSource($time_source); + + Storm_Test_ObjectWrapper::onLoaderOfModel('Class_Multimedia_DeviceHold') + ->whenCalled('findAllBy') + ->with(['role' => 'device', + 'model' => $device, + 'where' => 'start>='.$time_source->date(), + 'order' => 'start']) + ->answers([ + Class_Multimedia_DeviceHold::newInstanceWithId(3) + ->setStart(strtotime('2012-09-12 15:00')) + ->setEnd(strtotime('2012-09-12 16:00')) + ->setUser(Class_Users::newInstanceWithId(3)->setPrenom('Laurent')), + + Class_Multimedia_DeviceHold::newInstanceWithId(4) + ->setStart(strtotime('2012-09-13 12:00')) + ->setEnd(strtotime('2012-09-13 13:00')) + ->setUser(Class_Users::newInstanceWithId(4)->setPrenom('Estelle')) + ]); $this->dispatch('/admin/multimedia/holds/id/1', true); diff --git a/tests/library/Class/Multimedia/DeviceTest.php b/tests/library/Class/Multimedia/DeviceTest.php index 9c441f657657efa63811f569da388058640221d6..82d81b41141fe64aea002d3c622277152d7c21e6 100644 --- a/tests/library/Class/Multimedia/DeviceTest.php +++ b/tests/library/Class/Multimedia/DeviceTest.php @@ -19,22 +19,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 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; - } -} - - +require_once 'TimeSourceForTest.php'; abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase { @@ -69,7 +54,7 @@ abstract class Multimedia_DeviceCurrentHoldTestCase extends ModelTestCase { ->setGroup($this->_group); $time = strtotime('today'); - $this->_time_source = (new TimesSourceForTest())->setTime($time); + $this->_time_source = (new TimeSourceForTest())->setTime($time); Class_Multimedia_Device::setTimeSource($this->_time_source); Class_Multimedia_Location::setTimeSource($this->_time_source); diff --git a/tests/library/Class/TimeSourceForTest.php b/tests/library/Class/TimeSourceForTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d8e35b8737ff1a8d136f5aa58cc71b15541bd448 --- /dev/null +++ b/tests/library/Class/TimeSourceForTest.php @@ -0,0 +1,35 @@ +<?php +/** + * Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved. + * + * AFI-OPAC 2.0 is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * AFI-OPAC 2.0 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with AFI-OPAC 2.0; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +class TimeSourceForTest extends Class_TimeSource { + protected $_time; + + public function setTime($time) { + $this->_time = $time; + return $this; + } + + public function time() { + return $this->_time; + } +} + +?> \ No newline at end of file