Completed
Pull Request — master (#71)
by Jeroen De
04:20
created

MembershipApplication::encodeAndSetData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace WMDE\Fundraising\Entities;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Gedmo\Mapping\Annotation as Gedmo;
7
use WMDE\Fundraising\Store\MembershipApplicationData;
8
9
/**
10
 * @since 2.0
11
 *
12
 * @ORM\Table(name="request", indexes={@ORM\Index(name="idx_donation_id", columns={"donation_id"})})
13
 * @ORM\Entity
14
 */
15
class MembershipApplication {
16
17
	/**
18
	 * @var integer|null
19
	 *
20
	 * @ORM\Column(name="donation_id", type="integer", nullable=true)
21
	 */
22
	private $donationId;
23
24
	/**
25
	 * @var \DateTime
26
	 *
27
	 * @Gedmo\Timestampable(on="create")
28
	 * @ORM\Column(name="timestamp", type="datetime")
29
	 */
30
	private $timestamp;
31
32
	/**
33
	 * @var string|null
34
	 *
35
	 * @ORM\Column(name="anrede", type="string", length=16, nullable=true)
36
	 */
37
	private $salutation;
38
39
	/**
40
	 * @var string|null
41
	 *
42
	 * @ORM\Column(name="firma", type="string", length=100, nullable=true)
43
	 */
44
	private $company;
45
46
	/**
47
	 * @var string|null
48
	 *
49
	 * @ORM\Column(name="titel", type="string", length=16, nullable=true)
50
	 */
51
	private $title;
52
53
	/**
54
	 * @var string
55
	 *
56
	 * @ORM\Column(name="name", type="string", length=250, options={"default":""}, nullable=false)
57
	 */
58
	private $name = '';
59
60
	/**
61
	 * @var string
62
	 *
63
	 * @ORM\Column(name="vorname", type="string", length=50, options={"default":""}, nullable=false)
64
	 */
65
	private $firstName = '';
66
67
	/**
68
	 * @var string
69
	 *
70
	 * @ORM\Column(name="nachname", type="string", length=50, options={"default":""}, nullable=false)
71
	 */
72
	private $lastName = '';
73
74
	/**
75
	 * @var string|null
76
	 *
77
	 * @ORM\Column(name="strasse", type="string", length=100, nullable=true)
78
	 */
79
	private $address;
80
81
	/**
82
	 * @var string|null
83
	 *
84
	 * @ORM\Column(name="plz", type="string", length=8, nullable=true)
85
	 */
86
	private $postcode;
87
88
	/**
89
	 * @var string|null
90
	 *
91
	 * @ORM\Column(name="ort", type="string", length=100, nullable=true)
92
	 */
93
	private $city;
94
95
	/**
96
	 * @var string
97
	 *
98
	 * @ORM\Column(name="email", type="string", length=250, options={"default":""}, nullable=false)
99
	 */
100
	private $email = '';
101
102
	/**
103
	 * @var string
104
	 *
105
	 * @ORM\Column(name="phone", type="string", length=30, options={"default":""}, nullable=false)
106
	 */
107
	private $phone = '';
108
109
	/**
110
	 * Date of birth
111
	 *
112
	 * @var \DateTime|null
113
	 *
114
	 * @ORM\Column(name="dob", type="date", nullable=true)
115
	 */
116
	private $dateOfBirth;
117
118
	/**
119
	 * @var string
120
	 *
121
	 * @ORM\Column(name="wikimedium_shipping", type="string", options={"default":""}, nullable=false)
122
	 */
123
	private $wikimediumShipping = 'none';
124
125
	/**
126
	 * @var string
127
	 *
128
	 * @ORM\Column(name="membership_type", type="string", options={"default":"sustaining"}, nullable=false)
129
	 */
130
	private $membershipType = 'sustaining';
131
132
	/**
133
	 * @var integer
134
	 *
135
	 * @ORM\Column(name="membership_fee", type="integer", options={"default":0}, nullable=false)
136
	 */
137
	private $membershipFee = 0;
138
139
	/**
140
	 * FIXME: this should not be nullable
141
	 *
142
	 * @var integer
143
	 *
144
	 * @ORM\Column(name="membership_fee_interval", type="smallint", options={"default":12}, nullable=true)
145
	 */
146
	private $membershipFeeInterval = 12;
147
148
	/**
149
	 * @var string
150
	 *
151
	 * @ORM\Column(name="account_number", type="string", length=16, options={"default":""}, nullable=false)
152
	 */
153
	private $accountNumber = '';
154
155
	/**
156
	 * @var string
157
	 *
158
	 * @ORM\Column(name="bank_name", type="string", length=50, options={"default":""}, nullable=false)
159
	 */
160
	private $bankName = '';
161
162
	/**
163
	 * @var string
164
	 *
165
	 * @ORM\Column(name="bank_code", type="string", length=16, options={"default":""}, nullable=false)
166
	 */
167
	private $bankCode = '';
168
169
	/**
170
	 * @var string|null
171
	 *
172
	 * @ORM\Column(name="iban", type="string", length=32, options={"default":""}, nullable=true)
173
	 */
174
	private $iban = '';
175
176
	/**
177
	 * @var string|null
178
	 *
179
	 * @ORM\Column(name="bic", type="string", length=32, options={"default":""}, nullable=true)
180
	 */
181
	private $bic = '';
182
183
	/**
184
	 * @var string
185
	 *
186
	 * @ORM\Column(name="account_holder", type="string", length=50, options={"default":""}, nullable=false)
187
	 */
188
	private $accountHolder = '';
189
190
	/**
191
	 * @var string
192
	 *
193
	 * @ORM\Column(name="comment", type="text", options={"default":""}, nullable=false)
194
	 */
195
	private $comment = '';
196
197
	/**
198
	 * @var \DateTime|null
199
	 *
200
	 * @ORM\Column(name="export", type="datetime", nullable=true)
201
	 */
202
	private $export;
203
204
	/**
205
	 * @var \DateTime|null
206
	 *
207
	 * @ORM\Column(name="backup", type="datetime", nullable=true)
208
	 */
209
	private $backup;
210
211
	/**
212
	 * @var boolean
213
	 *
214
	 * @ORM\Column(name="wikilogin", type="boolean", options={"default":0}, nullable=false)
215
	 */
216
	private $wikilogin = 0;
217
218
	/**
219
	 * @var string|null
220
	 *
221
	 * @ORM\Column(name="tracking", type="string", length=50, nullable=true)
222
	 */
223
	private $tracking;
224
225
	/**
226
	 * FIXME: this should not be nullable
227
	 *
228
	 * @var integer
229
	 *
230
	 * @ORM\Column(name="status", type="smallint", options={"default":0}, nullable=true)
231
	 */
232
	private $status = 0;
233
234
	/**
235
	 * @var string|null
236
	 *
237
	 * @ORM\Column(name="country", type="string", length=8, options={"default":""}, nullable=true)
238
	 */
239
	private $country = '';
240
241
	/**
242
	 * @var string|null
243
	 *
244
	 * @ORM\Column(name="data", type="text", nullable=true)
245
	 */
246
	private $data;
247
248
	/**
249
	 * @var integer
250
	 *
251
	 * @ORM\Column(name="id", type="integer")
252
	 * @ORM\Id
253
	 * @ORM\GeneratedValue(strategy="IDENTITY")
254
	 */
255
	private $id;
256
257
	const STATUS_CONFIRMED = 1;
258
	const STATUS_NEUTRAL = 0;
259
	const STATUS_DELETED = -1;
260
	const STATUS_MODERATION = -2;
261
	const STATUS_ABORTED = -4;
262
	const STATUS_CANCELED = -8;
263
264
	/**
265
	 * @return integer
266
	 */
267
	public function getId() {
268
		return $this->id;
269
	}
270
271
	/**
272
	 * @since 2.0
273
	 *
274
	 * @param integer|null $id
275
	 */
276
	public function setId( $id ) {
277
		$this->id = $id;
278
	}
279
280
	/**
281
	 * @param integer|null $donationId
282
	 *
283
	 * @return self
284
	 */
285
	public function setDonationId( $donationId ) {
286
		$this->donationId = $donationId;
287
288
		return $this;
289
	}
290
291
	/**
292
	 * Returns the id of the donation that led to the membership application,
293
	 * or null when the application is not linked to any donation.
294
	 *
295
	 * @return integer|null
296
	 */
297
	public function getDonationId() {
298
		return $this->donationId;
299
	}
300
301
	/**
302
	 * @param \DateTime $timestamp
303
	 *
304
	 * @return self
305
	 */
306
	public function setTimestamp( $timestamp ) {
307
		$this->timestamp = $timestamp;
308
309
		return $this;
310
	}
311
312
	/**
313
	 * @return \DateTime
314
	 */
315
	public function getTimestamp() {
316
		return $this->timestamp;
317
	}
318
319
	/**
320
	 * @param string|null $salutation
321
	 *
322
	 * @return self
323
	 */
324
	public function setSalutation( $salutation ) {
325
		$this->salutation = $salutation;
326
327
		return $this;
328
	}
329
330
	/**
331
	 * @return string|null
332
	 */
333
	public function getSalutation() {
334
		return $this->salutation;
335
	}
336
337
	/**
338
	 * @param string|null $company
339
	 *
340
	 * @return self
341
	 */
342
	public function setCompany( $company ) {
343
		$this->company = $company;
344
345
		return $this;
346
	}
347
348
	/**
349
	 * @return string|null
350
	 */
351
	public function getCompany() {
352
		return $this->company;
353
	}
354
355
	/**
356
	 * @param string $title
357
	 *
358
	 * @return self
359
	 */
360
	public function setTitle( $title ) {
361
		$this->title = $title;
362
363
		return $this;
364
	}
365
366
	/**
367
	 * @return string
368
	 */
369
	public function getTitle() {
370
		return $this->title;
371
	}
372
373
	/**
374
	 * @param string $name
375
	 *
376
	 * @return self
377
	 */
378
	public function setName( $name ) {
379
		$this->name = $name;
380
381
		return $this;
382
	}
383
384
	/**
385
	 * @return string
386
	 */
387
	public function getName() {
388
		return $this->name;
389
	}
390
391
	/**
392
	 * @param string $firstName
393
	 *
394
	 * @return self
395
	 */
396
	public function setFirstName( $firstName ) {
397
		$this->firstName = $firstName;
398
		$this->setNameFromParts( $firstName, $this->getLastName() );
399
400
		return $this;
401
	}
402
403
	/**
404
	 * @return string
405
	 */
406
	public function getFirstName() {
407
		return $this->firstName;
408
	}
409
410
	/**
411
	 * @param string $lastName
412
	 *
413
	 * @return self
414
	 */
415
	public function setLastName( $lastName ) {
416
		$this->lastName = $lastName;
417
		$this->setNameFromParts( $this->getFirstName(), $lastName );
418
419
		return $this;
420
	}
421
422
	/**
423
	 * @return string
424
	 */
425
	public function getLastName() {
426
		return $this->lastName;
427
	}
428
429
	/**
430
	 * Sets the full name
431
	 */
432
	public function setNameFromParts( $vorname, $nachname) {
433
		$parts = array_filter( [ $vorname, $nachname ] );
434
		$this->setName( implode( ' ', $parts ) );
435
436
		return $this;
437
	}
438
439
	/**
440
	 * Set address (street, etc)
441
	 *
442
	 * @param string|null $address
443
	 *
444
	 * @return self
445
	 */
446
	public function setAddress( $address ) {
447
		$this->address = $address;
448
449
		return $this;
450
	}
451
452
	/**
453
	 * Get address (street, etc)
454
	 *
455
	 * @return string|null
456
	 */
457
	public function getAddress() {
458
		return $this->address;
459
	}
460
461
	/**
462
	 * @param string|null $postcode
463
	 *
464
	 * @return self
465
	 */
466
	public function setPostcode( $postcode ) {
467
		$this->postcode = $postcode;
468
469
		return $this;
470
	}
471
472
	/**
473
	 * @return string|null
474
	 */
475
	public function getPostcode() {
476
		return $this->postcode;
477
	}
478
479
	/**
480
	 * @param string|null $city
481
	 *
482
	 * @return self
483
	 */
484
	public function setCity( $city ) {
485
		$this->city = $city;
486
487
		return $this;
488
	}
489
490
	/**
491
	 * @return string|null
492
	 */
493
	public function getCity() {
494
		return $this->city;
495
	}
496
497
	/**
498
	 * Set email
499
	 *
500
	 * @param string $email
501
	 *
502
	 * @return self
503
	 */
504
	public function setEmail( $email ) {
505
		$this->email = $email;
506
507
		return $this;
508
	}
509
510
	/**
511
	 * Get email
512
	 *
513
	 * @return string
514
	 */
515
	public function getEmail() {
516
		return $this->email;
517
	}
518
519
	/**
520
	 * Set phone
521
	 *
522
	 * @param string $phone
523
	 *
524
	 * @return self
525
	 */
526
	public function setPhone( $phone ) {
527
		$this->phone = $phone;
528
529
		return $this;
530
	}
531
532
	/**
533
	 * Get phone
534
	 *
535
	 * @return string
536
	 */
537
	public function getPhone() {
538
		return $this->phone;
539
	}
540
541
	/**
542
	 * Sets the date of birth of the applicant
543
	 *
544
	 * @param \DateTime|null $dateOfBirth
545
	 *
546
	 * @return self
547
	 */
548
	public function setDob( $dateOfBirth ) {
549
		$this->dateOfBirth = $dateOfBirth;
550
551
		return $this;
552
	}
553
554
	/**
555
	 * Returns the date of birth of the applicant
556
	 *
557
	 * @return \DateTime|null
558
	 */
559
	public function getDob() {
560
		return $this->dateOfBirth;
561
	}
562
563
	/**
564
	 * @param string $wikimediumShipping
565
	 *
566
	 * @return self
567
	 */
568
	public function setWikimediumShipping( $wikimediumShipping ) {
569
		$this->wikimediumShipping = $wikimediumShipping;
570
571
		return $this;
572
	}
573
574
	/**
575
	 * @return string
576
	 */
577
	public function getWikimediumShipping() {
578
		return $this->wikimediumShipping;
579
	}
580
581
	/**
582
	 * @param string $membershipType
583
	 *
584
	 * @return self
585
	 */
586
	public function setMembershipType( $membershipType ) {
587
		$this->membershipType = $membershipType;
588
589
		return $this;
590
	}
591
592
	/**
593
	 * @return string
594
	 */
595
	public function getMembershipType() {
596
		return $this->membershipType;
597
	}
598
599
	/**
600
	 * @param integer $membershipFee
601
	 *
602
	 * @return self
603
	 */
604
	public function setMembershipFee( $membershipFee ) {
605
		$this->membershipFee = $membershipFee;
606
607
		return $this;
608
	}
609
610
	/**
611
	 * @return integer
612
	 */
613
	public function getMembershipFee() {
614
		return $this->membershipFee;
615
	}
616
617
	/**
618
	 * @param integer $membershipFeeInterval
619
	 *
620
	 * @return self
621
	 */
622
	public function setMembershipFeeInterval($membershipFeeInterval) {
623
		$this->membershipFeeInterval = $membershipFeeInterval;
624
625
		return $this;
626
	}
627
628
	/**
629
	 * @return integer
630
	 */
631
	public function getMembershipFeeInterval() {
632
		return $this->membershipFeeInterval;
633
	}
634
635
636
	/**
637
	 * @param string $accountNumber
638
	 *
639
	 * @return self
640
	 */
641
	public function setAccountNumber( $accountNumber ) {
642
		$this->accountNumber = $accountNumber;
643
644
		return $this;
645
	}
646
647
	/**
648
	 * @return string
649
	 */
650
	public function getAccountNumber() {
651
		return $this->accountNumber;
652
	}
653
654
	/**
655
	 * @param string $bankName
656
	 *
657
	 * @return self
658
	 */
659
	public function setBankName( $bankName ) {
660
		$this->bankName = $bankName;
661
662
		return $this;
663
	}
664
665
	/**
666
	 * @return string
667
	 */
668
	public function getBankName() {
669
		return $this->bankName;
670
	}
671
672
	/**
673
	 * @param string $bankCode
674
	 *
675
	 * @return self
676
	 */
677
	public function setBankCode( $bankCode ) {
678
		$this->bankCode = $bankCode;
679
680
		return $this;
681
	}
682
683
	/**
684
	 * @return string
685
	 */
686
	public function getBankCode() {
687
		return $this->bankCode;
688
	}
689
690
	/**
691
	 * @param string|null $iban
692
	 *
693
	 * @return self
694
	 */
695
	public function setIban( $iban ) {
696
		$this->iban = $iban;
697
698
		return $this;
699
	}
700
701
	/**
702
	 * @return string|null
703
	 */
704
	public function getIban() {
705
		return $this->iban;
706
	}
707
708
	/**
709
	 * @param string|null $bic
710
	 *
711
	 * @return self
712
	 */
713
	public function setBic( $bic ) {
714
		$this->bic = $bic;
715
716
		return $this;
717
	}
718
719
	/**
720
	 * @return string|null
721
	 */
722
	public function getBic() {
723
		return $this->bic;
724
	}
725
726
	/**
727
	 * @param string $accountHolder
728
	 *
729
	 * @return self
730
	 */
731
	public function setAccountHolder( $accountHolder ) {
732
		$this->accountHolder = $accountHolder;
733
734
		return $this;
735
	}
736
737
	/**
738
	 * @return string
739
	 */
740
	public function getAccountHolder() {
741
		return $this->accountHolder;
742
	}
743
744
	/**
745
	 * @param string $comment
746
	 *
747
	 * @return self
748
	 */
749
	public function setComment( $comment ) {
750
		$this->comment = $comment;
751
752
		return $this;
753
	}
754
755
	/**
756
	 * @return string
757
	 */
758
	public function getComment() {
759
		return $this->comment;
760
	}
761
762
	/**
763
	 * Sets the time of export.
764
	 *
765
	 * @param \DateTime|null $export
766
	 *
767
	 * @return self
768
	 */
769
	public function setExport( $export ) {
770
		$this->export = $export;
771
772
		return $this;
773
	}
774
775
	/**
776
	 * Returns the time of export.
777
	 *
778
	 * @return \DateTime|null
779
	 */
780
	public function getExport() {
781
		return $this->export;
782
	}
783
784
	/**
785
	 * Sets the time of backup.
786
	 *
787
	 * @param \DateTime|null $backup
788
	 *
789
	 * @return self
790
	 */
791
	public function setBackup( $backup ) {
792
		$this->backup = $backup;
793
794
		return $this;
795
	}
796
797
	/**
798
	 * Returns the time of backup.
799
	 *
800
	 * @return \DateTime|null
801
	 */
802
	public function getBackup() {
803
		return $this->backup;
804
	}
805
806
	/**
807
	 * @param boolean $wikilogin
808
	 *
809
	 * @return self
810
	 */
811
	public function setWikilogin( $wikilogin ) {
812
		$this->wikilogin = $wikilogin;
813
814
		return $this;
815
	}
816
817
	/**
818
	 * @return boolean
819
	 */
820
	public function getWikilogin() {
821
		return $this->wikilogin;
822
	}
823
824
	/**
825
	 * @param string|null $tracking
826
	 *
827
	 * @return self
828
	 */
829
	public function setTracking( $tracking ) {
830
		$this->tracking = $tracking;
831
832
		return $this;
833
	}
834
835
	/**
836
	 * @return string|null
837
	 */
838
	public function getTracking() {
839
		return $this->tracking;
840
	}
841
842
	/**
843
	 * Sets the status of the membership request.
844
	 * The allowed values are the STATUS_ constants in this class.
845
	 *
846
	 * @param integer $status
847
	 *
848
	 * @return self
849
	 */
850
	public function setStatus( $status ) {
851
		$this->status = $status;
852
853
		return $this;
854
	}
855
856
	/**
857
	 * Returns the status of the membership request.
858
	 * The possible values are the STATUS_ constants in this class.
859
	 *
860
	 * @return integer
861
	 */
862
	public function getStatus() {
863
		return $this->status;
864
	}
865
866
	/**
867
	 * @param string|null $country
868
	 *
869
	 * @return self
870
	 */
871
	public function setCountry( $country ) {
872
		$this->country = $country;
873
874
		return $this;
875
	}
876
877
	/**
878
	 * @return string|null
879
	 */
880
	public function getCountry() {
881
		return $this->country;
882
	}
883
884
	/**
885
	 * @param string|null $data
886
	 * @return self
887
	 */
888
	public function setData( $data ) {
889
		$this->data = $data;
890
891
		return $this;
892
	}
893
894
	/**
895
	 * @return string|null
896
	 */
897
	public function getData() {
898
		return $this->data;
899
	}
900
901
	public function isUnconfirmed() {
902
		return $this->getStatus() === self::STATUS_NEUTRAL;
903
	}
904
905
	public function log( $message ) {
906
		$dataArray = $this->getDecodedData();
907
		$dataArray[ "log" ][ date( "Y-m-d H:i:s" ) ] = $message;
908
		$this->encodeAndSetData( $dataArray );
909
910
		return $this;
911
	}
912
913
	/**
914
	 * NOTE: if possible, use @see getDataObject instead, as it provides a nicer API.
915
	 *
916
	 * @since 2.0
917
	 * @return array
918
	 */
919
	public function getDecodedData() {
920
		$data = unserialize( base64_decode( $this->data ) );
921
922
		return is_array( $data ) ? $data : [];
923
	}
924
925
	/**
926
	 * NOTE: if possible, use @see modifyDataObject instead, as it provides a nicer API.
927
	 *
928
	 * @since 2.0
929
	 * @param array $data
0 ignored issues
show
Bug introduced by
There is no parameter named $data. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
930
	 */
931
	public function encodeAndSetData( array $dataArray ) {
932
		$this->data = base64_encode( serialize( $dataArray ) );
933
	}
934
935
	/**
936
	 * WARNING: updates made to the return value will not be reflected in the Donation state.
937
	 * Similarly, updates to the Donation state will not propagate to the returned object.
938
	 * To update the Donation state, explicitly call @see setDataObject.
939
	 *
940
	 * @since 2.0
941
	 * @return MembershipApplicationData
942
	 */
943
	public function getDataObject() {
944
		$dataArray = $this->getDecodedData();
945
946
		$data = new MembershipApplicationData();
947
948
		$data->setAccessToken( array_key_exists( 'token', $dataArray ) ? $dataArray['token'] : null );
949
		$data->setUpdateToken( array_key_exists( 'utoken', $dataArray ) ? $dataArray['utoken'] : null );
950
951
		return $data;
952
	}
953
954
	/**
955
	 * @since 2.0
956
	 * @param MembershipApplicationData $data
957
	 */
958
	public function setDataObject( MembershipApplicationData $data ) {
959
		$dataArray = array_merge(
960
			$this->getDecodedData(),
961
			[
962
				'token' => $data->getAccessToken(),
963
				'utoken' => $data->getUpdateToken(),
964
			]
965
		);
966
967
		foreach ( [ 'token', 'utoken' ] as $keyName ) {
968
			if ( is_null( $dataArray[$keyName] ) ) {
969
				unset( $dataArray[$keyName] );
970
			}
971
		}
972
973
		$this->encodeAndSetData( $dataArray );
974
	}
975
976
	/**
977
	 * @since 2.0
978
	 * @param callable $modificationFunction Takes a modifiable MembershipApplicationData parameter
979
	 */
980
	public function modifyDataObject( callable $modificationFunction ) {
981
		$dataObject = $this->getDataObject();
982
		$modificationFunction( $dataObject );
983
		$this->setDataObject( $dataObject );
984
	}
985
986
}
987