@@ -722,11 +722,13 @@ protected function assemblePartialDayOptions(FieldsetElement $options): DateTime
722
722
7 => $ this ->translate ('Sunday ' )
723
723
]
724
724
]);
725
+
726
+ $ timeOptions = $ this ->getTimeOptions ();
725
727
$ options ->addElement ('select ' , 'from ' , [
726
728
'class ' => 'autosubmit ' ,
727
729
'required ' => true ,
728
730
'value ' => '00:00 ' ,
729
- 'options ' => $ this -> getTimeOptions () ,
731
+ 'options ' => $ timeOptions ,
730
732
'label ' => $ this ->translate ('From ' )
731
733
]);
732
734
$ from = $ options ->getElement ('from ' );
@@ -740,9 +742,18 @@ protected function assemblePartialDayOptions(FieldsetElement $options): DateTime
740
742
'validators ' => [new GreaterThanValidator ()]
741
743
]);
742
744
745
+ $ selectedFromTime = $ from ->getValue ();
746
+ foreach ($ timeOptions as $ key => $ value ) {
747
+ $ timeOptions [$ key ] = sprintf ('%s (%s) ' , $ value , $ this ->translate ('Next Day ' ));
748
+
749
+ if ($ selectedFromTime === $ key ) {
750
+ break ;
751
+ }
752
+ }
753
+
743
754
$ to = $ options ->createElement ('select ' , 'to ' , [
744
755
'required ' => true ,
745
- 'options ' => $ this -> getTimeOptions ()
756
+ 'options ' => $ timeOptions
746
757
]);
747
758
$ options ->registerElement ($ to );
748
759
@@ -818,27 +829,18 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
818
829
]);
819
830
$ from = $ options ->getElement ('from_day ' );
820
831
832
+ $ selectedFromDay = (int ) $ from ->getValue ();
833
+
834
+ for ($ i = 1 ; $ i <= $ selectedFromDay ; $ i ++) {
835
+ $ toDays [$ i ] = sprintf ('%s (%s) ' , $ toDays [$ i ], $ this ->translate ('Next week ' ));
836
+ }
837
+
821
838
$ options ->addElement ('select ' , 'to_day ' , [
822
839
'class ' => 'autosubmit ' ,
823
840
'required ' => true ,
824
841
'options ' => $ toDays ,
825
842
'value ' => 7 ,
826
- 'label ' => $ this ->translate ('To ' , 'notifications.rotation ' ),
827
- 'validators ' => [
828
- new CallbackValidator (function ($ value , $ validator ) use ($ options ) {
829
- if ($ value !== $ options ->getValue ('from_day ' )) {
830
- return true ;
831
- }
832
-
833
- if ($ options ->getValue ('from_at ' ) < $ options ->getValue ('to_at ' )) {
834
- $ validator ->addMessage ($ this ->translate ('Shifts cannot last longer than 7 days ' ));
835
-
836
- return false ;
837
- }
838
-
839
- return true ;
840
- })
841
- ]
843
+ 'label ' => $ this ->translate ('To ' , 'notifications.rotation ' )
842
844
]);
843
845
$ to = $ options ->getElement ('to_day ' );
844
846
@@ -850,17 +852,24 @@ protected function assembleMultiDayOptions(FieldsetElement $options): DateTime
850
852
'label ' => $ this ->translate ('Handoff every ' )
851
853
]);
852
854
855
+ $ timeOptions = $ this ->getTimeOptions ();
853
856
$ fromAt = $ options ->createElement ('select ' , 'from_at ' , [
854
857
'class ' => 'autosubmit ' ,
855
858
'required ' => true ,
856
- 'options ' => $ this -> getTimeOptions ()
859
+ 'options ' => $ timeOptions
857
860
]);
858
861
$ options ->registerElement ($ fromAt );
859
862
863
+ if ($ selectedFromDay === (int ) $ to ->getValue ()) {
864
+ $ selectedFromAt = $ fromAt ->getValue ();
865
+ $ keyIndex = array_search ($ selectedFromAt , array_keys ($ timeOptions ));
866
+ $ timeOptions = array_slice ($ timeOptions , 0 , $ keyIndex + 1 , true );
867
+ }
868
+
860
869
$ toAt = $ options ->createElement ('select ' , 'to_at ' , [
861
870
'class ' => 'autosubmit ' ,
862
871
'required ' => true ,
863
- 'options ' => $ this -> getTimeOptions ()
872
+ 'options ' => $ timeOptions
864
873
]);
865
874
$ options ->registerElement ($ toAt );
866
875
0 commit comments