forked from spiegel/seminars
/
class.tx_seminars_registrationmanager.php
1471 lines (1291 loc) · 51.6 KB
/
class.tx_seminars_registrationmanager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/**
* This utility class checks and creates registrations for seminars.
*
* This file does not include the locallang file in the BE because objectfromdb already does that.
*
* @package TYPO3
* @subpackage tx_seminars
*
* @author Oliver Klee <typo3-coding@oliverklee.de>
* @author Niels Pardon <mail@niels-pardon.de>
*/
class tx_seminars_registrationmanager extends tx_oelib_templatehelper {
/**
* @var string same as class name
*/
public $prefixId = 'tx_seminars_registrationmanager';
/**
* @var string path to this script relative to the extension directory
*/
public $scriptRelPath = 'class.tx_seminars_registrationmanager.php';
/**
* @var string the extension key
*/
public $extKey = 'seminars';
/**
* @var tx_seminars_registrationmanager
*/
private static $instance = NULL;
/**
* @var tx_seminars_registration the current registration
*/
private $registration = NULL;
/**
* @var bool whether we have already initialized the templates
* (which is done lazily)
*/
private $isTemplateInitialized = FALSE;
/**
* hook objects for this class
*
* @var array
*/
private $hooks = array();
/**
* whether the hooks in $this->hooks have been retrieved
*
* @var bool
*/
private $hooksHaveBeenRetrieved = FALSE;
/**
* @var int use text format for e-mails to attendees
*/
const SEND_TEXT_MAIL = 0;
/**
* @var int use HTML format for e-mails to attendees
*/
const SEND_HTML_MAIL = 1;
/**
* @var int use user-specific format for e-mails to attendees
*/
const SEND_USER_MAIL = 2;
/**
* a link builder instance
*
* @var tx_seminars_Service_SingleViewLinkBuilder
*/
private $linkBuilder = NULL;
/**
* The constructor.
*
* It still is public due to the templatehelper base class. Nevertheless,
* getInstance should be used so the Singleton property is retained.
*/
public function __construct() {
$this->init();
}
/**
* Frees as much memory that has been used by this object as possible.
*/
public function __destruct() {
unset($this->registration, $this->linkBuilder);
$this->hooks = array();
parent::__destruct();
}
/**
* Returns the instance of this class.
*
* @return tx_seminars_registrationmanager the current Singleton instance
*/
public static function getInstance() {
if (self::$instance === NULL) {
self::$instance = t3lib_div::makeInstance('tx_seminars_registrationmanager');
}
return self::$instance;
}
/**
* Purges the current instance so that getInstance will create a new instance.
*
* @return void
*/
public static function purgeInstance() {
self::$instance = NULL;
}
/**
* Checks whether is possible to register for a given event at all:
* if a possibly logged-in user has not registered yet for this event,
* if the event isn't canceled, full etc.
*
* If no user is logged in, it is just checked whether somebody could
* register for this event.
*
* This function works even if no user is logged in.
*
* @param tx_seminars_seminar $event
* am event for which we'll check if it is possible to register
*
* @return bool TRUE if it is okay to register, FALSE otherwise
*/
public function canRegisterIfLoggedIn(tx_seminars_seminar $event) {
if (!$event->canSomebodyRegister()) {
return FALSE;
}
if (!tx_oelib_FrontEndLoginManager::getInstance()->isLoggedIn()) {
return TRUE;
}
$canRegister = $this->couldThisUserRegister($event);
/** @var $user tx_seminars_Model_FrontEndUser */
$user = tx_oelib_FrontEndLoginManager::getInstance()->getLoggedInUser('tx_seminars_Mapper_FrontEndUser');
foreach ($this->getHooks() as $hook) {
if (method_exists($hook, 'canRegisterForSeminar')) {
$canRegister = $canRegister && $hook->canRegisterForSeminar($event, $user);
}
}
return $canRegister;
}
/**
* Checks whether is possible to register for a given seminar at all:
* if a possibly logged-in user has not registered yet for this seminar, if the seminar isn't canceled, full etc.
*
* If no user is logged in, it is just checked whether somebody could register for this seminar.
*
* Returns a message if there is anything to complain about and an empty string otherwise.
*
* This function even works if no user is logged in.
*
* Note: This function does not check whether a logged-in front-end user fulfills all requirements for an event.
*
* @param tx_seminars_seminar $event a seminar for which we'll check if it is possible to register
*
* @return string error message or empty string
*/
public function canRegisterIfLoggedInMessage(tx_seminars_seminar $event) {
$message = '';
$isLoggedIn = tx_oelib_FrontEndLoginManager::getInstance()->isLoggedIn();
if ($isLoggedIn && $this->isUserBlocked($event)) {
$message = $this->translate('message_userIsBlocked');
} elseif ($isLoggedIn && !$this->couldThisUserRegister($event)) {
$message = $this->translate('message_alreadyRegistered');
} elseif (!$event->canSomebodyRegister()) {
$message = $event->canSomebodyRegisterMessage();
}
if ($isLoggedIn && ($message === '')) {
/** @var $user tx_seminars_Model_FrontEndUser */
$user = tx_oelib_FrontEndLoginManager::getInstance()->getLoggedInUser('tx_seminars_Mapper_FrontEndUser');
foreach ($this->getHooks() as $hook) {
if (method_exists($hook, 'canRegisterForSeminarMessage')) {
$message = $hook->canRegisterForSeminarMessage($event, $user);
if ($message !== '') {
break;
}
}
}
}
return $message;
}
/**
* Checks whether the current FE user (if any is logged in) could register
* for the current event, not checking the event's vacancies yet.
* So this function only checks whether the user is logged in and isn't blocked for the event's duration yet.
*
* Note: This function does not check whether a logged-in front-end user fulfills all requirements for an event.
*
* @param tx_seminars_seminar $seminar a seminar for which we'll check if it is possible to register
*
* @return bool TRUE if the user could register for the given event, FALSE otherwise
*/
private function couldThisUserRegister(tx_seminars_seminar $seminar) {
// A user can register either if the event allows multiple registrations
// or the user isn't registered yet and isn't blocked either.
return $seminar->allowsMultipleRegistrations() || (!$this->isUserRegistered($seminar) && !$this->isUserBlocked($seminar));
}
/**
* Creates an HTML link to the registration or login page.
*
* @param tx_oelib_templatehelper $plugin the pi1 object with configuration data
* @param tx_seminars_seminar $event the seminar to create the registration link for
*
* @return string the HTML tag, will be empty if the event needs no registration, nobody can register to this event or the
* currently logged in user is already registered to this event and the event does not allow multiple
* registrations by one user
*/
public function getRegistrationLink(tx_oelib_templatehelper $plugin, tx_seminars_seminar $event) {
if (!$event->needsRegistration() || !$this->canRegisterIfLoggedIn($event)) {
return '';
}
return $this->getLinkToRegistrationOrLoginPage($plugin, $event);
}
/**
* Creates an HTML link to either the registration page (if a user is logged in) or the login page (if no user is logged in).
*
* Before you can call this function, you should make sure that the link makes sense (ie. the seminar still has vacancies, the
* user has not registered for this seminar etc.).
*
* @param tx_oelib_templatehelper $plugin an object for a live page
* @param tx_seminars_seminar $seminar a seminar for which we'll check if it is possible to register
*
* @return string HTML code with the link
*/
public function getLinkToRegistrationOrLoginPage(tx_oelib_templatehelper $plugin, tx_seminars_seminar $seminar) {
return $this->getLinkToStandardRegistrationOrLoginPage($plugin, $seminar, $this->getRegistrationLabel($plugin, $seminar));
}
/**
* Creates the label for the registration link.
*
* @param tx_oelib_templatehelper $plugin an object for a live page
* @param tx_seminars_seminar $seminar a seminar to which the registration should relate
*
* @return string label for the registration link, will not be empty
*/
private function getRegistrationLabel(tx_oelib_templatehelper $plugin, tx_seminars_seminar $seminar) {
if ($seminar->hasVacancies()) {
if ($seminar->hasDate()) {
$label = $plugin->translate('label_onlineRegistration');
} else {
$label = $plugin->translate('label_onlinePrebooking');
}
} else {
if ($seminar->hasRegistrationQueue()) {
$label = sprintf(
$plugin->translate('label_onlineRegistrationOnQueue'), $seminar->getAttendancesOnRegistrationQueue()
);
} else {
$label = $plugin->translate('label_onlineRegistration');
}
}
return $label;
}
/**
* Creates an HTML link to either the registration page (if a user is logged in) or the login page (if no user is logged in).
*
* This function only creates the link to the standard registration or login
* page; it should not be used if the seminar has a separate details page.
*
* @param tx_oelib_templatehelper $plugin an object for a live page
* @param tx_seminars_seminar $seminar a seminar for which we'll check if it is possible to register
* @param string $label label for the link, will not be empty
*
* @return string HTML code with the link
*/
private function getLinkToStandardRegistrationOrLoginPage(
tx_oelib_templatehelper $plugin, tx_seminars_seminar $seminar, $label
) {
if (tx_oelib_FrontEndLoginManager::getInstance()->isLoggedIn()) {
// provides the registration link
$result = $plugin->cObj->getTypoLink(
$label,
$plugin->getConfValueInteger('registerPID'),
array('tx_seminars_pi1[seminar]' => $seminar->getUid(), 'tx_seminars_pi1[action]' => 'register')
);
} else {
// provides the login link
$result = $plugin->getLoginLink($label, $plugin->getConfValueInteger('registerPID'), $seminar->getUid());
}
return $result;
}
/**
* Creates an HTML link to the unregistration page (if a user is logged in).
*
* @param tslib_pibase $plugin an object for a live page
* @param tx_seminars_registration $registration a registration from which we'll get the UID for our GET parameters
*
* @return string HTML code with the link
*/
public function getLinkToUnregistrationPage(tslib_pibase $plugin, tx_seminars_registration $registration) {
return $plugin->cObj->getTypoLink(
$plugin->translate('label_onlineUnregistration'),
$plugin->getConfValueInteger('registerPID'),
array('tx_seminars_pi1[registration]' => $registration->getUid(), 'tx_seminars_pi1[action]' => 'unregister')
);
}
/**
* Checks whether a seminar UID is valid, ie., a non-deleted and non-hidden seminar with the given number exists.
*
* This function can be called even if no seminar object exists.
*
* @param string $seminarUid a given seminar UID (needs not necessarily be an int)
*
* @return bool TRUE the UID is valid, FALSE otherwise
*/
public function existsSeminar($seminarUid) {
return tx_seminars_OldModel_Abstract::recordExists($seminarUid, 'tx_seminars_seminars');
}
/**
* Checks whether a seminar UID is valid, ie., a non-deleted and non-hidden seminar with the given number exists.
*
* This method can be called even if no seminar object exists.
*
* For invalid or inexistent UIDs, this method also send a 404 HTTP header.
*
* @param string $seminarUid a given seminar UID (needs not necessarily be an int)
*
* @return string an empty string if the UID is valid, otherwise a localized error message
*/
public function existsSeminarMessage($seminarUid) {
if ($seminarUid <= 0) {
tx_oelib_headerProxyFactory::getInstance()->getHeaderProxy()->addHeader('Status: 404 Not Found');
return $this->translate('message_missingSeminarNumber');
}
if (!tx_seminars_OldModel_Abstract::recordExists($seminarUid, 'tx_seminars_seminars')) {
tx_oelib_headerProxyFactory::getInstance()->getHeaderProxy()->addHeader('Status: 404 Not Found');
return $this->translate('message_wrongSeminarNumber');
}
return '';
}
/**
* Checks whether a front-end user is already registered for this seminar.
*
* This method must not be called when no front-end user is logged in!
*
* @param tx_seminars_seminar $seminar a seminar for which we'll check if it is possible to register
*
* @return bool TRUE if user is already registered, FALSE otherwise.
*/
public function isUserRegistered(tx_seminars_seminar $seminar) {
return $seminar->isUserRegistered($this->getFeUserUid());
}
/**
* Checks whether a certain user already is registered for this seminar.
*
* This method must not be called when no front-end user is logged in!
*
* @param tx_seminars_seminar $seminar a seminar for which we'll check if it is possible to register
*
* @return string empty string if everything is OK, else a localized error message
*/
public function isUserRegisteredMessage(tx_seminars_seminar $seminar) {
return $seminar->isUserRegisteredMessage($this->getFeUserUid());
}
/**
* Checks whether a front-end user is already blocked during the time for a given event by other booked events.
*
* For this, only events that forbid multiple registrations are checked.
*
* @param tx_seminars_seminar $seminar a seminar for which we'll check whether the user already is blocked by an other seminars
*
* @return bool TRUE if user is blocked by another registration, FALSE otherwise
*/
private function isUserBlocked(tx_seminars_seminar $seminar) {
return $seminar->isUserBlocked($this->getFeUserUid());
}
/**
* Checks whether the data the user has just entered is okay for creating
* a registration, e.g. mandatory fields are filled, number fields only
* contain numbers, the number of seats to register is not too high etc.
*
* Please note that this function does not create a registration - it just checks.
*
* @param tx_seminars_seminar $seminar the seminar object (that's the seminar we would like to register for)
* @param array $registrationData associative array with the registration data the user has just entered
*
* @return bool TRUE if the data is okay, FALSE otherwise
*/
public function canCreateRegistration(tx_seminars_seminar $seminar, array $registrationData) {
return $this->canRegisterSeats($seminar, $registrationData['seats']);
}
/**
* Checks whether a registration with a given number of seats could be
* created, ie. an actual number is given and there are at least that many vacancies.
*
* @param tx_seminars_seminar $seminar the seminar object (that's the seminar we would like to register for)
* @param int|string $numberOfSeats the number of seats to check (should be an integer, but we can't be sure of this)
*
* @return bool TRUE if there are at least that many vacancies, FALSE otherwise
*/
public function canRegisterSeats(tx_seminars_seminar $seminar, $numberOfSeats) {
$numberOfSeats = trim($numberOfSeats);
// If no number of seats is given, ie. the user has not entered anything
// or the field is not shown at all, assume 1.
if (($numberOfSeats == '') || ($numberOfSeats == '0')) {
$numberOfSeats = '1';
}
$numberOfSeatsInt = (int)$numberOfSeats;
// Check whether we have a valid number
if ($numberOfSeats == strval($numberOfSeatsInt)) {
if ($seminar->hasUnlimitedVacancies()) {
$result = TRUE;
} else {
$result = ($seminar->hasRegistrationQueue() || ($seminar->getVacancies() >= $numberOfSeatsInt));
}
} else {
$result = FALSE;
}
return $result;
}
/**
* Creates a registration to $this->registration, writes it to DB,
* and notifies the organizer and the user (both via e-mail).
*
* The additional notifications will only be sent if this is enabled in the
* TypoScript setup (which is the default).
*
* @param tx_seminars_seminar $seminar the seminar we would like to register for
* @param array $formData the raw registration data from the registration form
* @param tslib_pibase $plugin live plugin object
*
* @return tx_seminars_Model_Registration the created, saved registration
*/
public function createRegistration(tx_seminars_seminar $seminar, array $formData, tslib_pibase $plugin) {
$this->registration = t3lib_div::makeInstance('tx_seminars_registration', $plugin->cObj);
$this->registration->setRegistrationData($seminar, $this->getFeUserUid(), $formData);
$this->registration->commitToDb();
$seminar->calculateStatistics();
$user = tx_oelib_FrontEndLoginManager::getInstance()->getLoggedInUser('tx_seminars_Mapper_FrontEndUser');
foreach ($this->getHooks() as $hook) {
if (method_exists($hook, 'seminarRegistrationCreated')) {
$hook->seminarRegistrationCreated($this->registration, $user);
}
}
/** @var tx_seminars_Mapper_Registration $mapper */
$mapper = tx_oelib_MapperRegistry::get('tx_seminars_Mapper_Registration');
return $mapper->find($this->registration->getUid());
}
/**
* Sends the e-mails for a new registration.
*
* @param tx_seminars_registration $registration
* @param tslib_pibase $plugin
*
* @return void
*/
public function sendEmailsForNewRegistration(tx_seminars_registration $registration, tslib_pibase $plugin) {
if ($this->registration->isOnRegistrationQueue()) {
$this->notifyAttendee($this->registration, $plugin, 'confirmationOnRegistrationForQueue');
$this->notifyOrganizers($this->registration, 'notificationOnRegistrationForQueue');
} else {
$this->notifyAttendee($this->registration, $plugin, 'confirmation');
$this->notifyOrganizers($this->registration, 'notification');
}
if ($this->getConfValueBoolean('sendAdditionalNotificationEmails')) {
$this->sendAdditionalNotification($this->registration);
}
}
/**
* Fills $registration with $formData (as submitted via the registration form).
*
* This function sets all necessary registration data except for three
* things:
* - event
* - user
* - whether the registration is on the queue
*
* Note: This functions does not check whether registration is possible at all.
*
* @param tx_seminars_Model_Registration $registration the registration to fill, must already have an event assigned
* @param array $formData the raw data submitted via the form, may be empty
*
* @return void
*/
protected function setRegistrationData(tx_seminars_Model_Registration $registration, array $formData) {
$event = $registration->getEvent();
$seats = isset($formData['seats']) ? (int)$formData['seats'] : 1;
if ($seats < 1) {
$seats = 1;
}
$registration->setSeats($seats);
$registeredThemselves = isset($formData['registered_themselves'])
? (bool)$formData['registered_themselves'] : FALSE;
$registration->setRegisteredThemselves($registeredThemselves);
$availablePrices = $event->getAvailablePrices();
if (isset($formData['price']) && isset($availablePrices[$formData['price']])) {
$priceCode = $formData['price'];
} else {
reset($availablePrices);
$priceCode = key($availablePrices);
}
$registration->setPrice($priceCode);
$totalPrice = $availablePrices[$priceCode] * $seats;
$registration->setTotalPrice($totalPrice);
$attendeesNames = isset($formData['attendees_names']) ? strip_tags($formData['attendees_names']) : '';
$registration->setAttendeesNames($attendeesNames);
$kids = isset($formData['kids']) ? max(0, (int)$formData['kids']) : 0;
$registration->setKids($kids);
$paymentMethod = NULL;
if ($totalPrice > 0) {
$availablePaymentMethods = $event->getPaymentMethods();
if (!$availablePaymentMethods->isEmpty()) {
if ($availablePaymentMethods->count() == 1) {
$paymentMethod = $availablePaymentMethods->first();
} else {
$paymentMethodUid = isset($formData['method_of_payment'])
? max(0, (int)$formData['method_of_payment']) : 0;
if (($paymentMethodUid > 0) && $availablePaymentMethods->hasUid($paymentMethodUid)) {
/** @var tx_seminars_Mapper_PaymentMethod $mapper */
$mapper = tx_oelib_MapperRegistry::get('tx_seminars_Mapper_PaymentMethod');
/** @var tx_seminars_Model_PaymentMethod $paymentMethod */
$paymentMethod = $mapper->find($paymentMethodUid);
}
}
}
}
$registration->setPaymentMethod($paymentMethod);
$accountNumber = isset($formData['account_number'])
? strip_tags($this->unifyWhitespace($formData['account_number'])) : '';
$registration->setAccountNumber($accountNumber);
$bankCode = isset($formData['bank_code']) ? strip_tags($this->unifyWhitespace($formData['bank_code'])) : '';
$registration->setBankCode($bankCode);
$bankName = isset($formData['bank_name']) ? strip_tags($this->unifyWhitespace($formData['bank_name'])) : '';
$registration->setBankName($bankName);
$accountOwner = isset($formData['account_owner']) ? strip_tags($this->unifyWhitespace($formData['account_owner'])) : '';
$registration->setAccountOwner($accountOwner);
$company = isset($formData['company']) ? strip_tags($formData['company']) : '';
$registration->setCompany($company);
$validGenderMale = (string) tx_oelib_Model_FrontEndUser::GENDER_MALE;
$validGenderFemale = (string) tx_oelib_Model_FrontEndUser::GENDER_FEMALE;
if (isset($formData['gender'])
&& (($formData['gender'] === $validGenderMale) || ($formData['gender'] === $validGenderFemale)
)
) {
$gender = (int)$formData['gender'];
} else {
$gender = tx_oelib_Model_FrontEndUser::GENDER_UNKNOWN;
}
$registration->setGender($gender);
$name = isset($formData['name']) ? strip_tags($this->unifyWhitespace($formData['name'])) : '';
$registration->setName($name);
$address = isset($formData['address']) ? strip_tags($formData['address']) : '';
$registration->setAddress($address);
$zip = isset($formData['zip']) ? strip_tags($this->unifyWhitespace($formData['zip'])) : '';
$registration->setZip($zip);
$city = isset($formData['city']) ? strip_tags($this->unifyWhitespace($formData['city'])) : '';
$registration->setCity($city);
$country = isset($formData['country']) ? strip_tags($this->unifyWhitespace($formData['country'])) : '';
$registration->setCountry($country);
}
/**
* Replaces all non-space whitespace in $rawString with single regular spaces.
*
* @param string $rawString the string to unify, may be empty
*
* @return string $rawString with all whitespace changed to regular spaces
*/
private function unifyWhitespace($rawString) {
return preg_replace('/[\r\n\t ]+/', ' ', $rawString);
}
/**
* Removes the given registration (if it exists and if it belongs to the
* currently logged-in FE user).
*
* @param int $uid the UID of the registration that should be removed
* @param tslib_pibase $plugin a live plugin object
*
* @return void
*/
public function removeRegistration($uid, tslib_pibase $plugin) {
if (!tx_seminars_OldModel_Abstract::recordExists($uid, 'tx_seminars_attendances')) {
return;
}
$this->registration = t3lib_div::makeInstance(
'tx_seminars_registration',
$plugin->cObj,
tx_oelib_db::select(
'*', 'tx_seminars_attendances', 'uid = ' . $uid . tx_oelib_db::enableFields('tx_seminars_attendances')
)
);
if ($this->registration->getUser() !== $this->getFeUserUid()) {
return;
}
/** @var $user tx_seminars_Model_FrontEndUser */
$user = tx_oelib_FrontEndLoginManager::getInstance()->getLoggedInUser('tx_seminars_Mapper_FrontEndUser');
foreach ($this->getHooks() as $hook) {
if (method_exists($hook, 'seminarRegistrationRemoved')) {
$hook->seminarRegistrationRemoved($this->registration, $user);
}
}
tx_oelib_db::update(
'tx_seminars_attendances',
'uid = ' . $uid,
array('hidden' => 1, 'tstamp' => $GLOBALS['SIM_EXEC_TIME'])
);
$this->notifyAttendee($this->registration, $plugin, 'confirmationOnUnregistration');
$this->notifyOrganizers($this->registration, 'notificationOnUnregistration');
$this->fillVacancies($plugin);
}
/**
* Fills vacancies created through a unregistration with attendees from the registration queue.
*
* @param tslib_pibase $plugin live plugin object
*
* @return void
*/
private function fillVacancies(tslib_pibase $plugin) {
$seminar = $this->registration->getSeminarObject();
$seminar->calculateStatistics();
if (!$seminar->hasVacancies()) {
return;
}
$vacancies = $seminar->getVacancies();
/** @var tx_seminars_BagBuilder_Registration $registrationBagBuilder */
$registrationBagBuilder = t3lib_div::makeInstance('tx_seminars_BagBuilder_Registration');
$registrationBagBuilder->limitToEvent($seminar->getUid());
$registrationBagBuilder->limitToOnQueue();
$registrationBagBuilder->limitToSeatsAtMost($vacancies);
$bag = $registrationBagBuilder->build();
/** @var tx_seminars_registration $registration */
foreach ($bag as $registration) {
if ($vacancies <= 0) {
break;
}
if ($registration->getSeats() <= $vacancies) {
tx_oelib_db::update(
'tx_seminars_attendances', 'uid = ' . $registration->getUid(), array('registration_queue' => 0)
);
$vacancies -= $registration->getSeats();
$user = $registration->getFrontEndUser();
foreach ($this->getHooks() as $hook) {
if (method_exists($hook, 'seminarRegistrationMovedFromQueue')) {
$hook->seminarRegistrationMovedFromQueue($registration, $user);
}
}
$this->notifyAttendee($registration, $plugin, 'confirmationOnQueueUpdate');
$this->notifyOrganizers($registration, 'notificationOnQueueUpdate');
if ($this->getConfValueBoolean('sendAdditionalNotificationEmails')) {
$this->sendAdditionalNotification($registration);
}
}
}
}
/**
* Checks if the logged-in user fulfills all requirements for registration for the event $event.
*
* A front-end user needs to be logged in when this function is called.
*
* @param tx_seminars_seminar $event the event to check
*
* @return bool TRUE if the user fulfills all requirements, FALSE otherwise
*/
public function userFulfillsRequirements(tx_seminars_seminar $event) {
if (!$event->hasRequirements()) {
return TRUE;
}
$missingTopics = $this->getMissingRequiredTopics($event);
$result = $missingTopics->isEmpty();
return $result;
}
/**
* Returns the event topics the user still needs to register for in order to be able to register for $event.
*
* @param tx_seminars_seminar $event the event to check
*
* @return tx_seminars_Bag_Event the event topics which still need the user's registration, may be empty
*/
public function getMissingRequiredTopics(tx_seminars_seminar $event) {
/** @var tx_seminars_BagBuilder_Event $builder */
$builder = t3lib_div::makeInstance('tx_seminars_BagBuilder_Event');
$builder->limitToRequiredEventTopics($event->getTopicUid());
$builder->limitToTopicsWithoutRegistrationByUser($this->getFeUserUid());
return $builder->build();
}
/**
* Sends an e-mail to the attendee with a message concerning his/her registration or unregistration.
*
* @param tx_seminars_registration $oldRegistration the registration for which the notification should be sent
* @param tslib_pibase $plugin a live plugin
* @param string $helloSubjectPrefix
* prefix for the locallang key of the localized hello and subject
* string; allowed values are:
* - confirmation
* - confirmationOnUnregistration
* - confirmationOnRegistrationForQueue
* - confirmationOnQueueUpdate
* In the following the parameter is prefixed with "email_" and
* postfixed with "Hello" or "Subject".
*
* @return void
*/
public function notifyAttendee(
tx_seminars_registration $oldRegistration, tslib_pibase $plugin, $helloSubjectPrefix = 'confirmation'
) {
if (!$this->getConfValueBoolean('send' . ucfirst($helloSubjectPrefix))) {
return;
}
/** @var $event tx_seminars_seminar */
$event = $oldRegistration->getSeminarObject();
if (!$event->hasOrganizers()) {
return;
}
if (!$oldRegistration->hasExistingFrontEndUser()) {
return;
}
if (!$oldRegistration->getFrontEndUser()->hasEMailAddress()) {
return;
}
/** @var $eMailNotification tx_oelib_Mail */
$eMailNotification = t3lib_div::makeInstance('tx_oelib_Mail');
$eMailNotification->addRecipient($oldRegistration->getFrontEndUser());
$eMailNotification->setSender($event->getFirstOrganizer());
$eMailNotification->setSubject(
$this->translate('email_' . $helloSubjectPrefix . 'Subject') . ': ' . $event->getTitleAndDate('-')
);
$this->initializeTemplate();
$mailFormat = tx_oelib_configurationProxy::getInstance('seminars')->getAsInteger('eMailFormatForAttendees');
if (($mailFormat == self::SEND_HTML_MAIL)
|| (($mailFormat == self::SEND_USER_MAIL) && $oldRegistration->getFrontEndUser()->wantsHtmlEMail())
) {
$eMailNotification->setCssFile($this->getConfValueString('cssFileForAttendeeMail'));
$eMailNotification->setHTMLMessage($this->buildEmailContent($oldRegistration, $plugin, $helloSubjectPrefix, TRUE));
}
$eMailNotification->setMessage($this->buildEmailContent($oldRegistration, $plugin, $helloSubjectPrefix));
/** @var tx_seminars_Mapper_Registration $mapper */
$mapper = tx_oelib_MapperRegistry::get('tx_seminars_Mapper_Registration');
/** @var $registration tx_seminars_Model_Registration */
$registration = $mapper->find($oldRegistration->getUid());
foreach ($this->getHooks() as $hook) {
if (method_exists($hook, 'modifyThankYouEmail')) {
$hook->modifyThankYouEmail($eMailNotification, $registration);
}
}
/** @var Tx_Oelib_MailerFactory $mailerFactory */
$mailerFactory = t3lib_div::makeInstance('Tx_Oelib_MailerFactory');
$mailerFactory->getMailer()->send($eMailNotification);
}
/**
* Sends an e-mail to all organizers with a message about a registration or unregistration.
*
* @param tx_seminars_registration $registration
* the registration for which the notification should be send
* @param string $helloSubjectPrefix
* prefix for the locallang key of the localized hello and subject string, Allowed values are:
* - notification
* - notificationOnUnregistration
* - notificationOnRegistrationForQueue
* - notificationOnQueueUpdate
* In the following, the parameter is prefixed with "email_" and postfixed with "Hello" or "Subject".
*
* @return void
*/
public function notifyOrganizers(tx_seminars_registration $registration, $helloSubjectPrefix = 'notification') {
if (!$this->getConfValueBoolean('send' . ucfirst($helloSubjectPrefix))) {
return;
}
if (!$registration->hasExistingFrontEndUser()) {
return;
}
$event = $registration->getSeminarObject();
if (!$event->hasOrganizers()) {
return;
}
$organizers = $event->getOrganizerBag();
/** @var $eMailNotification tx_oelib_Mail */
$eMailNotification = t3lib_div::makeInstance('tx_oelib_Mail');
$eMailNotification->setSender($event->getFirstOrganizer());
/** @var tx_seminars_OldModel_Organizer $organizer */
foreach ($organizers as $organizer) {
$eMailNotification->addRecipient($organizer);
}
$eMailNotification->setSubject(
$this->translate('email_' . $helloSubjectPrefix . 'Subject') . ': ' . $registration->getTitle()
);
$this->initializeTemplate();
$this->hideSubparts($this->getConfValueString('hideFieldsInNotificationMail'), 'field_wrapper');
$this->setMarker('hello', $this->translate('email_' . $helloSubjectPrefix . 'Hello'));
$this->setMarker('summary', $registration->getTitle());
if ($this->hasConfValueString('showSeminarFieldsInNotificationMail')) {
$this->setMarker(
'seminardata', $event->dumpSeminarValues($this->getConfValueString('showSeminarFieldsInNotificationMail'))
);
} else {
$this->hideSubparts('seminardata', 'field_wrapper');
}
if ($this->hasConfValueString('showFeUserFieldsInNotificationMail')) {
$this->setMarker(
'feuserdata', $registration->dumpUserValues($this->getConfValueString('showFeUserFieldsInNotificationMail'))
);
} else {
$this->hideSubparts('feuserdata', 'field_wrapper');
}
if ($this->hasConfValueString('showAttendanceFieldsInNotificationMail')) {
$this->setMarker(
'attendancedata',
$registration->dumpAttendanceValues($this->getConfValueString('showAttendanceFieldsInNotificationMail'))
);
} else {
$this->hideSubparts('attendancedata', 'field_wrapper');
}
$this->callModifyOrganizerNotificationEmailHooks($registration, $this->getTemplate());
$eMailNotification->setMessage($this->getSubpart('MAIL_NOTIFICATION'));
$this->modifyNotificationEmail($eMailNotification, $registration);
/** @var Tx_Oelib_MailerFactory $mailerFactory */
$mailerFactory = t3lib_div::makeInstance('Tx_Oelib_MailerFactory');
$mailerFactory->getMailer()->send($eMailNotification);
}
/**
* Calls the modifyOrganizerNotificationEmail hooks.
*
* @param tx_seminars_registration $registration
* @param Tx_Oelib_Template $emailTemplate
*
* @return void
*/
protected function callModifyOrganizerNotificationEmailHooks(
tx_seminars_registration $registration, Tx_Oelib_Template $emailTemplate
) {
foreach ($this->getHooks() as $hook) {
if ($hook instanceof tx_seminars_Interface_Hook_Registration) {
/** @var $hook tx_seminars_Interface_Hook_Registration */
$hook->modifyOrganizerNotificationEmail($registration, $emailTemplate);
}
}
}
/**
* Modifies the notification e-mail.
*
* This method is intended to be overridden in XClasses if needed.
*
* @param tx_oelib_Mail $emailNotification
* @param tx_seminars_registration $registration
*
* @return void
*/
protected function modifyNotificationEmail(tx_oelib_Mail $emailNotification, tx_seminars_registration $registration) {
}
/**
* Calls the modifyAttendeeEmailText hooks.
*
* @param tx_seminars_registration $registration
* @param Tx_Oelib_Template $emailTemplate
*
* @return void
*/
protected function callModifyAttendeeEmailTextHooks(tx_seminars_registration $registration, Tx_Oelib_Template $emailTemplate) {
foreach ($this->getHooks() as $hook) {
if ($hook instanceof tx_seminars_Interface_Hook_Registration) {
/** @var $hook tx_seminars_Interface_Hook_Registration */
$hook->modifyAttendeeEmailText($registration, $emailTemplate);
}
}
}
/**
* Checks if additional notifications to the organizers are necessary.
* In that case, the notification e-mails will be sent to all organizers.
*
* Additional notifications mails will be sent out upon the following events:
* - an event now has enough registrations
* - an event is fully booked
* If both things happen at the same time (minimum and maximum count of
* attendees are the same), only the "event is full" message will be sent.
*
* @param tx_seminars_registration $registration the registration for which the notification should be send
*
* @return void
*/
public function sendAdditionalNotification(
tx_seminars_registration $registration
) {
if ($registration->isOnRegistrationQueue()) {
return;
}
$emailReason = $this->getReasonForNotification($registration);
if ($emailReason == '') {
return;
}
$event = $registration->getSeminarObject();
/** @var $eMail tx_oelib_Mail */
$eMail = t3lib_div::makeInstance('tx_oelib_Mail');
$eMail->setSender($event->getFirstOrganizer());