Passed
Pull Request — master (#154)
by Gabriel
03:48
created

MembershipApplication::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

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