1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
* Created by PhpStorm. |
5
|
|
|
* User: benedikt |
6
|
|
|
* Date: 9/17/17 |
7
|
|
|
* Time: 11:35 AM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Tfboe\FmLib\Entity\Traits; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
14
|
|
|
use Doctrine\Common\Collections\Collection; |
15
|
|
|
use Doctrine\ORM\Mapping as ORM; |
16
|
|
|
use Tfboe\FmLib\Entity\CompetitionInterface; |
17
|
|
|
use Tfboe\FmLib\Entity\Helpers\NameEntity; |
18
|
|
|
use Tfboe\FmLib\Entity\Helpers\TimestampableEntity; |
19
|
|
|
use Tfboe\FmLib\Entity\Helpers\TournamentHierarchyInterface; |
20
|
|
|
use Tfboe\FmLib\Entity\TournamentInterface; |
21
|
|
|
use Tfboe\FmLib\Entity\UserInterface; |
22
|
|
|
use Tfboe\FmLib\Helpers\Level; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Trait Tournament |
26
|
|
|
* @package Tfboe\FmLib\Entity\Traits |
27
|
|
|
*/ |
28
|
|
|
trait Tournament |
29
|
|
|
{ |
30
|
|
|
use TimestampableEntity; |
31
|
|
|
use NameEntity; |
32
|
|
|
|
33
|
|
|
//<editor-fold desc="Fields"> |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @ORM\Column(type="string") |
37
|
|
|
* @var string |
38
|
|
|
*/ |
39
|
|
|
private $tournamentListId; |
40
|
|
|
/** |
41
|
|
|
* @ORM\ManyToOne(targetEntity="\Tfboe\FmLib\Entity\UserInterface") |
42
|
|
|
* @var UserInterface |
43
|
|
|
*/ |
44
|
|
|
private $creator; |
45
|
|
|
/** |
46
|
|
|
* @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\CompetitionInterface", mappedBy="tournament",indexBy="name") |
47
|
|
|
* @var Collection|CompetitionInterface[] |
48
|
|
|
*/ |
49
|
|
|
private $competitions; |
50
|
|
|
//</editor-fold desc="Fields"> |
51
|
|
|
|
52
|
|
|
//<editor-fold desc="Public Methods"> |
53
|
|
|
/** |
54
|
|
|
* @inheritDoc |
55
|
|
|
*/ |
56
|
|
|
public function getChildren(): Collection |
57
|
|
|
{ |
58
|
|
|
return $this->getCompetitions(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return CompetitionInterface[]|Collection |
63
|
|
|
*/ |
64
|
|
|
public function getCompetitions() |
65
|
|
|
{ |
66
|
|
|
return $this->competitions; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return UserInterface |
71
|
|
|
*/ |
72
|
|
|
public function getCreator(): UserInterface |
73
|
|
|
{ |
74
|
|
|
return $this->creator; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @inheritDoc |
79
|
|
|
*/ |
80
|
|
|
public function getLevel(): int |
81
|
|
|
{ |
82
|
|
|
return Level::TOURNAMENT; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @inheritDoc |
87
|
|
|
*/ |
88
|
|
|
public function getLocalIdentifier() |
89
|
|
|
{ |
90
|
|
|
return $this->getId(); |
|
|
|
|
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @inheritDoc |
95
|
|
|
*/ |
96
|
|
|
public function getParent(): ?TournamentHierarchyInterface |
97
|
|
|
{ |
98
|
|
|
return null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return string |
103
|
|
|
*/ |
104
|
|
|
public function getTournamentListId(): string |
105
|
|
|
{ |
106
|
|
|
return $this->tournamentListId; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* Tournament constructor. |
111
|
|
|
*/ |
112
|
|
|
protected final function init() |
113
|
|
|
{ |
114
|
|
|
$this->tournamentListId = ""; |
115
|
|
|
$this->competitions = new ArrayCollection(); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @param UserInterface $creator |
120
|
|
|
* @return TournamentInterface|Tournament |
121
|
|
|
*/ |
122
|
|
|
public function setCreator(UserInterface $creator) |
123
|
|
|
{ |
124
|
|
|
$this->creator = $creator; |
125
|
|
|
return $this; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param string $tournamentListId |
130
|
|
|
* @return TournamentInterface|Tournament |
131
|
|
|
*/ |
132
|
|
|
public function setTournamentListId(string $tournamentListId) |
133
|
|
|
{ |
134
|
|
|
$this->tournamentListId = $tournamentListId; |
135
|
|
|
return $this; |
136
|
|
|
} |
137
|
|
|
//</editor-fold desc="Public Methods"> |
138
|
|
|
} |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.