Skip to content
Snippets Groups Projects
Commit ae7bb8e3 authored by efalcy's avatar efalcy
Browse files

dev #17360 : by default display training for current year and fix some bugs :

  - display sessions if training contains sessions in 2 differents years
  - display training in box event if selected training in preferences contains deleted training
parent 16e08438
Branches
Tags
2 merge requests!529Hotline 6.56,!516Dev#16866 hide session
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
class Admin_FormationController extends ZendAfi_Controller_Action { class Admin_FormationController extends ZendAfi_Controller_Action {
use Trait_Translator; use Trait_Translator;
use Trait_TimeSource;
public function getRessourceDefinitions() { public function getRessourceDefinitions() {
return [ return [
'model' => [ 'model' => [
...@@ -41,6 +41,18 @@ class Admin_FormationController extends ZendAfi_Controller_Action { ...@@ -41,6 +41,18 @@ class Admin_FormationController extends ZendAfi_Controller_Action {
'after_add' => function($formation) { $this->_redirect('/admin/session-formation/add/formation_id/' . $formation->getId());} ]; 'after_add' => function($formation) { $this->_redirect('/admin/session-formation/add/formation_id/' . $formation->getId());} ];
} }
protected function setYearsForCombo() {
$years = Class_SessionFormation::getYears();
$current_year= self::getCurrentYear();
if (empty($years))
$years[$current_year]=$current_year;
$this->view->years = $years;
return $this->view->selected_year = $this->_getParam('year',
in_array($current_year, $this->view->years) ?
$current_year:reset($years));
}
public function indexAction() { public function indexAction() {
if ($this->_request->isPost()) { if ($this->_request->isPost()) {
...@@ -50,17 +62,12 @@ class Admin_FormationController extends ZendAfi_Controller_Action { ...@@ -50,17 +62,12 @@ class Admin_FormationController extends ZendAfi_Controller_Action {
$this->view->titre = 'Mise à jour des formations'; $this->view->titre = 'Mise à jour des formations';
$formations_by_year = Class_Formation::indexByYear(Class_Formation::findAllBy(['order' => 'id desc']), true); $this->view->formations = array_filter(Class_Formation::findAllBy(['order' => 'id desc']),
$years = array_keys($formations_by_year);
$this->view->years = array_combine($years, $years);
$this->view->selected_year = $this->_getParam('year', end($years));
$this->view->formations = array_filter($formations_by_year[$this->view->selected_year],
function($f) {return !$f->hasSessions();}); function($f) {return !$f->hasSessions();});
$sessions = Class_SessionFormation::findAllBy(['where' => 'left(date_debut, 4)="'.$this->view->selected_year.'"', $this->setYearsForCombo();
'order' => 'date_debut']); $this->view->sessions = Class_SessionFormation::getAllSessionsForYear($this->view->selected_year);
$this->view->sessions = $sessions;
$this->_setParam('year', $this->view->selected_year); $this->_setParam('year', $this->view->selected_year);
} }
...@@ -68,7 +75,6 @@ class Admin_FormationController extends ZendAfi_Controller_Action { ...@@ -68,7 +75,6 @@ class Admin_FormationController extends ZendAfi_Controller_Action {
public function getAction() { public function getAction() {
$this->_helper->viewRenderer->setNoRender(); $this->_helper->viewRenderer->setNoRender();
$this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8'); $this->getResponse()->setHeader('Content-Type', 'application/json; charset=utf-8');
$formations_years = Class_Formation::indexByYear( $formations_years = Class_Formation::indexByYear(
Class_Formation::findAllBy(['order' => 'libelle']), Class_Formation::findAllBy(['order' => 'libelle']),
true); true);
......
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * 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 * 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 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
class Class_Date_Holiday { class Class_Date_Holiday {
public static function getTimestampsForYear($year = null) { public static function getTimestampsForYear($year = null) {
if (null == $year) if (null == $year)
$year = (int) date('Y'); $year = (int) date('Y');
$stamps = array( $stamps = array(
mktime(0, 0, 0, 1, 1, $year), // 1er janvier mktime(0, 0, 0, 1, 1, $year), // 1er janvier
...@@ -39,7 +39,7 @@ class Class_Date_Holiday { ...@@ -39,7 +39,7 @@ class Class_Date_Holiday {
// php ne les calcul que pour des timestamp valides // php ne les calcul que pour des timestamp valides
if (1970 > $year or 2037 < $year) if (1970 > $year or 2037 < $year)
return $stamps; return $stamps;
$easterDate = easter_date($year); $easterDate = easter_date($year);
$easterDay = date('j', $easterDate); $easterDay = date('j', $easterDate);
$easterMonth = date('n', $easterDate); $easterMonth = date('n', $easterDate);
......
...@@ -19,11 +19,33 @@ ...@@ -19,11 +19,33 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
class SessionFormationLoader extends Storm_Model_Loader {
public function getAllSessionsForYear($year) {
return Class_SessionFormation::findAllBy(['where' => 'left(date_debut, 4)="'.$year.'"',
'order' => 'date_debut']);
}
public function getYears() {
$sessions = Class_SessionFormation::findAllBy(['order' => 'id desc']);
$years = [];
foreach ($sessions as $session) {
$years[$session->getAnnee()]=$session->getAnnee();
}
arsort($years);
return $years;
}
public function getCurrentYear() {
return self::getCurrentYear();
}
}
class Class_SessionFormation extends Storm_Model_Abstract { class Class_SessionFormation extends Storm_Model_Abstract {
use Trait_TimeSource, Trait_Translator; use Trait_TimeSource, Trait_Translator;
protected $_table_name = 'sessions_formation'; protected $_table_name = 'sessions_formation';
protected $_loader_class = 'SessionFormationLoader';
protected $_belongs_to = ['formation' => ['model' => 'Class_Formation'], protected $_belongs_to = ['formation' => ['model' => 'Class_Formation'],
'lieu' => ['model' => 'Class_Lieu']]; 'lieu' => ['model' => 'Class_Lieu']];
...@@ -264,6 +286,7 @@ class Class_SessionFormation extends Storm_Model_Abstract { ...@@ -264,6 +286,7 @@ class Class_SessionFormation extends Storm_Model_Abstract {
return $this->setVisible(true); return $this->setVisible(true);
} }
} }
?> ?>
\ No newline at end of file
...@@ -16,13 +16,13 @@ ...@@ -16,13 +16,13 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * 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 * 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 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
trait Trait_TimeSource { trait Trait_TimeSource {
/** @var Class_TimeSource */ /** @var Class_TimeSource */
protected static $_time_source; protected static $_time_source;
/** /**
* @category testing * @category testing
...@@ -33,6 +33,11 @@ trait Trait_TimeSource { ...@@ -33,6 +33,11 @@ trait Trait_TimeSource {
} }
public static function getCurrentYear() {
return date('Y',self::getTimeSource()->time());
}
/** @return Class_TimeSource */ /** @return Class_TimeSource */
public static function getTimeSource() { public static function getTimeSource() {
if (null == self::$_time_source) if (null == self::$_time_source)
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* *
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE * 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 * 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 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
...@@ -26,11 +26,10 @@ class ZendAfi_View_Helper_Accueil_FormationsWidget extends ZendAfi_View_Helper_A ...@@ -26,11 +26,10 @@ class ZendAfi_View_Helper_Accueil_FormationsWidget extends ZendAfi_View_Helper_A
$selected_formations = array_filter(explode('-', $this->preferences['selected_formations'])); $selected_formations = array_filter(explode('-', $this->preferences['selected_formations']));
$formations = []; $formations = [];
foreach($selected_formations as $selected_formation) { foreach($selected_formations as $selected_formation) {
$formations[] = Class_Formation::find($selected_formation); if ($formation=Class_Formation::find($selected_formation))
$formations[] = $formation;
} }
$formations_by_year = Class_Formation::indexByYear($formations); $formations_by_year = Class_Formation::indexByYear($formations);
$this->contenu = $this->view->renderFormationsByYear($formations_by_year, 'Widget'); $this->contenu = $this->view->renderFormationsByYear($formations_by_year, 'Widget');
return $this->getHtmlArray(); return $this->getHtmlArray();
} }
......
...@@ -861,6 +861,50 @@ class Admin_FormationControllerShowLearnPythonTest extends Admin_FormationContr ...@@ -861,6 +861,50 @@ class Admin_FormationControllerShowLearnPythonTest extends Admin_FormationContr
} }
class Admin_FormationControllerSessionDefaultYearSelectionTest extends Admin_FormationControllerTestCase {
public function setUp() {
parent::setUp();
$_session_python_mars = $this->fixture('Class_SessionFormation',
['id'=>144,
'formation_id' => 12,
'date_debut' => '2010-03-21',
'stagiaires' => []
]);
$this->fixture('Class_SessionFormation',
['id'=>148,
'formation_id' => 12,
'date_debut' => '2012-06-21',
'stagiaires' => []
]);
$time_source = new TimeSourceForTest('2010-12-27 09:00:00');
Trait_TimeSource::setTimeSource($time_source);
}
/** @test */
public function defaultSelectedYearShouldBe2010() {
$this->dispatch('/admin/formation/index');
$this->assertXPathContentContains('//select[@name="year"]//option[@selected="selected"][@value="2010"]', '2010');
}
/** @test */
public function selectedYear2012ShouldDisplayTrainingWithoutSession() {
$this->dispatch('/admin/formation/index/year/2012');
$this->assertXPathContentContains('//tr//td', 'Learn emptyness');
}
/** @test */
public function selectedYear2009ShouldDisplayTrainingWithoutSession() {
$this->dispatch('/admin/formation/index/year/2012');
$this->assertXPathContentContains('//tr//td', 'Learn emptyness');
}
}
class Admin_FormationControllerSessionLearnPythonTest extends Admin_FormationControllerTestCase { class Admin_FormationControllerSessionLearnPythonTest extends Admin_FormationControllerTestCase {
public function setUp() { public function setUp() {
......
...@@ -216,16 +216,13 @@ class AbonneControllerFormationsListWithLearnJavaNotVisibleTest extends Abstract ...@@ -216,16 +216,13 @@ class AbonneControllerFormationsListWithLearnJavaNotVisibleTest extends Abstract
class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest extends AbstractAbonneControllerFormationsTestCase { class AbonneControllerFormationsSessionListWithLearnSmalltalkNotVisibleTest extends AbstractAbonneControllerFormationsTestCase {
public function setUp() { public function setUp() {
parent::setUp(); parent::setUp();
} }
/** @test */ /** @test */
public function trainingJavaShouldBeDisplayed() { public function trainingJavaShouldBeDisplayed() {
$this->dispatch('/opac/formations', true); $this->dispatch('/opac/formations', true);
$this->assertXPathContentContains('//h2', 'Learn Java',$this->response->getBody()); $this->assertXPathContentContains('//h2', 'Learn Java',$this->response->getBody());
......
...@@ -60,7 +60,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithNoSessionTest extends Zend ...@@ -60,7 +60,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithNoSessionTest extends Zend
'date_debut' => '2014-05-05'])]]), 'date_debut' => '2014-05-05'])]]),
['division' => 1, ['division' => 1,
'type_module' => 'FORMATIONS_WIDGET', 'type_module' => 'FORMATIONS_WIDGET',
'preferences' => ['selected_formations' => '1']]); 'preferences' => ['titre' => 'Formations','selected_formations' => '1']]);
} }
...@@ -72,7 +72,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithNoSessionTest extends Zend ...@@ -72,7 +72,7 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithNoSessionTest extends Zend
/** @test */ /** @test */
public function titleShouldBeBrowseJazzDomain() { public function titleShouldBeBrowseJazzDomain() {
$this->assertXPathContentContains($this->_html, '//div[@class="titre"]', 'Formations'); $this->assertXPathContentContains($this->_html, '//div[@class="titre"]', 'Formations',$this->_html);
} }
...@@ -225,4 +225,29 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithInvisibleFormationTest ext ...@@ -225,4 +225,29 @@ class ZendAfi_View_Helper_Accueil_FormationsWidgetWithInvisibleFormationTest ext
$this->assertNotXPathContentContains($this->_html, '//ul/li', 'Air Dogfight chapter 1'); $this->assertNotXPathContentContains($this->_html, '//ul/li', 'Air Dogfight chapter 1');
} }
} }
class ZendAfi_View_Helper_Accueil_FormationsWidgetWithDeletedFormationsInPreferencesTest extends ZendAfi_View_Helper_Accueil_FormationsWidgetTestCase {
public function setup() {
parent::setup();
$this->renderWidget(
$this->fixture('Class_Formation',
['id' => 1,
'libelle' => 'Air Dogfight chapter 1',
'visible' => true,
'sessions' => [$this->fixture('Class_SessionFormation',
['id' => 1,
'date_debut' => '2014-06-01',
'date_fin' => '2014-06-10'])]]),
['division' => 1,
'type_module' => 'FORMATIONS_WIDGET',
'preferences' => ['selected_formations' => '3-1-2']]);
}
/** @test */
public function airDogFightShouldBeDisplayed() {
$this->assertXPathContentContains($this->_html, '//ul/li', 'Air Dogfight chapter 1',$this->_html);
}
}
?> ?>
\ 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