@@ -18,6 +18,9 @@ class manager
1818 /** @var \phpbb\config\config */
1919 protected $ config ;
2020
21+ /** @var \phpbb\user */
22+ protected $ user ;
23+
2124 /** @var string */
2225 protected $ ads_table ;
2326
@@ -32,14 +35,16 @@ class manager
3235 *
3336 * @param \phpbb\db\driver\driver_interface $db DB driver interface
3437 * @param \phpbb\config\config $config Config object
38+ * @param \phpbb\user $user User object
3539 * @param string $ads_table Ads table
3640 * @param string $ad_locations_table Ad locations table
3741 * @param string $ad_group_table Ad group table
3842 */
39- public function __construct (\phpbb \db \driver \driver_interface $ db , \phpbb \config \config $ config , $ ads_table , $ ad_locations_table , $ ad_group_table )
43+ public function __construct (\phpbb \db \driver \driver_interface $ db , \phpbb \config \config $ config , \ phpbb \ user $ user , $ ads_table , $ ad_locations_table , $ ad_group_table )
4044 {
4145 $ this ->db = $ db ;
4246 $ this ->config = $ config ;
47+ $ this ->user = $ user ;
4348 $ this ->ads_table = $ ads_table ;
4449 $ this ->ad_locations_table = $ ad_locations_table ;
4550 $ this ->ad_group_table = $ ad_group_table ;
@@ -78,15 +83,19 @@ public function get_ads($ad_locations, $user_groups, $non_content_page = false)
7883 $ sql_where_non_content = $ non_content_page ? 'AND a.ad_content_only = 0 ' : '' ;
7984 $ sql_where_user_groups = !empty ($ user_groups ) ? 'AND NOT EXISTS (SELECT ag.group_id FROM ' . $ this ->ad_group_table . ' ag WHERE ag.ad_id = a.ad_id AND ' . $ this ->db ->sql_in_set ('ag.group_id ' , $ user_groups ) . ') ' : '' ;
8085
86+ // Get user's current time and convert to UTC equivalent for comparison
87+ $ user_now = $ this ->user ->create_datetime ();
88+ $ sql_time = $ this ->user ->get_timestamp_from_format ('Y-m-d H:i:s ' , $ user_now ->format ('Y-m-d H:i:s ' ), new \DateTimeZone ('UTC ' ));
89+
8190 $ sql = 'SELECT al.location_id, a.ad_id, a.ad_code, a.ad_centering
8291 FROM ' . $ this ->ad_locations_table . ' al
8392 LEFT JOIN ' . $ this ->ads_table . ' a
8493 ON (al.ad_id = a.ad_id)
8594 WHERE a.ad_enabled = 1
8695 AND (a.ad_start_date = 0
87- OR a.ad_start_date < ' . time () . ')
96+ OR a.ad_start_date <= ' . $ sql_time . ')
8897 AND (a.ad_end_date = 0
89- OR a.ad_end_date > ' . time () . ")
98+ OR a.ad_end_date > ' . $ sql_time . ")
9099 $ sql_where_views
91100 $ sql_where_clicks
92101 $ sql_where_non_content
0 commit comments