Passed
Pull Request — master (#149)
by
unknown
03:33 queued 01:20
created

MembershipApplication::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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