Completed
Pull Request — master (#149)
by
unknown
03:33
created

MembershipApplication::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Entities;
6
7
use Doctrine\ORM\Mapping as ORM;
8
use Gedmo\Mapping\Annotation as Gedmo;
9
use WMDE\Fundraising\Store\MembershipApplicationData;
10
11
/**
12
 * @since 2.0
13
 *
14
 * @ORM\Table(
15
 *     name="request",
16
 *     indexes={
17
 *			@ORM\Index(name="m_email", columns={"email"}, flags={"fulltext"}),
18
 *          @ORM\Index(name="m_name", columns={"name"}, flags={"fulltext"}),
19
 *     		@ORM\Index(name="m_ort", columns={"ort"}, flags={"fulltext"})
20
 *     }
21
 *	 )
22
 * @ORM\Entity
23
 */
24
class MembershipApplication {
25
26
	public const STATUS_CONFIRMED = 1;
27
	public const STATUS_NEUTRAL = 0;
28
	public const STATUS_DELETED = -1;
29
	public const STATUS_MODERATION = -2;
30
	public const STATUS_ABORTED = -4;
31
	public const STATUS_CANCELED = -8;
32
33
	/**
34
	 * @var integer
35
	 *
36
	 * @ORM\Column(name="id", type="integer")
37
	 * @ORM\Id
38
	 * @ORM\GeneratedValue(strategy="IDENTITY")
39
	 */
40
	private $id;
41
42
	/**
43
	 * FIXME: this should not be nullable
44
	 *
45
	 * @var integer
46
	 *
47
	 * @ORM\Column(name="status", type="smallint", options={"default":0}, nullable=true)
48
	 */
49
	private $status = 0;
50
51
	/**
52
	 * This is no longer written by the fundraising frontend.
53
	 *
54
	 * Until we remove all references to this field in the backend, the field is not removed but just marked as deprecated.
55
	 *
56
	 * @deprecated
57
	 * @var integer|null
58
	 *
59
	 * @ORM\Column(name="donation_id", type="integer", nullable=true)
60
	 */
61
	private $donationId;
62
63
	/**
64
	 * @var \DateTime
65
	 *
66
	 * @Gedmo\Timestampable(on="create")
67
	 * @ORM\Column(name="timestamp", type="datetime")
68
	 */
69
	private $creationTime;
70
71
	/**
72
	 * @var string|null
73
	 *
74
	 * @ORM\Column(name="anrede", type="string", length=16, nullable=true)
75
	 */
76
	private $applicantSalutation;
77
78
	/**
79
	 * @var string|null
80
	 *
81
	 * @ORM\Column(name="firma", type="string", length=100, nullable=true)
82
	 */
83
	private $company;
84
85
	/**
86
	 * @var string|null
87
	 *
88
	 * @ORM\Column(name="titel", type="string", length=16, nullable=true)
89
	 */
90
	private $applicantTitle;
91
92
	/**
93
	 * @var string
94
	 *
95
	 * @ORM\Column(name="name", type="string", length=250, options={"default":""}, nullable=false)
96
	 */
97
	private $probablyUnusedNameField = '';
98
99
	/**
100
	 * @var string
101
	 *
102
	 * @ORM\Column(name="vorname", type="string", length=50, options={"default":""}, nullable=false)
103
	 */
104
	private $applicantFirstName = '';
105
106
	/**
107
	 * @var string
108
	 *
109
	 * @ORM\Column(name="nachname", type="string", length=50, options={"default":""}, nullable=false)
110
	 */
111
	private $applicantLastName = '';
112
113
	/**
114
	 * @var string|null
115
	 *
116
	 * @ORM\Column(name="strasse", type="string", length=100, nullable=true)
117
	 */
118
	private $address;
119
120
	/**
121
	 * @var string|null
122
	 *
123
	 * @ORM\Column(name="plz", type="string", length=8, nullable=true)
124
	 */
125
	private $postcode;
126
127
	/**
128
	 * @var string|null
129
	 *
130
	 * @ORM\Column(name="ort", type="string", length=100, nullable=true)
131
	 */
132
	private $city;
133
134
	/**
135
	 * @var string|null
136
	 *
137
	 * @ORM\Column(name="country", type="string", length=8, options={"default":""}, nullable=true)
138
	 */
139
	private $country = '';
140
141
	/**
142
	 * @var string
143
	 *
144
	 * @ORM\Column(name="email", type="string", length=250, options={"default":""}, nullable=false)
145
	 */
146
	private $applicantEmailAddress = '';
147
148
	/**
149
	 * @var string
150
	 *
151
	 * @ORM\Column(name="phone", type="string", length=30, options={"default":""}, nullable=false)
152
	 */
153
	private $applicantPhoneNumber = '';
154
155
	/**
156
	 * Date of birth
157
	 *
158
	 * @var \DateTime|null
159
	 *
160
	 * @ORM\Column(name="dob", type="date", nullable=true)
161
	 */
162
	private $applicantDateOfBirth;
163
164
	/**
165
	 * @var string
166
	 *
167
	 * @ORM\Column(name="wikimedium_shipping", type="string", options={"default":""}, nullable=false)
168
	 */
169
	private $wikimediumShipping = 'none';
170
171
	/**
172
	 * @var string
173
	 *
174
	 * @ORM\Column(name="membership_type", type="string", options={"default":"sustaining"}, nullable=false)
175
	 */
176
	private $membershipType = 'sustaining';
177
178
	/**
179
	 * @var string
180
	 *
181
	 * @ORM\Column(name="payment_type", type="string", options={"default":"BEZ"}, nullable=false)
182
	 */
183
	private $paymentType = 'BEZ';
184
185
	/**
186
	 * @var integer
187
	 *
188
	 * @ORM\Column(name="membership_fee", type="integer", options={"default":0}, nullable=false)
189
	 */
190
	private $paymentAmountInEuro = 0;
191
192
	/**
193
	 * FIXME: this should not be nullable
194
	 *
195
	 * @var integer
196
	 *
197
	 * @ORM\Column(name="membership_fee_interval", type="smallint", options={"default":12}, nullable=true)
198
	 */
199
	private $paymentIntervalInMonths = 12;
200
201
	/**
202
	 * @var string
203
	 *
204
	 * @ORM\Column(name="account_number", type="string", length=16, options={"default":""}, nullable=false)
205
	 */
206
	private $paymentBankAccount = '';
207
208
	/**
209
	 * @var string
210
	 *
211
	 * @ORM\Column(name="bank_name", type="string", length=100, options={"default":""}, nullable=false)
212
	 */
213
	private $paymentBankName = '';
214
215
	/**
216
	 * @var string
217
	 *
218
	 * @ORM\Column(name="bank_code", type="string", length=16, options={"default":""}, nullable=false)
219
	 */
220
	private $paymentBankCode = '';
221
222
	/**
223
	 * @var string|null
224
	 *
225
	 * @ORM\Column(name="iban", type="string", length=32, options={"default":""}, nullable=true)
226
	 */
227
	private $paymentIban = '';
228
229
	/**
230
	 * @var string|null
231
	 *
232
	 * @ORM\Column(name="bic", type="string", length=32, options={"default":""}, nullable=true)
233
	 */
234
	private $paymentBic = '';
235
236
	/**
237
	 * @var string
238
	 *
239
	 * @ORM\Column(name="account_holder", type="string", length=50, options={"default":""}, nullable=false)
240
	 */
241
	private $paymentBankAccountHolder = '';
242
243
	/**
244
	 * @var string
245
	 *
246
	 * @ORM\Column(name="comment", type="text", options={"default":""}, nullable=false)
247
	 */
248
	private $comment = '';
249
250
	/**
251
	 * @var \DateTime|null
252
	 *
253
	 * @ORM\Column(name="export", type="datetime", nullable=true)
254
	 */
255
	private $export;
256
257
	/**
258
	 * @var \DateTime|null
259
	 *
260
	 * @ORM\Column(name="backup", type="datetime", nullable=true)
261
	 */
262
	private $backup;
263
264
	/**
265
	 * @var boolean
266
	 *
267
	 * @ORM\Column(name="wikilogin", type="boolean", options={"default":0}, nullable=false)
268
	 */
269
	private $wikilogin = 0;
270
271
	/**
272
	 * @var string|null
273
	 *
274
	 * @ORM\Column(name="tracking", type="string", length=50, nullable=true)
275
	 */
276
	private $tracking;
277
278
	/**
279
	 * @var string|null
280
	 *
281
	 * @ORM\Column(name="data", type="text", nullable=true)
282
	 */
283
	private $data;
284
285
	/**
286
	 * @var boolean|null
287
	 *
288
	 * @ORM\Column(name="donation_receipt", type="boolean", nullable=true)
289
	 */
290
	private $donationReceipt;
291
292
	/**
293
	 * @ORM\OneToOne(targetEntity="AddressChange", cascade={"all"}, fetch="EAGER")
294
	 */
295
	private $addressChange;
296
297
	/**
298
	 * Donation constructor creates a new AddressChange entity unless one is supplied by Doctrine
299
	 */
300 20
	public function __construct() {
301 20
		$this->addressChange = new AddressChange();
302 20
	}
303
304
	/**
305
	 * @return integer
306
	 */
307 3
	public function getId() {
308 3
		return $this->id;
309
	}
310
311
	/**
312
	 * @since 2.0
313
	 *
314
	 * @param integer|null $id
315
	 */
316 2
	public function setId( $id ) {
317 2
		$this->id = $id;
318 2
	}
319
320
	/**
321
	 * @param integer|null $donationId
322
	 *
323
	 * @return self
324
	 */
325
	public function setDonationId( $donationId ) {
326
		$this->donationId = $donationId;
0 ignored issues
show
Deprecated Code introduced by
The property WMDE\Fundraising\Entitie...pplication::$donationId has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
327
328
		return $this;
329
	}
330
331
	/**
332
	 * Returns the id of the donation that led to the membership application,
333
	 * or null when the application is not linked to any donation.
334
	 *
335
	 * @return integer|null
336
	 */
337
	public function getDonationId() {
338
		return $this->donationId;
0 ignored issues
show
Deprecated Code introduced by
The property WMDE\Fundraising\Entitie...pplication::$donationId has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
339
	}
340
341
	/**
342
	 * @param \DateTime|null $creationTime
343
	 *
344
	 * @return self
345
	 */
346
	public function setCreationTime( $creationTime ) {
347
		$this->creationTime = $creationTime;
348
349
		return $this;
350
	}
351
352
	/**
353
	 * @return \DateTime|null
354
	 */
355
	public function getCreationTime() {
356
		return $this->creationTime;
357
	}
358
359
	/**
360
	 * @param string|null $applicantSalutation
361
	 *
362
	 * @return self
363
	 */
364
	public function setApplicantSalutation( $applicantSalutation ) {
365
		$this->applicantSalutation = $applicantSalutation;
366
367
		return $this;
368
	}
369
370
	/**
371
	 * @return string|null
372
	 */
373
	public function getApplicantSalutation() {
374
		return $this->applicantSalutation;
375
	}
376
377
	/**
378
	 * @param string|null $company
379
	 *
380
	 * @return self
381
	 */
382
	public function setCompany( $company ) {
383
		$this->company = $company;
384
385
		return $this;
386
	}
387
388
	/**
389
	 * @return string|null
390
	 */
391
	public function getCompany() {
392
		return $this->company;
393
	}
394
395
	/**
396
	 * @param string $applicantTitle
397
	 *
398
	 * @return self
399
	 */
400
	public function setApplicantTitle( $applicantTitle ) {
401
		$this->applicantTitle = $applicantTitle;
402
403
		return $this;
404
	}
405
406
	/**
407
	 * @return string
408
	 */
409
	public function getApplicantTitle() {
410
		return $this->applicantTitle;
411
	}
412
413
	/**
414
	 * @param string $probablyUnusedNameField
415
	 *
416
	 * @return self
417
	 */
418
	public function setProbablyUnusedNameField( $probablyUnusedNameField ) {
419
		$this->probablyUnusedNameField = $probablyUnusedNameField;
420
421
		return $this;
422
	}
423
424
	/**
425
	 * @return string
426
	 */
427
	public function getProbablyUnusedNameField() {
428
		return $this->probablyUnusedNameField;
429
	}
430
431
	/**
432
	 * @param string $applicantFirstName
433
	 *
434
	 * @return self
435
	 */
436
	public function setApplicantFirstName( $applicantFirstName ) {
437
		$this->applicantFirstName = $applicantFirstName;
438
		$this->setNameFromParts( $applicantFirstName, $this->getApplicantLastName() );
439
440
		return $this;
441
	}
442
443
	/**
444
	 * @return string
445
	 */
446
	public function getApplicantFirstName() {
447
		return $this->applicantFirstName;
448
	}
449
450
	/**
451
	 * @param string $applicantLastName
452
	 *
453
	 * @return self
454
	 */
455
	public function setApplicantLastName( $applicantLastName ) {
456
		$this->applicantLastName = $applicantLastName;
457
		$this->setNameFromParts( $this->getApplicantFirstName(), $applicantLastName );
458
459
		return $this;
460
	}
461
462
	/**
463
	 * @return string
464
	 */
465
	public function getApplicantLastName() {
466
		return $this->applicantLastName;
467
	}
468
469
	/**
470
	 * Sets the full name
471
	 *
472
	 * @param string|null $firstName
473
	 * @param string|null $lastName
474
	 *
475
	 * @return self
476
	 */
477
	private function setNameFromParts( $firstName, $lastName ) {
478
		$this->setProbablyUnusedNameField( implode(
479
			' ',
480
			array_filter( [ $firstName, $lastName ] )
481
		) );
482
483
		return $this;
484
	}
485
486
	/**
487
	 * Set address (street, etc)
488
	 *
489
	 * @param string|null $address
490
	 *
491
	 * @return self
492
	 */
493
	public function setAddress( $address ) {
494
		$this->address = $address;
495
496
		return $this;
497
	}
498
499
	/**
500
	 * Get address (street, etc)
501
	 *
502
	 * @return string|null
503
	 */
504
	public function getAddress() {
505
		return $this->address;
506
	}
507
508
	/**
509
	 * @param string|null $postcode
510
	 *
511
	 * @return self
512
	 */
513
	public function setPostcode( $postcode ) {
514
		$this->postcode = $postcode;
515
516
		return $this;
517
	}
518
519
	/**
520
	 * @return string|null
521
	 */
522
	public function getPostcode() {
523
		return $this->postcode;
524
	}
525
526
	/**
527
	 * @param string|null $city
528
	 *
529
	 * @return self
530
	 */
531
	public function setCity( $city ) {
532
		$this->city = $city;
533
534
		return $this;
535
	}
536
537
	/**
538
	 * @return string|null
539
	 */
540
	public function getCity() {
541
		return $this->city;
542
	}
543
544
	/**
545
	 * Set email
546
	 *
547
	 * @param string $applicantEmailAddress
548
	 *
549
	 * @return self
550
	 */
551
	public function setApplicantEmailAddress( $applicantEmailAddress ) {
552
		$this->applicantEmailAddress = $applicantEmailAddress;
553
554
		return $this;
555
	}
556
557
	/**
558
	 * Get email
559
	 *
560
	 * @return string
561
	 */
562
	public function getApplicantEmailAddress() {
563
		return $this->applicantEmailAddress;
564
	}
565
566
	/**
567
	 * Set phone
568
	 *
569
	 * @param string $applicantPhoneNumber
570
	 *
571
	 * @return self
572
	 */
573
	public function setApplicantPhoneNumber( $applicantPhoneNumber ) {
574
		$this->applicantPhoneNumber = $applicantPhoneNumber;
575
576
		return $this;
577
	}
578
579
	/**
580
	 * Get phone
581
	 *
582
	 * @return string
583
	 */
584
	public function getApplicantPhoneNumber() {
585
		return $this->applicantPhoneNumber;
586
	}
587
588
	/**
589
	 * @param \DateTime|null $dateOfBirth
590
	 *
591
	 * @return self
592
	 */
593
	public function setApplicantDateOfBirth( $dateOfBirth ) {
594
		$this->applicantDateOfBirth = $dateOfBirth;
595
596
		return $this;
597
	}
598
599
	/**
600
	 * @return \DateTime|null
601
	 */
602
	public function getApplicantDateOfBirth() {
603
		return $this->applicantDateOfBirth;
604
	}
605
606
	/**
607
	 * @param string $wikimediumShipping
608
	 *
609
	 * @return self
610
	 */
611
	public function setWikimediumShipping( $wikimediumShipping ) {
612
		$this->wikimediumShipping = $wikimediumShipping;
613
614
		return $this;
615
	}
616
617
	/**
618
	 * @return string
619
	 */
620
	public function getWikimediumShipping() {
621
		return $this->wikimediumShipping;
622
	}
623
624
	/**
625
	 * @param string $membershipType
626
	 *
627
	 * @return self
628
	 */
629
	public function setMembershipType( $membershipType ) {
630
		$this->membershipType = $membershipType;
631
632
		return $this;
633
	}
634
635
	/**
636
	 * @return string
637
	 */
638
	public function getMembershipType() {
639
		return $this->membershipType;
640
	}
641
642
	/**
643
	 * @since 2.1
644
	 *
645
	 * @param string $paymentType
646
	 *
647
	 * @return self
648
	 */
649
	public function setPaymentType( $paymentType ) {
650
		$this->paymentType = $paymentType;
651
652
		return $this;
653
	}
654
655
	/**
656
	 * @since 2.1
657
	 *
658
	 * @return string
659
	 */
660
	public function getPaymentType() {
661
		return $this->paymentType;
662
	}
663
664
	/**
665
	 * @param integer $paymentAmountInEuro
666
	 *
667
	 * @return self
668
	 */
669
	public function setPaymentAmount( $paymentAmountInEuro ) {
670
		$this->paymentAmountInEuro = $paymentAmountInEuro;
671
672
		return $this;
673
	}
674
675
	/**
676
	 * @return integer
677
	 */
678
	public function getPaymentAmount() {
679
		return $this->paymentAmountInEuro;
680
	}
681
682
	/**
683
	 * @param integer $paymentIntervalInMonths
684
	 *
685
	 * @return self
686
	 */
687
	public function setPaymentIntervalInMonths($paymentIntervalInMonths) {
688
		$this->paymentIntervalInMonths = $paymentIntervalInMonths;
689
690
		return $this;
691
	}
692
693
	/**
694
	 * @return integer
695
	 */
696
	public function getPaymentIntervalInMonths() {
697
		return $this->paymentIntervalInMonths;
698
	}
699
700
701
	/**
702
	 * @param string $paymentBankAccount
703
	 *
704
	 * @return self
705
	 */
706
	public function setPaymentBankAccount( $paymentBankAccount ) {
707
		$this->paymentBankAccount = $paymentBankAccount;
708
709
		return $this;
710
	}
711
712
	/**
713
	 * @return string
714
	 */
715
	public function getPaymentBankAccount() {
716
		return $this->paymentBankAccount;
717
	}
718
719
	/**
720
	 * @param string $paymentBankName
721
	 *
722
	 * @return self
723
	 */
724
	public function setPaymentBankName( $paymentBankName ) {
725
		$this->paymentBankName = $paymentBankName;
726
727
		return $this;
728
	}
729
730
	/**
731
	 * @return string
732
	 */
733
	public function getPaymentBankName() {
734
		return $this->paymentBankName;
735
	}
736
737
	/**
738
	 * @param string $paymentBankCode
739
	 *
740
	 * @return self
741
	 */
742
	public function setPaymentBankCode( $paymentBankCode ) {
743
		$this->paymentBankCode = $paymentBankCode;
744
745
		return $this;
746
	}
747
748
	/**
749
	 * @return string
750
	 */
751
	public function getPaymentBankCode() {
752
		return $this->paymentBankCode;
753
	}
754
755
	/**
756
	 * @param string|null $paymentIban
757
	 *
758
	 * @return self
759
	 */
760
	public function setPaymentIban( $paymentIban ) {
761
		$this->paymentIban = $paymentIban;
762
763
		return $this;
764
	}
765
766
	/**
767
	 * @return string|null
768
	 */
769
	public function getPaymentIban() {
770
		return $this->paymentIban;
771
	}
772
773
	/**
774
	 * @param string|null $paymentBic
775
	 *
776
	 * @return self
777
	 */
778
	public function setPaymentBic( $paymentBic ) {
779
		$this->paymentBic = $paymentBic;
780
781
		return $this;
782
	}
783
784
	/**
785
	 * @return string|null
786
	 */
787
	public function getPaymentBic() {
788
		return $this->paymentBic;
789
	}
790
791
	/**
792
	 * @param string $paymentBankAccountHolder
793
	 *
794
	 * @return self
795
	 */
796
	public function setPaymentBankAccountHolder( $paymentBankAccountHolder ) {
797
		$this->paymentBankAccountHolder = $paymentBankAccountHolder;
798
799
		return $this;
800
	}
801
802
	/**
803
	 * @return string
804
	 */
805
	public function getPaymentBankAccountHolder() {
806
		return $this->paymentBankAccountHolder;
807
	}
808
809
	/**
810
	 * @param string $comment
811
	 *
812
	 * @return self
813
	 */
814
	public function setComment( $comment ) {
815
		$this->comment = $comment;
816
817
		return $this;
818
	}
819
820
	/**
821
	 * @return string
822
	 */
823
	public function getComment() {
824
		return $this->comment;
825
	}
826
827
	/**
828
	 * Sets the time of export.
829
	 *
830
	 * @param \DateTime|null $export
831
	 *
832
	 * @return self
833
	 */
834
	public function setExport( $export ) {
835
		$this->export = $export;
836
837
		return $this;
838
	}
839
840
	/**
841
	 * Returns the time of export.
842
	 *
843
	 * @return \DateTime|null
844
	 */
845
	public function getExport() {
846
		return $this->export;
847
	}
848
849
	/**
850
	 * Sets the time of backup.
851
	 *
852
	 * @param \DateTime|null $backup
853
	 *
854
	 * @return self
855
	 */
856
	public function setBackup( $backup ) {
857
		$this->backup = $backup;
858
859
		return $this;
860
	}
861
862
	/**
863
	 * Returns the time of backup.
864
	 *
865
	 * @return \DateTime|null
866
	 */
867
	public function getBackup() {
868
		return $this->backup;
869
	}
870
871
	/**
872
	 * @param boolean $wikilogin
873
	 *
874
	 * @return self
875
	 */
876
	public function setWikilogin( $wikilogin ) {
877
		$this->wikilogin = $wikilogin;
878
879
		return $this;
880
	}
881
882
	/**
883
	 * @return boolean
884
	 */
885
	public function getWikilogin() {
886
		return $this->wikilogin;
887
	}
888
889
	/**
890
	 * @param string|null $tracking
891
	 *
892
	 * @return self
893
	 */
894
	public function setTracking( $tracking ) {
895
		$this->tracking = $tracking;
896
897
		return $this;
898
	}
899
900
	/**
901
	 * @return string|null
902
	 */
903
	public function getTracking() {
904
		return $this->tracking;
905
	}
906
907
	/**
908
	 * Sets the status of the membership request.
909
	 * The allowed values are the STATUS_ constants in this class.
910
	 *
911
	 * @param integer $status
912
	 *
913
	 * @return self
914
	 */
915 6
	public function setStatus( $status ) {
916 6
		$this->status = $status;
917
918 6
		return $this;
919
	}
920
921
	/**
922
	 * Returns the status of the membership request.
923
	 * The possible values are the STATUS_ constants in this class.
924
	 *
925
	 * @return integer
926
	 */
927
	public function getStatus() {
928
		return $this->status;
929
	}
930
931
	/**
932
	 * @param string|null $country
933
	 *
934
	 * @return self
935
	 */
936
	public function setCountry( $country ) {
937
		$this->country = $country;
938
939
		return $this;
940
	}
941
942
	/**
943
	 * @return string|null
944
	 */
945
	public function getCountry() {
946
		return $this->country;
947
	}
948
949
	/**
950
	 * @param string|null $data
951
	 * @return self
952
	 */
953
	public function setData( $data ) {
954
		$this->data = $data;
955
956
		return $this;
957
	}
958
959
	/**
960
	 * @return string|null
961
	 */
962
	public function getData() {
963
		return $this->data;
964
	}
965
966
	/**
967
	 * @return bool
968
	 */
969
	public function isUnconfirmed() {
970
		return $this->status === self::STATUS_NEUTRAL;
971
	}
972
973
	/**
974
	 * @return bool
975
	 */
976 3
	public function needsModeration() {
977 3
		return $this->status < 0 && abs( $this->status ) & abs( self::STATUS_MODERATION );
978
	}
979
980
	/**
981
	 * @return bool
982
	 */
983 4
	public function isCancelled() {
984 4
		return $this->status < 0 && abs( $this->status ) & abs( self::STATUS_CANCELED );
985
	}
986
987
	/**
988
	 * @since 4.2
989
	 * @return bool
990
	 */
991 2
	public function isDeleted() {
992 2
		return $this->status < 0 && abs( $this->status ) & abs( self::STATUS_DELETED );
993
	}
994
995
	public function log( $message ) {
996
		$dataArray = $this->getDecodedData();
997
		$dataArray['log'][date( 'Y-m-d H:i:s' )] = $message;
998
		$this->encodeAndSetData( $dataArray );
999
1000
		return $this;
1001
	}
1002
1003
	/**
1004
	 * NOTE: if possible, use @see getDataObject instead, as it provides a nicer API.
1005
	 *
1006
	 * @since 2.0
1007
	 * @return array
1008
	 */
1009 5
	public function getDecodedData() {
1010 5
		if ( $this->data === null ) {
1011 3
			return [];
1012
		}
1013
1014 4
		$data = unserialize( base64_decode( $this->data ) );
1015
1016 4
		return is_array( $data ) ? $data : [];
1017
	}
1018
1019
	/**
1020
	 * NOTE: if possible, use @see modifyDataObject instead, as it provides a nicer API.
1021
	 *
1022
	 * @since 2.0
1023
	 * @param array $dataArray
1024
	 */
1025 4
	public function encodeAndSetData( array $dataArray ) {
1026 4
		$this->data = base64_encode( serialize( $dataArray ) );
1027 4
	}
1028
1029
	/**
1030
	 * WARNING: updates made to the return value will not be reflected in the Donation state.
1031
	 * Similarly, updates to the Donation state will not propagate to the returned object.
1032
	 * To update the Donation state, explicitly call @see setDataObject.
1033
	 *
1034
	 * @since 2.0
1035
	 * @return MembershipApplicationData
1036
	 */
1037 2
	public function getDataObject() {
1038 2
		$dataArray = $this->getDecodedData();
1039
1040 2
		$data = new MembershipApplicationData();
1041
1042 2
		$data->setAccessToken( array_key_exists( 'token', $dataArray ) ? $dataArray['token'] : null );
1043 2
		$data->setUpdateToken( array_key_exists( 'utoken', $dataArray ) ? $dataArray['utoken'] : null );
1044 2
		$data->setPreservedStatus( array_key_exists( 'old_status', $dataArray ) ? $dataArray['old_status'] : null );
1045
1046 2
		return $data;
1047
	}
1048
1049
	/**
1050
	 * @since 2.0
1051
	 * @param MembershipApplicationData $data
1052
	 */
1053 4
	public function setDataObject( MembershipApplicationData $data ) {
1054 4
		$dataArray = array_merge(
1055 4
			$this->getDecodedData(),
1056
			[
1057 4
				'token' => $data->getAccessToken(),
1058 4
				'utoken' => $data->getUpdateToken(),
1059 4
				'old_status' => $data->getPreservedStatus(),
1060
			]
1061
		);
1062
1063 4
		foreach ( [ 'token', 'utoken', 'old_status' ] as $keyName ) {
1064 4
			if ( is_null( $dataArray[$keyName] ) ) {
1065 4
				unset( $dataArray[$keyName] );
1066
			}
1067
		}
1068
1069 4
		$this->encodeAndSetData( $dataArray );
1070 4
	}
1071
1072
	/**
1073
	 * @since 2.0
1074
	 * @param callable $modificationFunction Takes a modifiable MembershipApplicationData parameter
1075
	 */
1076 1
	public function modifyDataObject( callable $modificationFunction ) {
1077 1
		$dataObject = $this->getDataObject();
1078 1
		$modificationFunction( $dataObject );
1079 1
		$this->setDataObject( $dataObject );
1080 1
	}
1081
1082
	/**
1083
	 * Set donation receipt state
1084
	 *
1085
	 * @since 7.0
1086
	 *
1087
	 * @param boolean|null $donationReceipt
1088
	 * @return self
1089
	 */
1090 1
	public function setDonationReceipt( ?bool $donationReceipt ): self {
1091 1
		$this->donationReceipt = $donationReceipt;
1092
1093 1
		return $this;
1094
	}
1095
1096
	/**
1097
	 * Get donation receipt state
1098
	 *
1099
	 * @since 7.0
1100
	 *
1101
	 * @return boolean|null
1102
	 */
1103 2
	public function getDonationReceipt(): ?bool {
1104 2
		return $this->donationReceipt;
1105
	}
1106
1107
	/**
1108
	 * Get AddressChange reference
1109
	 *
1110
	 * @since 8.0
1111
	 *
1112
	 * @return AddressChange
1113
	 */
1114
	public function getAddressChange(): AddressChange {
1115
		return $this->addressChange;
1116
	}
1117
}
1118