Completed
Pull Request — master (#41)
by Leszek
04:36
created

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