11<?php
22namespace Saleslayer \Synccatalog \Block \Adminhtml \Synccatalog \Edit \Tab ;
33
4+ use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
5+
46// use \Magento\Catalog\Model\Category as categoryModel;
57
68/**
@@ -25,10 +27,12 @@ public function __construct(
2527 \Magento \Framework \Registry $ registry ,
2628 \Magento \Framework \Data \FormFactory $ formFactory ,
2729 \Magento \Store \Model \System \Store $ systemStore ,
30+ TimezoneInterface $ timezone ,
2831 array $ data = []
2932 ) {
3033 parent ::__construct ($ context , $ registry , $ formFactory , $ data );
3134 $ this ->_systemStore = $ systemStore ;
35+ $ this ->timezone = $ timezone ;
3236 }
3337
3438 /**
@@ -55,25 +59,28 @@ protected function _prepareForm()
5559 $ modelData = $ model ->getData ();
5660
5761 if (empty ($ modelData )){
58- $ modelData ['store_view_ids ' ] = array ( '0 ' ) ;
62+ $ modelData ['store_view_ids ' ] = [ '0 ' ] ;
5963 }else {
6064 $ modelData ['store_view_ids ' ] = json_decode ($ modelData ['store_view_ids ' ],1 );
6165 }
6266
63- $ auto_sync_options = array ();
64- $ auto_sync_values = array (0 , 1 , 3 , 6 , 8 , 12 , 15 , 24 , 48 , 72 );
67+ $ auto_sync_options = [];
68+ $ auto_sync_values = [0 , 1 , 3 , 6 , 8 , 12 , 15 , 24 , 48 , 72 ];
69+
6570 foreach ($ auto_sync_values as $ auto_sync_value ) {
6671 if ($ auto_sync_value == 0 ){
67- array_push ($ auto_sync_options , array ( 'label ' => ' ' , 'value ' => $ auto_sync_value) );
72+ array_push ($ auto_sync_options , [ 'label ' => ' ' , 'value ' => $ auto_sync_value] );
6873 }else {
69- array_push ($ auto_sync_options , array ( 'label ' => $ auto_sync_value .'H ' , 'value ' => $ auto_sync_value) );
74+ array_push ($ auto_sync_options , [ 'label ' => $ auto_sync_value .'H ' , 'value ' => $ auto_sync_value] );
7075 }
7176 }
7277
78+ $ datetime_last_sync = '' ;
79+
7380 if (!empty ($ modelData ['last_sync ' ])){
74- $ time_lapsed = ' <br><small>Since last sync of this connector step: ' . $ this ->elapsed_time ( strtotime ( $ modelData ['last_sync ' ])). ' </small> ' ;
75- } else {
76- $ time_lapsed = '' ;
81+ $ last_sync_timezoned = $ this ->timezone -> date ( $ modelData ['last_sync ' ])-> format ( ' M d, Y, H:i:s A ' ) ;
82+ $ datetime_last_sync = " <br><small>Connector's last auto-synchronization: " . $ last_sync_timezoned . " </small> " ;
83+ $ datetime_last_sync .= " <br><small><strong>*Note: This synchronization will be executed according to the server time.</strong></small> " ;
7784 }
7885
7986 $ fieldset ->addField (
@@ -87,21 +94,24 @@ protected function _prepareForm()
8794 'required ' => false ,
8895 'values ' => $ auto_sync_options ,
8996 'disabled ' => false ,
90- 'after_element_html ' =>$ time_lapsed ,
97+ 'after_element_html ' => $ datetime_last_sync ,
9198 'class ' => 'conn_field '
9299 ]
93100 );
94101
95- if (!empty ($ modelData ) && isset ($ modelData ['auto_sync ' ]) && $ modelData ['auto_sync ' ]>= 24 ){
102+ if (!empty ($ modelData ) && isset ($ modelData ['auto_sync ' ]) && $ modelData ['auto_sync ' ] >= 24 ){
96103 $ hour_input_disabled = false ;
97104 }else {
98105 $ hour_input_disabled = true ;
99106 }
100107
101- $ auto_sync_hour_options = array () ;
108+ $ auto_sync_hour_options = [] ;
102109 $ hours_range = range (0 , 23 );
103- foreach ($ hours_range as $ hour ){
104- $ auto_sync_hour_options [$ hour ] = array ('label ' => (strlen ($ hour ) == 1 ? '0 ' .$ hour : $ hour ).':00 ' , 'value ' => $ hour );
110+ foreach ($ hours_range as $ hour ){
111+ $ auto_sync_hour_options [$ hour ] = [
112+ 'label ' => (strlen ($ hour ) == 1 ? '0 ' .$ hour : $ hour ).':00 ' ,
113+ 'value ' => $ hour
114+ ];
105115 }
106116
107117 $ fieldset ->addField (
@@ -152,21 +162,6 @@ protected function _prepareForm()
152162
153163 return parent ::_prepareForm ();
154164 }
155- private function elapsed_time ($ timestamp , $ precision = 2 ) {
156- $ time = time () - $ timestamp ;
157- $ result = '' ;
158- $ a = array ('decade ' => 315576000 , 'year ' => 31557600 , 'month ' => 2629800 , 'week ' => 604800 , 'day ' => 86400 , 'hour ' => 3600 , 'min ' => 60 , 'sec ' => 1 );
159- $ i = 0 ;
160- foreach ($ a as $ k => $ v ) {
161- $ $ k = floor ($ time /$ v );
162- if ($ $ k ) $ i ++;
163- $ time = $ i >= $ precision ? 0 : $ time - $ $ k * $ v ;
164- $ s = $ $ k > 1 ? 's ' : '' ;
165- $ $ k = $ $ k ? $ $ k .' ' .$ k .$ s .' ' : '' ;
166- $ result .= $ $ k ;
167- }
168- return $ result ? $ result .'ago ' : '1 sec to go ' ;
169- }
170165
171166 /**
172167 * Prepare label for tab
0 commit comments