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

dev #36620 improve formation widget : fix order by selection display

parent 2dbc1ecc
Branches
Tags
6 merge requests!1553Master,!1519Master,!1506Master,!1502Master,!1451Dev#36620 improve formation widget,!1437Dev#36620 improve formation widget
......@@ -25,9 +25,9 @@ class Class_Systeme_ModulesAccueil_Formations extends Class_Systeme_ModulesAccue
const DISPLAY_BLOC ='Block';
const DISPLAY_NO_GROUP = 'NoGroup';
const DISPLAY_GROUP_BY_YEAR = 'ByYear';
const ORDER_BY_SELECTION = 0;
const ORDER_BY_CONTRIBUTORS=1;
const ORDER_BY_CREATION_ID=2;
const ORDER_BY_SELECTION = 'selection';
const ORDER_BY_CONTRIBUTORS='contributors';
const ORDER_BY_CREATION_ID='creation';
protected $_group = Class_Systeme_ModulesAccueil::GROUP_INFO;
......
......@@ -39,14 +39,29 @@ class ZendAfi_View_Helper_Accueil_FormationsWidget extends ZendAfi_View_Helper_A
if(!$selected_formations = array_filter(explode('-', $this->preferences['selected_formations'])))
return [];
if(!isset($this->preferences['display_order']) || !($display_order = $this->preferences['display_order']))
return Class_Formation::findAllBy(['id' => $selected_formations]);
$display_order = $this->preferences['display_order'];
if( 1 == $display_order)
if( Class_Systeme_ModulesAccueil_Formations::ORDER_BY_SELECTION == $display_order)
return $this->_displayBySelection($selected_formations);
if( Class_Systeme_ModulesAccueil_Formations::ORDER_BY_CONTRIBUTORS == $display_order)
return $this->_displayByNumberOfParticipants($selected_formations);
if( 2 == $display_order)
if( Class_Systeme_ModulesAccueil_Formations::ORDER_BY_CREATION_ID == $display_order)
return $this->_displayByCreationDate($selected_formations);
return Class_Formation::findAllBy(['id' => $selected_formations]);
}
protected function _displayBySelection($formations_ids) {
$formations = Class_Formation::findAllBy(['id' => $formations_ids]);
usort($formations, function ($one, $two)
use ($formations_ids){
return array_search($one->getId(),$formations_ids) > array_search($two->getId(),$formations_ids) ? 1: -1;
});
return $formations;
}
......
......@@ -312,8 +312,9 @@ class ZendAfi_View_Helper_Accueil_SortAndDisplayFormationsWidgetTest extends Zen
['division' => 1,
'type_module' => 'FORMATIONS_WIDGET',
'preferences' => ['selected_formations' => '3-1-5',
'display_order' => 0]]);
$this->assertXPathContentContains($this->_html, '//ul/li[1]' , 'Formation numero 1');
'display_order' => 'selection',
'display_group_mode' => 'NoGroup']]);
$this->assertXPathContentContains($this->_html, '//ul/li[1]' , 'Formation numero 3');
}
......@@ -325,7 +326,7 @@ class ZendAfi_View_Helper_Accueil_SortAndDisplayFormationsWidgetTest extends Zen
['division' => 1,
'type_module' => 'FORMATIONS_WIDGET',
'preferences' => ['selected_formations' => '3-1-5',
'display_order' => 1,
'display_order' => 'contributors',
'display_group_mode' => 'NoGroup']]);
$this->assertXPathContentContains($this->_html, '//ul/li[1]' , 'Formation numero 1');
......@@ -340,7 +341,7 @@ class ZendAfi_View_Helper_Accueil_SortAndDisplayFormationsWidgetTest extends Zen
['division' => 1,
'type_module' => 'FORMATIONS_WIDGET',
'preferences' => ['selected_formations' => '3-1-5',
'display_order' => 2,
'display_order' => 'creation',
]]);
$this->assertXPathContentContains($this->_html, '//ul/li[2]' , 'Formation numero 1');
......@@ -355,7 +356,7 @@ class ZendAfi_View_Helper_Accueil_SortAndDisplayFormationsWidgetTest extends Zen
['division' => 1,
'type_module' => 'FORMATIONS_WIDGET',
'preferences' => ['selected_formations' => '3-1-5',
'display_order' => 2,
'display_order' => 'creation',
'display_mode' =>'Block']]);
$this->assertXPathContentContains($this->_html, '//dd[1]' , '1 octobre 2016 au 4 octobre 2016');
......@@ -369,7 +370,7 @@ class ZendAfi_View_Helper_Accueil_SortAndDisplayFormationsWidgetTest extends Zen
['division' => 1,
'type_module' => 'FORMATIONS_WIDGET',
'preferences' => ['selected_formations' => '3-1-5',
'display_order' => 2,
'display_order' => 'creation',
'display_group_mode' => 'ByYear',
'display_mode' =>'Block']]);
$this->assertXPathContentContains($this->_html, '//h2[1]' , '2010');
......
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