Completed
Pull Request — master (#149)
by
unknown
05:10
created

setProbablyUnusedNameField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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