2020use phpbb \language \language ;
2121use phpbb \notification \manager ;
2222use phpbb \template \template ;
23+ use phpbb \user ;
2324use phpbb \webpushnotifications \form \form_helper ;
2425use Symfony \Component \EventDispatcher \EventSubscriberInterface ;
2526
@@ -46,6 +47,9 @@ class listener implements EventSubscriberInterface
4647 /* @var template */
4748 protected $ template ;
4849
50+ /** @var user */
51+ protected $ user ;
52+
4953 /* @var manager */
5054 protected $ phpbb_notifications ;
5155
@@ -61,17 +65,19 @@ class listener implements EventSubscriberInterface
6165 * @param form_helper $form_helper Form helper object
6266 * @param language $language Language object
6367 * @param template $template Template object
68+ * @param user $user
6469 * @param manager $phpbb_notifications Notifications manager object
6570 * @param $root_path
6671 */
67- public function __construct (config $ config , controller_helper $ controller_helper , FastImageSize $ imagesize , form_helper $ form_helper , language $ language , template $ template , manager $ phpbb_notifications , $ root_path )
72+ public function __construct (config $ config , controller_helper $ controller_helper , FastImageSize $ imagesize , form_helper $ form_helper , language $ language , template $ template , user $ user , manager $ phpbb_notifications , $ root_path )
6873 {
6974 $ this ->config = $ config ;
7075 $ this ->controller_helper = $ controller_helper ;
7176 $ this ->imagesize = $ imagesize ;
7277 $ this ->form_helper = $ form_helper ;
7378 $ this ->language = $ language ;
7479 $ this ->template = $ template ;
80+ $ this ->user = $ user ;
7581 $ this ->phpbb_notifications = $ phpbb_notifications ;
7682 $ this ->root_path = $ root_path ;
7783 }
@@ -92,19 +98,26 @@ public static function getSubscribedEvents()
9298 */
9399 public function load_template_data ()
94100 {
101+ if (!$ this ->can_use_notifications ())
102+ {
103+ return ;
104+ }
105+
95106 $ methods = $ this ->phpbb_notifications ->get_subscription_methods ();
96107 $ webpush_method = $ methods ['notification.method.phpbb.wpn.webpush ' ] ?? null ;
97108
98- if ($ webpush_method ! == null )
109+ if ($ webpush_method = == null )
99110 {
100- if (!$ this ->language ->is_set ('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH ' ))
101- {
102- $ this ->language ->add_lang ('webpushnotifications_module_ucp ' , 'phpbb/webpushnotifications ' );
103- }
111+ return ;
112+ }
104113
105- $ template_ary = $ webpush_method ['method ' ]->get_ucp_template_data ($ this ->controller_helper , $ this ->form_helper );
106- $ this ->template ->assign_vars ($ template_ary );
114+ if (!$ this ->language ->is_set ('NOTIFICATION_METHOD_PHPBB_WPN_WEBPUSH ' ))
115+ {
116+ $ this ->language ->add_lang ('webpushnotifications_module_ucp ' , 'phpbb/webpushnotifications ' );
107117 }
118+
119+ $ template_ary = $ webpush_method ['method ' ]->get_ucp_template_data ($ this ->controller_helper , $ this ->form_helper );
120+ $ this ->template ->assign_vars ($ template_ary );
108121 }
109122
110123 /**
@@ -217,4 +230,18 @@ protected function add_error($event, $error_key, $param = null)
217230 $ error [] = $ this ->language ->lang ($ error_key , $ param );
218231 $ event ['error ' ] = $ error ;
219232 }
233+
234+ /**
235+ * Can notifications be used by the user?
236+ *
237+ * @return bool
238+ */
239+ protected function can_use_notifications ()
240+ {
241+ return $ this ->config ['load_notifications ' ]
242+ && $ this ->config ['allow_board_notifications ' ]
243+ && $ this ->config ['wpn_webpush_enable ' ]
244+ && $ this ->user ->id () !== ANONYMOUS
245+ && (int ) $ this ->user ->data ['user_type ' ] !== USER_IGNORE ;
246+ }
220247}
0 commit comments