Elector.php 2.79 KB
Newer Older
1
<?php
2
namespace T3o\Election\Domain\Model;
3

4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

Oliver Eglseder's avatar
Oliver Eglseder committed
17
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
18
19
20
21
22
23
24

/**
 * Class Elector
 */
class Elector extends AbstractPerson
{
    /**
25
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3o\Election\Domain\Model\Electorate>
26
     * @lazy
27
28
29
     */
    protected $electorates = '';

30
    /**
31
     * @var \TYPO3\CMS\Extbase\Persistence\ObjectStorage<\T3o\Election\Domain\Model\ElectionInvitation>
32
     * @lazy
33
34
35
     */
    protected $electionInvitations = [];

Oliver Eglseder's avatar
Oliver Eglseder committed
36
37
38
39
40
41
42
43
44
    /**
     * Elector constructor.
     */
    public function __construct()
    {
        parent::__construct();
        $this->electorates = new ObjectStorage();
    }

45
    /**
46
     * @return \T3o\Election\Domain\Model\Electorate[]
47
48
49
50
51
52
53
     */
    public function getElectorates()
    {
        return $this->electorates;
    }

    /**
54
     * @param \T3o\Election\Domain\Model\Electorate[] $electorates
55
56
57
58
59
     */
    public function setElectorates($electorates)
    {
        $this->electorates = $electorates;
    }
Oliver Eglseder's avatar
Oliver Eglseder committed
60
61
62
63
64
65
66
67
68
69

    /**
     * @param Electorate $electorate
     */
    public function addElectorate(Electorate $electorate = null)
    {
        if (null !== $electorate) {
            $this->electorates->attach($electorate);
        }
    }
70
71
72
73
74
75

    /**
     * @return ElectionInvitation[]
     */
    public function getElectionInvitations()
    {
76
        return $this->electionInvitations ?? 0;
77
78
79
80
81
82
83
    }

    /**
     * @param ObjectStorage $electionInvitations
     */
    public function setElectionInvitations($electionInvitations)
    {
84
        $this->electionInvitations = $electionInvitations ?? 0;
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
    }

    /**
     * @param Election $election
     * @return bool
     */
    public function hasElectionInvitationForElection(Election $election)
    {
        foreach ($this->getElectionInvitations() as $electionInvitation) {
            if ($electionInvitation->getElectionCircular()->getElection() === $election) {
                return true;
            }
        }
        return false;
    }
100
101
102
103
104
105
106
107
108
109
110
111
112
113

    /**
     * @param Election $election
     * @return bool|ElectionInvitation
     */
    public function getElectionInvitationForElection(Election $election)
    {
        foreach ($this->getElectionInvitations() as $electionInvitation) {
            if ($electionInvitation->getElectionCircular()->getElection() === $election) {
                return $electionInvitation;
            }
        }
        return false;
    }
114
}