Completed
Pull Request — master (#43)
by
unknown
02:23
created

Donation::getUpdatedAt()   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 0
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 \DateTime
151
	 *
152
	 * @Gedmo\Timestampable(on="update")
153
	 * @ORM\Column(name="updatedAt", type="datetime", nullable=true)
154
	 */
155
	private $updatedAt;
156
157
	/**
158
	 * @var string
159
	 *
160
	 * @ORM\Column(name="status", type="string", length=1, options={"default":"N", "fixed":true}, nullable=false)
161
	 */
162
	private $status = 'N';
163
164
	/**
165
	 * @var \DateTime
166
	 *
167
	 * @ORM\Column(name="dt_gruen", type="datetime", nullable=true)
168
	 */
169
	private $dtGruen;
170
171
	/**
172
	 * @var \DateTime
173
	 *
174
	 * @ORM\Column(name="dt_backup", type="datetime", nullable=true)
175
	 */
176
	private $dtBackup;
177
178
	/**
179
	 * @var integer
180
	 *
181
	 * @ORM\Column(name="id", type="integer")
182
	 * @ORM\Id
183
	 * @ORM\GeneratedValue(strategy="IDENTITY")
184
	 */
185
	private $id;
186
187
188
	/**
189
	 * Set name
190
	 *
191
	 * @param string $name
192
	 * @return Donation
193
	 */
194
	public function setName( $name ) {
195
		$this->name = $name;
196
197
		return $this;
198
	}
199
200
	/**
201
	 * Get name
202
	 *
203
	 * @return string
204
	 */
205
	public function getName() {
206
		return $this->name;
207
	}
208
209
	/**
210
	 * Set city
211
	 *
212
	 * @param string $city
213
	 * @return Spenden
214
	 */
215
	public function setCity( $city ) {
216
		$this->city = $city;
217
218
		return $this;
219
	}
220
221
	/**
222
	 * Get city
223
	 *
224
	 * @return string
225
	 */
226
	public function getCity() {
227
		return $this->city;
228
	}
229
230
	/**
231
	 * Set email
232
	 *
233
	 * @param string $email
234
	 * @return Donation
235
	 */
236
	public function setEmail( $email ) {
237
		$this->email = $email;
238
239
		return $this;
240
	}
241
242
	/**
243
	 * Get email
244
	 *
245
	 * @return string
246
	 */
247
	public function getEmail() {
248
		return $this->email;
249
	}
250
251
	/**
252
	 * Set info
253
	 *
254
	 * @param boolean $info
255
	 * @return Donation
256
	 */
257
	public function setInfo( $info ) {
258
		$this->info = $info;
259
260
		return $this;
261
	}
262
263
	/**
264
	 * Get info
265
	 *
266
	 * @return boolean
267
	 */
268
	public function getInfo() {
269
		return $this->info;
270
	}
271
272
	/**
273
	 * Set donation receipt state
274
	 *
275
	 * @param boolean $donationReceipt
276
	 * @return Donation
277
	 */
278
	public function setDonationReceipt( $donationReceipt ) {
279
		$this->donationReceipt = $donationReceipt;
280
281
		return $this;
282
	}
283
284
	/**
285
	 * Get donation receipt state
286
	 *
287
	 * @return boolean
288
	 */
289
	public function getDonationReceipt() {
290
		return $this->donationReceipt;
291
	}
292
293
	/**
294
	 * Set publicly displayed donation record
295
	 *
296
	 * @param string $publicRecord
297
	 * @return Donation
298
	 */
299
	public function setPublicRecord( $publicRecord ) {
300
		$this->publicRecord = $publicRecord;
301
302
		return $this;
303
	}
304
305
	/**
306
	 * Get publicly displayed donation record
307
	 *
308
	 * @return string
309
	 */
310
	public function getPublicRecord() {
311
		return $this->publicRecord;
312
	}
313
314
	/**
315
	 * Set amount
316
	 *
317
	 * @param string $amount
318
	 * @return Donation
319
	 */
320
	public function setAmount( $amount ) {
321
		$this->amount = $amount;
322
323
		return $this;
324
	}
325
326
	/**
327
	 * Get amount
328
	 *
329
	 * @return string
330
	 */
331
	public function getAmount() {
332
		return $this->amount;
333
	}
334
335
	/**
336
	 * Set period
337
	 *
338
	 * @param integer $period
339
	 * @return Donation
340
	 */
341
	public function setPeriod( $period ) {
342
		$this->period = $period;
343
344
		return $this;
345
	}
346
347
	/**
348
	 * Get period
349
	 *
350
	 * @return integer
351
	 */
352
	public function getPeriod() {
353
		return $this->period;
354
	}
355
356
	/**
357
	 * Set payment type short code
358
	 *
359
	 * @param string $paymentType
360
	 * @return Donation
361
	 */
362
	public function setPaymentType( $paymentType ) {
363
		$this->paymentType = $paymentType;
364
365
		return $this;
366
	}
367
368
	/**
369
	 * Get payment type short code
370
	 *
371
	 * @return string
372
	 */
373
	public function getPaymentType() {
374
		return $this->paymentType;
375
	}
376
377
	/**
378
	 * Set comment
379
	 *
380
	 * @param string $comment
381
	 * @return Donation
382
	 */
383
	public function setComment( $comment ) {
384
		$this->comment = $comment;
385
386
		return $this;
387
	}
388
389
	/**
390
	 * Get comment
391
	 *
392
	 * @return string
393
	 */
394
	public function getComment() {
395
		return $this->comment;
396
	}
397
398
	/**
399
	 * Set bank transfer reference code
400
	 *
401
	 * @param string $transferCode
402
	 * @return Donation
403
	 */
404
	public function setTransferCode( $transferCode ) {
405
		$this->transferCode = $transferCode;
406
407
		return $this;
408
	}
409
410
	/**
411
	 * Get bank transfer reference code
412
	 *
413
	 * @return string
414
	 */
415
	public function getTransferCode() {
416
		return $this->transferCode;
417
	}
418
419
	/**
420
	 * Set data
421
	 *
422
	 * @param string $data
423
	 * @return Donation
424
	 */
425
	public function setData( $data ) {
426
		$this->data = $data;
427
428
		return $this;
429
	}
430
431
	/**
432
	 * Get data
433
	 *
434
	 * @return string
435
	 */
436
	public function getData() {
437
		return $this->data;
438
	}
439
440
	/**
441
	 * Set source
442
	 *
443
	 * @param string $source
444
	 * @return Donation
445
	 */
446
	public function setSource( $source ) {
447
		$this->source = $source;
448
449
		return $this;
450
	}
451
452
	/**
453
	 * Get source
454
	 *
455
	 * @return string
456
	 */
457
	public function getSource() {
458
		return $this->source;
459
	}
460
461
	/**
462
	 * Set remoteAddr
463
	 *
464
	 * @param string $remoteAddr
465
	 * @return Donation
466
	 */
467
	public function setRemoteAddr( $remoteAddr ) {
468
		$this->remoteAddr = $remoteAddr;
469
470
		return $this;
471
	}
472
473
	/**
474
	 * Get remoteAddr
475
	 *
476
	 * @return string
477
	 */
478
	public function getRemoteAddr() {
479
		return $this->remoteAddr;
480
	}
481
482
	/**
483
	 * Set hash
484
	 *
485
	 * @param string $hash
486
	 * @return Donation
487
	 */
488
	public function setHash( $hash ) {
489
		$this->hash = $hash;
490
491
		return $this;
492
	}
493
494
	/**
495
	 * Get hash
496
	 *
497
	 * @return string
498
	 */
499
	public function getHash() {
500
		return $this->hash;
501
	}
502
503
	/**
504
	 * Set isPublic
505
	 *
506
	 * @param boolean $isPublic
507
	 * @return Donation
508
	 */
509
	public function setIsPublic( $isPublic ) {
510
		$this->isPublic = $isPublic;
511
512
		return $this;
513
	}
514
515
	/**
516
	 * Get isPublic
517
	 *
518
	 * @return boolean
519
	 */
520
	public function getIsPublic() {
521
		return $this->isPublic;
522
	}
523
524
	/**
525
	 * Set dtNew
526
	 *
527
	 * @param \DateTime $dtNew
528
	 * @return Donation
529
	 */
530
	public function setDtNew( $dtNew ) {
531
		$this->dtNew = $dtNew;
532
533
		return $this;
534
	}
535
536
	/**
537
	 * Get dtNew
538
	 *
539
	 * @return \DateTime
540
	 */
541
	public function getDtNew() {
542
		return $this->dtNew;
543
	}
544
545
	/**
546
	 * Set dtDel
547
	 *
548
	 * @param \DateTime $dtDel
549
	 * @return Donation
550
	 */
551
	public function setDtDel( $dtDel ) {
552
		$this->dtDel = $dtDel;
553
554
		return $this;
555
	}
556
557
	/**
558
	 * Get dtDel
559
	 *
560
	 * @return \DateTime
561
	 */
562
	public function getDtDel() {
563
		return $this->dtDel;
564
	}
565
566
	/**
567
	 * Set dtExp
568
	 *
569
	 * @param \DateTime $dtExp
570
	 * @return Donation
571
	 */
572
	public function setDtExp( $dtExp ) {
573
		$this->dtExp = $dtExp;
574
575
		return $this;
576
	}
577
578
	/**
579
	 * Get dtExp
580
	 *
581
	 * @return \DateTime
582
	 */
583
	public function getDtExp() {
584
		return $this->dtExp;
585
	}
586
587
	/**
588
	 * Set status
589
	 *
590
	 * @param string $status
591
	 * @return Donation
592
	 */
593
	public function setStatus( $status ) {
594
		$this->status = $status;
595
596
		return $this;
597
	}
598
599
	/**
600
	 * Get status
601
	 *
602
	 * @return string
603
	 */
604
	public function getStatus() {
605
		return $this->status;
606
	}
607
608
	/**
609
	 * Set dtGruen
610
	 *
611
	 * @param \DateTime $dtGruen
612
	 * @return Donation
613
	 */
614
	public function setDtGruen( $dtGruen ) {
615
		$this->dtGruen = $dtGruen;
616
617
		return $this;
618
	}
619
620
	/**
621
	 * Get dtGruen
622
	 *
623
	 * @return \DateTime
624
	 */
625
	public function getDtGruen() {
626
		return $this->dtGruen;
627
	}
628
629
	/**
630
	 * Set dtBackup
631
	 *
632
	 * @param \DateTime $dtBackup
633
	 * @return Donation
634
	 */
635
	public function setDtBackup( $dtBackup ) {
636
		$this->dtBackup = $dtBackup;
637
638
		return $this;
639
	}
640
641
	/**
642
	 * Get dtBackup
643
	 *
644
	 * @return \DateTime
645
	 */
646
	public function getDtBackup() {
647
		return $this->dtBackup;
648
	}
649
650
	/**
651
	 * @return \DateTime
652
	 */
653
	public function getUpdatedAt() {
654
		return $this->updatedAt;
655
	}
656
657
	/**
658
	 * @param \DateTime $updatedAt
659
	 */
660
	public function setUpdatedAt( $updatedAt ) {
661
		$this->updatedAt = $updatedAt;
662
	}
663
664
	/**
665
	 * Get id
666
	 *
667
	 * @return integer
668
	 */
669
	public function getId() {
670
		return $this->id;
671
	}
672
673
	public function getUExpiry() {
674
		$data = $this->decodeData( $this->data );
675
676
		return $data[ 'uexpiry' ];
677
	}
678
679
	public function uTokenIsExpired() {
680
		$uexp_time = strtotime( $this->getUExpiry() );
681
		return time() > $uexp_time;
682
	}
683
684
	public function validateToken( $tokenToCheck, $serverSecret ) {
685
		$checkToken = preg_replace( '/\$.*$/', '', $tokenToCheck );
686
687
		$checkToken = $checkToken . '$' .
688
			sha1( sha1( "$checkToken+$serverSecret" ) . '|' .
689
				sha1( "{$this->id}+$serverSecret" ) . '|' .
690
				sha1( "{$this->dtNew->format( 'Y-m-d H:i:s' )}+$serverSecret" ) );
691
		return $checkToken === $tokenToCheck;
692
	}
693
694
	public function getEntryType( $mode = null ) {
695
		$data = $this->decodeData( $this->data );
696
697
		if ( $mode === null ) {
698
			$mode = $this->publicRecord;
699
			if ( !is_int( $mode ) ) {
700
				return $this->publicRecord;
701
			}
702
		}
703
704
		if ( $mode == 1 || $mode == 2 ) {
705
			$eintrag = $this->name;
706
		} else {
707
			$eintrag = "anonym";
708
		}
709
710
		if ( ( $mode == 1 || $mode == 3 ) && !empty( $data[ "ort" ] ) ) {
711
			$eintrag .= ", " . $data[ "ort" ];
712
		}
713
714
		return $eintrag;
715
	}
716
717
	private function decodeData( $data ) {
718
		return unserialize( base64_decode( $data ) );
719
	}
720
}
721