@@ -76,14 +76,73 @@ public function __construct
7676 $ this ->promo_code_repository = $ promo_code_repository ;
7777 }
7878
79- private static $ speaker_announcement_excluded_tracks = [
80- 23 => [
81- IPresentation::SelectionStatus_Alternate => [],
82- IPresentation::SelectionStatus_Accepted => [],
83- IPresentation::SelectionStatus_Unaccepted => []
84- ]
85- ];
79+ /**
80+ * @param IPresentationSpeaker $speaker
81+ * @param ISummit $current_summit
82+ * @param bool|string $role
83+ * @param bool $check_email_existance
84+ * @return bool
85+ */
86+ public function sendSelectionAnnouncementEmailForSpeaker (IPresentationSpeaker $ speaker , ISummit $ current_summit , $ role = IPresentationSpeaker::RoleSpeaker, $ check_email_existance = true ){
87+
88+ return $ this ->tx_manager ->transaction (function () use (
89+ $ current_summit ,
90+ $ speaker ,
91+ $ role ,
92+ $ check_email_existance
93+ ) {
94+ // we need an email for this speaker ...
95+ $ email = $ speaker ->getEmail ();
96+ if (empty ($ email )) return false ;
97+
98+ if ($ check_email_existance && $ speaker ->announcementEmailAlreadySent ($ current_summit ->ID )) return false ;
99+
100+ $ sender_service = $ this ->sender_factory ->build ($ current_summit , $ speaker , $ role );
101+
102+ // get registration code
103+ if (is_null ($ sender_service )) {
104+ echo sprintf ('excluding email to %s ' , $ email ) . PHP_EOL ;
105+ return false ;
106+ }
107+
108+ $ code = null ;
109+
110+ if ($ speaker ->hasPublishedPresentations ($ current_summit ->getIdentifier (), $ role )) //get approved code
111+ {
112+ $ code = $ this ->promo_code_repository ->getNextAvailableByType
113+ (
114+ $ current_summit ,
115+ ISpeakerSummitRegistrationPromoCode::TypeAccepted
116+ );
117+ if (is_null ($ code )) throw new Exception ('not available promo code!!! ' );
118+ } else if ($ speaker ->hasAlternatePresentations ($ current_summit ->getIdentifier (), $ role )) // get alternate code
119+ {
120+ $ code = $ this ->promo_code_repository ->getNextAvailableByType
121+ (
122+ $ current_summit ,
123+ ISpeakerSummitRegistrationPromoCode::TypeAlternate
124+ );
125+ if (is_null ($ code )) throw new Exception ('not available alternate promo code!!! ' );
126+ }
86127
128+ $ params = [
129+
130+ 'Speaker ' => $ speaker ,
131+ 'Summit ' => $ current_summit ,
132+ "Role " => $ role
133+ ];
134+
135+ if (!is_null ($ code )) {
136+ $ speaker ->registerSummitPromoCode ($ code );
137+ $ code ->setEmailSent (true );
138+ $ code ->write ();
139+ $ params ['PromoCode ' ] = $ code ;
140+ }
141+ echo sprintf ('sending email to %s ' , $ email ) . PHP_EOL ;
142+ $ sender_service ->send ($ params );
143+ return true ;
144+ });
145+ }
87146
88147 public function sendSpeakersSelectionAnnouncementBySummit (ISummit $ current_summit , $ batch_size )
89148 {
@@ -120,59 +179,8 @@ public function sendSpeakersSelectionAnnouncementBySummit(ISummit $current_summi
120179
121180 foreach ($ speakers as $ speaker ) {
122181
123- if (!$ speaker instanceof IPresentationSpeaker) continue ;
124- // we need an email for this speaker ...
125- $ email = $ speaker ->getEmail ();
126- if (empty ($ email )) continue ;
127-
128- if ($ speaker ->announcementEmailAlreadySent ($ current_summit ->ID )) continue ;
129-
130- $ sender_service = $ this ->sender_factory ->build ($ current_summit , $ speaker , IPresentationSpeaker::RoleSpeaker);
131-
132- // get registration code
133- if (is_null ($ sender_service )) {
134- echo sprintf ('excluding email to %s ' , $ email ).PHP_EOL ;
135- continue ;
136- }
137-
138- $ code = null ;
139-
140- if ($ speaker ->hasPublishedPresentations ($ current_summit ->getIdentifier (), IPresentationSpeaker::RoleSpeaker)) //get approved code
141- {
142- $ code = $ this ->promo_code_repository ->getNextAvailableByType
143- (
144- $ current_summit ,
145- ISpeakerSummitRegistrationPromoCode::TypeAccepted,
146- $ batch_size
147- );
148- if (is_null ($ code )) throw new Exception ('not available promo code!!! ' );
149- } else if ($ speaker ->hasAlternatePresentations ($ current_summit ->getIdentifier (), IPresentationSpeaker::RoleSpeaker)) // get alternate code
150- {
151- $ code = $ this ->promo_code_repository ->getNextAvailableByType
152- (
153- $ current_summit ,
154- ISpeakerSummitRegistrationPromoCode::TypeAlternate,
155- $ batch_size
156- );
157- if (is_null ($ code )) throw new Exception ('not available alternate promo code!!! ' );
158- }
159-
160- $ params = array
161- (
162- 'Speaker ' => $ speaker ,
163- 'Summit ' => $ current_summit ,
164- "Role " => IPresentationSpeaker::RoleSpeaker
165- );
166-
167- if (!is_null ($ code )) {
168- $ speaker ->registerSummitPromoCode ($ code );
169- $ code ->setEmailSent (true );
170- $ code ->write ();
171- $ params ['PromoCode ' ] = $ code ;
172- }
173- echo sprintf ('sending email to %s ' , $ email ).PHP_EOL ;
174- $ sender_service ->send ($ params );
175- ++$ speakers_notified ;
182+ if ($ this ->sendSelectionAnnouncementEmailForSpeaker ($ speaker , $ current_summit ))
183+ ++$ speakers_notified ;
176184 }
177185 $ task ->updatePage ($ count , $ page_size );
178186 $ task ->write ();
@@ -224,65 +232,8 @@ public function sendModeratorsSelectionAnnouncementBySummit(ISummit $current_sum
224232 echo sprintf ('total speakers %s - count %s ' , $ count , count ($ moderators )).PHP_EOL ;
225233
226234 foreach ($ moderators as $ moderator ) {
227-
228- if (!$ moderator instanceof IPresentationSpeaker) continue ;
229- // we need an email for this speaker ...
230- $ email = $ moderator ->getEmail ();
231- if (empty ($ email )) continue ;
232-
233- if ($ moderator ->announcementEmailAlreadySent ($ current_summit ->ID )) continue ;
234-
235- $ sender_service = $ this ->sender_factory ->build ($ current_summit , $ moderator , IPresentationSpeaker::RoleModerator);
236- // get registration code
237- if (is_null ($ sender_service )) {
238- echo sprintf ('excluding email to %s ' , $ email ).PHP_EOL ;
239- continue ;
240- }
241-
242- $ code = null ;
243-
244- if (
245- $ moderator ->hasPublishedRegularPresentations ($ current_summit ->getIdentifier (), IPresentationSpeaker::RoleModerator, true ) ||
246- $ moderator ->hasPublishedLightningPresentations ($ current_summit ->getIdentifier (), IPresentationSpeaker::RoleModerator, true )
247- ) //get approved code
248- {
249- $ code = $ this ->promo_code_repository ->getNextAvailableByType
250- (
251- $ current_summit ,
252- ISpeakerSummitRegistrationPromoCode::TypeAccepted,
253- $ batch_size
254- );
255- if (is_null ($ code )) throw new Exception ('not available promo code!!! ' );
256- } else if
257- (
258- $ moderator ->hasAlternatePresentations ($ current_summit ->getIdentifier (), IPresentationSpeaker::RoleModerator, true )
259- ) // get alternate code
260- {
261- $ code = $ this ->promo_code_repository ->getNextAvailableByType
262- (
263- $ current_summit ,
264- ISpeakerSummitRegistrationPromoCode::TypeAlternate,
265- $ batch_size
266- );
267- if (is_null ($ code )) throw new Exception ('not available alternate promo code!!! ' );
268- }
269-
270- $ params = array
271- (
272- 'Speaker ' => $ moderator ,
273- 'Summit ' => $ current_summit ,
274- "Role " => IPresentationSpeaker::RoleModerator
275- );
276-
277- if (!is_null ($ code )) {
278- $ moderator ->registerSummitPromoCode ($ code );
279- $ code ->setEmailSent (true );
280- $ code ->write ();
281- $ params ['PromoCode ' ] = $ code ;
282- }
283- echo sprintf ('sending email to %s ' , $ email ).PHP_EOL ;
284- $ sender_service ->send ($ params );
285- ++$ speakers_notified ;
235+ if ($ this ->sendSelectionAnnouncementEmailForSpeaker ($ moderator , $ current_summit , IPresentationSpeaker::RoleModerator))
236+ ++$ speakers_notified ;
286237 }
287238 $ task ->updatePage ($ count , $ page_size );
288239 $ task ->write ();
0 commit comments