Completed
Push — master ( 685463...a3ac99 )
by Benedikt
13:47
created

Competition::getChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
rs 10
1
<?php
2
declare(strict_types=1);
3
/**
4
 * Created by PhpStorm.
5
 * User: benedikt
6
 * Date: 10/15/17
7
 * Time: 10:57 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\TournamentHierarchyInterface;
19
use Tfboe\FmLib\Entity\PhaseInterface;
20
use Tfboe\FmLib\Entity\Team;
21
use Tfboe\FmLib\Entity\TournamentInterface;
22
use Tfboe\FmLib\Helpers\Level;
23
24
25
/**
26
 * Trait Competition
27
 * @package Tfboe\FmLib\Entity\Traits
28
 */
29
trait Competition
30
{
31
  use NameEntity;
32
33
//<editor-fold desc="Fields">
34
  /**
35
   * @ORM\ManyToOne(targetEntity="\Tfboe\FmLib\Entity\TournamentInterface", inversedBy="competitions")
36
   * @var TournamentInterface
37
   */
38
  private $tournament;
39
40
  /**
41
   * @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\Team", mappedBy="competition", indexBy="startNumber")
42
   * @var Collection|Team[]
43
   */
44
  private $teams;
45
46
  /**
47
   * @ORM\OneToMany(targetEntity="\Tfboe\FmLib\Entity\PhaseInterface", mappedBy="competition", indexBy="phaseNumber")
48
   * @var Collection|PhaseInterface[]
49
   */
50
  private $phases;
51
//</editor-fold desc="Fields">
52
53
//<editor-fold desc="Public Methods">
54
  /**
55
   * @inheritDoc
56
   */
57
  public function getChildren(): Collection
58
  {
59
    return $this->getPhases();
60
  }
61
62
  /**
63
   * @inheritDoc
64
   */
65
  public function getLevel(): int
66
  {
67
    return Level::COMPETITION;
68
  }
69
70
  /**
71
   * @inheritDoc
72
   */
73
  public function getLocalIdentifier()
74
  {
75
    return $this->getName();
76
  }
77
78
  /**
79
   * @inheritDoc
80
   */
81
  public function getParent(): ?TournamentHierarchyInterface
82
  {
83
    return $this->getTournament();
84
  }
85
86
  /**
87
   * @return PhaseInterface[]|Collection
88
   */
89
  public function getPhases()
90
  {
91
    return $this->phases;
92
  }
93
94
  /**
95
   * @return Team[]|Collection
96
   */
97
  public function getTeams()
98
  {
99
    return $this->teams;
100
  }
101
102
  /**
103
   * @return TournamentInterface
104
   */
105
  public function getTournament(): TournamentInterface
106
  {
107
    return $this->tournament;
108
  }
109
110
  /**
111
   * Competition constructor.
112
   */
113
  public function init()
114
  {
115
    $this->teams = new ArrayCollection();
116
    $this->phases = new ArrayCollection();
117
  }
118
119
  /**
120
   * @param TournamentInterface $tournament
121
   * @return $this|CompetitionInterface|Competition
122
   */
123
  public function setTournament(TournamentInterface $tournament)
124
  {
125
    if ($this->tournament !== null) {
126
      $this->tournament->getCompetitions()->remove($this->getName());
127
    }
128
    $this->tournament = $tournament;
129
    $tournament->getCompetitions()->set($this->getName(), $this);
130
    return $this;
131
  }
132
//</editor-fold desc="Public Methods">
133
}