Completed
Pull Request — master (#53)
by Jeroen De
06:28 queued 03:58
created

Donation::setDonationReceipt()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
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
8
/**
9
 * @since 2.0
10
 *
11
 * @ORM\Table(name="spenden", indexes={@ORM\Index(name="email", columns={"email"}), @ORM\Index(name="name", columns={"name"}), @ORM\Index(name="ort", columns={"ort"}), @ORM\Index(name="dt_new", columns={"dt_new", "is_public"}), @ORM\Index(name="dt_exp", columns={"dt_exp", "dt_del"}), @ORM\Index(name="zahlweise", columns={"zahlweise", "dt_new"}), @ORM\Index(name="dt_gruen", columns={"dt_gruen", "dt_del"}), @ORM\Index(name="ueb_code", columns={"ueb_code"}), @ORM\Index(name="dt_backup", columns={"dt_backup"}), @ORM\Index(name="status", columns={"status", "dt_new"}), @ORM\Index(name="comment_list", columns={"is_public", "dt_del"})})
12
 * @ORM\Entity
13
 */
14
class Donation {
15
	/**
16
	 * @var string
17
	 *
18
	 * @ORM\Column(name="name", type="string", length=250, nullable=true)
19
	 */
20
	private $name;
21
22
	/**
23
	 * @var string
24
	 *
25
	 * @ORM\Column(name="ort", type="string", length=250, nullable=true)
26
	 */
27
	private $city;
28
29
	/**
30
	 * @var string
31
	 *
32
	 * @ORM\Column(name="email", type="string", length=250, nullable=true)
33
	 */
34
	private $email;
35
36
	/**
37
	 * @var boolean
38
	 *
39
	 * @ORM\Column(name="info", type="boolean", options={"default":0}, nullable=false)
40
	 */
41
	private $info = 0;
42
43
	/**
44
	 * @var boolean
45
	 *
46
	 * @ORM\Column(name="bescheinigung", type="boolean", nullable=true)
47
	 */
48
	private $donationReceipt;
49
50
	/**
51
	 * @var string
52
	 *
53
	 * @ORM\Column(name="eintrag", type="string", length=250, options={"default":""}, nullable=false)
54
	 */
55
	private $publicRecord = '';
56
57
	/**
58
	 * @var string
59
	 *
60
	 * @ORM\Column(name="betrag", type="string", length=250, nullable=true)
61
	 */
62
	private $amount;
63
64
	/**
65
	 * @var integer
66
	 *
67
	 * @ORM\Column(name="periode", type="smallint", options={"default":0}, nullable=false)
68
	 */
69
	private $period = 0;
70
71
	/**
72
	 * @var string
73
	 *
74
	 * @ORM\Column(name="zahlweise", type="string", length=3, options={"default":"BEZ", "fixed":true}, nullable=false)
75
	 */
76
	private $paymentType = 'BEZ';
77
78
	/**
79
	 * @var string
80
	 *
81
	 * @ORM\Column(name="kommentar", type="text", options={"default":""}, nullable=false)
82
	 */
83
	private $comment = '';
84
85
	/**
86
	 * @var string
87
	 *
88
	 * @ORM\Column(name="ueb_code", type="string", length=32, options={"default":""}, nullable=false)
89
	 */
90
	private $transferCode = '';
91
92
	/**
93
	 * @var string
94
	 *
95
	 * @ORM\Column(name="data", type="text", nullable=true)
96
	 */
97
	private $data;
98
99
	/**
100
	 * @var string
101
	 *
102
	 * @ORM\Column(name="source", type="string", length=250, nullable=true)
103
	 */
104
	private $source;
105
106
	/**
107
	 * @var string
108
	 *
109
	 * @ORM\Column(name="remote_addr", type="string", length=250, options={"default":""}, nullable=false)
110
	 */
111
	private $remoteAddr = '';
112
113
	/**
114
	 * @var string
115
	 *
116
	 * @ORM\Column(name="hash", type="string", length=250, nullable=true)
117
	 */
118
	private $hash;
119
120
	/**
121
	 * @var boolean
122
	 *
123
	 * @ORM\Column(name="is_public", type="boolean", options={"default":0}, nullable=false)
124
	 */
125
	private $isPublic = 0;
126
127
	/**
128
	 * @var \DateTime
129
	 *
130
	 * @Gedmo\Timestampable(on="create")
131
	 * @ORM\Column(name="dt_new", type="datetime", nullable=true)
132
	 */
133
	private $dtNew;
134
135
	/**
136
	 * @var \DateTime
137
	 *
138
	 * @ORM\Column(name="dt_del", type="datetime", nullable=true)
139
	 */
140
	private $dtDel;
141
142
	/**
143
	 * @var \DateTime
144
	 *
145
	 * @ORM\Column(name="dt_exp", type="datetime", nullable=true)
146
	 */
147
	private $dtExp;
148
149
	/**
150
	 * @var string
151
	 *
152
	 * @ORM\Column(name="status", type="string", length=1, options={"default":"N", "fixed":true}, nullable=false)
153
	 */
154
	private $status = 'N';
155
156
	/**
157
	 * @var \DateTime
158
	 *
159
	 * @ORM\Column(name="dt_gruen", type="datetime", nullable=true)
160
	 */
161
	private $dtGruen;
162
163
	/**
164
	 * @var \DateTime
165
	 *
166
	 * @ORM\Column(name="dt_backup", type="datetime", nullable=true)
167
	 */
168
	private $dtBackup;
169
170
	/**
171
	 * @var integer
172
	 *
173
	 * @ORM\Column(name="id", type="integer")
174
	 * @ORM\Id
175
	 * @ORM\GeneratedValue(strategy="IDENTITY")
176
	 */
177
	private $id;
178
179
180
	/**
181
	 * Set name
182
	 *
183
	 * @param string $name
184
	 * @return self
185
	 */
186
	public function setName( $name ) {
187
		$this->name = $name;
188
189
		return $this;
190
	}
191
192
	/**
193
	 * Get name
194
	 *
195
	 * @return string
196
	 */
197
	public function getName() {
198
		return $this->name;
199
	}
200
201
	/**
202
	 * Set city
203
	 *
204
	 * @param string $city
205
	 * @return self
206
	 */
207
	public function setCity( $city ) {
208
		$this->city = $city;
209
210
		return $this;
211
	}
212
213
	/**
214
	 * Get city
215
	 *
216
	 * @return string
217
	 */
218
	public function getCity() {
219
		return $this->city;
220
	}
221
222
	/**
223
	 * Set email
224
	 *
225
	 * @param string $email
226
	 * @return self
227
	 */
228
	public function setEmail( $email ) {
229
		$this->email = $email;
230
231
		return $this;
232
	}
233
234
	/**
235
	 * Get email
236
	 *
237
	 * @return string
238
	 */
239
	public function getEmail() {
240
		return $this->email;
241
	}
242
243
	/**
244
	 * Set info
245
	 *
246
	 * @param boolean $info
247
	 * @return self
248
	 */
249
	public function setInfo( $info ) {
250
		$this->info = $info;
251
252
		return $this;
253
	}
254
255
	/**
256
	 * Get info
257
	 *
258
	 * @return boolean
259
	 */
260
	public function getInfo() {
261
		return $this->info;
262
	}
263
264
	/**
265
	 * Set donation receipt state
266
	 *
267
	 * @param boolean $donationReceipt
268
	 * @return self
269
	 */
270
	public function setDonationReceipt( $donationReceipt ) {
271
		$this->donationReceipt = $donationReceipt;
272
273
		return $this;
274
	}
275
276
	/**
277
	 * Get donation receipt state
278
	 *
279
	 * @return boolean
280
	 */
281
	public function getDonationReceipt() {
282
		return $this->donationReceipt;
283
	}
284
285
	/**
286
	 * Set publicly displayed donation record
287
	 *
288
	 * @param string $publicRecord
289
	 * @return self
290
	 */
291
	public function setPublicRecord( $publicRecord ) {
292
		$this->publicRecord = $publicRecord;
293
294
		return $this;
295
	}
296
297
	/**
298
	 * Get publicly displayed donation record
299
	 *
300
	 * @return string
301
	 */
302
	public function getPublicRecord() {
303
		return $this->publicRecord;
304
	}
305
306
	/**
307
	 * Set amount
308
	 *
309
	 * @param string $amount
310
	 * @return self
311
	 */
312
	public function setAmount( $amount ) {
313
		$this->amount = $amount;
314
315
		return $this;
316
	}
317
318
	/**
319
	 * Get amount
320
	 *
321
	 * @return string
322
	 */
323
	public function getAmount() {
324
		return $this->amount;
325
	}
326
327
	/**
328
	 * Set period
329
	 *
330
	 * @param integer $period
331
	 * @return self
332
	 */
333
	public function setPeriod( $period ) {
334
		$this->period = $period;
335
336
		return $this;
337
	}
338
339
	/**
340
	 * Get period
341
	 *
342
	 * @return integer
343
	 */
344
	public function getPeriod() {
345
		return $this->period;
346
	}
347
348
	/**
349
	 * Set payment type short code
350
	 *
351
	 * @param string $paymentType
352
	 * @return self
353
	 */
354
	public function setPaymentType( $paymentType ) {
355
		$this->paymentType = $paymentType;
356
357
		return $this;
358
	}
359
360
	/**
361
	 * Get payment type short code
362
	 *
363
	 * @return string
364
	 */
365
	public function getPaymentType() {
366
		return $this->paymentType;
367
	}
368
369
	/**
370
	 * Set comment
371
	 *
372
	 * @param string $comment
373
	 * @return self
374
	 */
375
	public function setComment( $comment ) {
376
		$this->comment = $comment;
377
378
		return $this;
379
	}
380
381
	/**
382
	 * Get comment
383
	 *
384
	 * @return string
385
	 */
386
	public function getComment() {
387
		return $this->comment;
388
	}
389
390
	/**
391
	 * Set bank transfer reference code
392
	 *
393
	 * @param string $transferCode
394
	 * @return self
395
	 */
396
	public function setTransferCode( $transferCode ) {
397
		$this->transferCode = $transferCode;
398
399
		return $this;
400
	}
401
402
	/**
403
	 * Get bank transfer reference code
404
	 *
405
	 * @return string
406
	 */
407
	public function getTransferCode() {
408
		return $this->transferCode;
409
	}
410
411
	/**
412
	 * Set data
413
	 *
414
	 * @param string $data
415
	 * @return self
416
	 */
417
	public function setData( $data ) {
418
		$this->data = $data;
419
420
		return $this;
421
	}
422
423
	/**
424
	 * Get data
425
	 *
426
	 * @return string
427
	 */
428
	public function getData() {
429
		return $this->data;
430
	}
431
432
	/**
433
	 * Set source
434
	 *
435
	 * @param string $source
436
	 * @return self
437
	 */
438
	public function setSource( $source ) {
439
		$this->source = $source;
440
441
		return $this;
442
	}
443
444
	/**
445
	 * Get source
446
	 *
447
	 * @return string
448
	 */
449
	public function getSource() {
450
		return $this->source;
451
	}
452
453
	/**
454
	 * Set remoteAddr
455
	 *
456
	 * @param string $remoteAddr
457
	 * @return self
458
	 */
459
	public function setRemoteAddr( $remoteAddr ) {
460
		$this->remoteAddr = $remoteAddr;
461
462
		return $this;
463
	}
464
465
	/**
466
	 * Get remoteAddr
467
	 *
468
	 * @return string
469
	 */
470
	public function getRemoteAddr() {
471
		return $this->remoteAddr;
472
	}
473
474
	/**
475
	 * Set hash
476
	 *
477
	 * @param string $hash
478
	 * @return self
479
	 */
480
	public function setHash( $hash ) {
481
		$this->hash = $hash;
482
483
		return $this;
484
	}
485
486
	/**
487
	 * Get hash
488
	 *
489
	 * @return string
490
	 */
491
	public function getHash() {
492
		return $this->hash;
493
	}
494
495
	/**
496
	 * Set isPublic
497
	 *
498
	 * @param boolean $isPublic
499
	 * @return self
500
	 */
501
	public function setIsPublic( $isPublic ) {
502
		$this->isPublic = $isPublic;
503
504
		return $this;
505
	}
506
507
	/**
508
	 * Get isPublic
509
	 *
510
	 * @return boolean
511
	 */
512
	public function getIsPublic() {
513
		return $this->isPublic;
514
	}
515
516
	/**
517
	 * Set dtNew
518
	 *
519
	 * @param \DateTime $dtNew
520
	 * @return self
521
	 */
522
	public function setDtNew( $dtNew ) {
523
		$this->dtNew = $dtNew;
524
525
		return $this;
526
	}
527
528
	/**
529
	 * Get dtNew
530
	 *
531
	 * @return \DateTime
532
	 */
533
	public function getDtNew() {
534
		return $this->dtNew;
535
	}
536
537
	/**
538
	 * Set dtDel
539
	 *
540
	 * @param \DateTime $dtDel
541
	 * @return self
542
	 */
543
	public function setDtDel( $dtDel ) {
544
		$this->dtDel = $dtDel;
545
546
		return $this;
547
	}
548
549
	/**
550
	 * Get dtDel
551
	 *
552
	 * @return \DateTime
553
	 */
554
	public function getDtDel() {
555
		return $this->dtDel;
556
	}
557
558
	/**
559
	 * Set dtExp
560
	 *
561
	 * @param \DateTime $dtExp
562
	 * @return self
563
	 */
564
	public function setDtExp( $dtExp ) {
565
		$this->dtExp = $dtExp;
566
567
		return $this;
568
	}
569
570
	/**
571
	 * Get dtExp
572
	 *
573
	 * @return \DateTime
574
	 */
575
	public function getDtExp() {
576
		return $this->dtExp;
577
	}
578
579
	/**
580
	 * Set status
581
	 *
582
	 * @param string $status
583
	 * @return self
584
	 */
585
	public function setStatus( $status ) {
586
		$this->status = $status;
587
588
		return $this;
589
	}
590
591
	/**
592
	 * Get status
593
	 *
594
	 * @return string
595
	 */
596
	public function getStatus() {
597
		return $this->status;
598
	}
599
600
	/**
601
	 * Set dtGruen
602
	 *
603
	 * @param \DateTime $dtGruen
604
	 * @return self
605
	 */
606
	public function setDtGruen( $dtGruen ) {
607
		$this->dtGruen = $dtGruen;
608
609
		return $this;
610
	}
611
612
	/**
613
	 * Get dtGruen
614
	 *
615
	 * @return \DateTime
616
	 */
617
	public function getDtGruen() {
618
		return $this->dtGruen;
619
	}
620
621
	/**
622
	 * Set dtBackup
623
	 *
624
	 * @param \DateTime $dtBackup
625
	 * @return self
626
	 */
627
	public function setDtBackup( $dtBackup ) {
628
		$this->dtBackup = $dtBackup;
629
630
		return $this;
631
	}
632
633
	/**
634
	 * Get dtBackup
635
	 *
636
	 * @return \DateTime
637
	 */
638
	public function getDtBackup() {
639
		return $this->dtBackup;
640
	}
641
642
	/**
643
	 * Get id
644
	 *
645
	 * @return integer
646
	 */
647
	public function getId() {
648
		return $this->id;
649
	}
650
651
	public function getUExpiry() {
652
		return $this->getDecodedData()[ 'uexpiry' ];
653
	}
654
655
	public function uTokenIsExpired() {
656
		return time() > strtotime( $this->getUExpiry() );
657
	}
658
659
	public function validateToken( $tokenToCheck, $serverSecret ) {
660
		$checkToken = preg_replace( '/\$.*$/', '', $tokenToCheck );
661
662
		$checkToken = $checkToken . '$' .
663
			sha1( sha1( "$checkToken+$serverSecret" ) . '|' .
664
				sha1( "{$this->id}+$serverSecret" ) . '|' .
665
				sha1( "{$this->dtNew->format( 'Y-m-d H:i:s' )}+$serverSecret" ) );
666
		return $checkToken === $tokenToCheck;
667
	}
668
669
	public function getEntryType( $mode = null ) {
670
		$data = $this->getDecodedData();
671
672
		if ( $mode === null ) {
673
			$mode = $this->publicRecord;
674
			if ( !is_int( $mode ) ) {
675
				return $this->publicRecord;
676
			}
677
		}
678
679
		if ( $mode == 1 || $mode == 2 ) {
680
			$eintrag = $this->name;
681
		} else {
682
			$eintrag = "anonym";
683
		}
684
685
		if ( ( $mode == 1 || $mode == 3 ) && !empty( $data[ "ort" ] ) ) {
686
			$eintrag .= ", " . $data[ "ort" ];
687
		}
688
689
		return $eintrag;
690
	}
691
692
	/**
693
	 * @since 2.0
694
	 * @return array
695
	 */
696
	public function getDecodedData() {
697
		return unserialize( base64_decode( $this->data ) );
698
	}
699
700
	/**
701
	 * @since 2.0
702
	 * @param array $data
703
	 */
704
	public function encodeAndSetData( array $data ) {
705
		$this->data = base64_encode( serialize( $data ) );
706
	}
707
708
	/**
709
	 * Marks the donation as cancelled by updating the required fields.
710
	 * No validation is done here, as this should happen in the domain.
711
	 *
712
	 * @since 2.0
713
	 */
714
	public function cancel() {
715
		$this->dtDel = date( 'Y-m-d H:i:s' );
0 ignored issues
show
Documentation Bug introduced by
It seems like date('Y-m-d H:i:s') of type string is incompatible with the declared type object<DateTime> of property $dtDel.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
716
		$this->status = 'D';
717
718
		$data = $this->getDecodedData();
719
720
		$data['dt_del'] = $this->dtDel;
721
		$data['status'] = $this->status;
722
		$data['utoken'] = '';
723
724
		// TODO: write to $data['log'] ?
725
726
		$this->encodeAndSetData( $data );
727
	}
728
729
}
730