Track.php 3.54 KB
Newer Older
martin's avatar
track    
martin committed
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\TrackRepository")
 */
class Track
{
    /**
     * @ORM\Id()
14
     * @ORM\GeneratedValue()
martin's avatar
track    
martin committed
15
16
     * @ORM\Column(type="integer")
     */
Clouard Regis's avatar
Clouard Regis committed
17
    private ?int $id;
martin's avatar
track    
martin committed
18
19
20
21

    /**
     * @ORM\Column(type="string", length=255)
     */
Clouard Regis's avatar
Clouard Regis committed
22
    private ?string $name;
martin's avatar
track    
martin committed
23

Clouard Regis's avatar
Clouard Regis committed
24
25
26
    /**
     * @ORM\Column(type="integer")
     */
Clouard Regis's avatar
Clouard Regis committed
27
    private ?int $format;
Clouard Regis's avatar
Clouard Regis committed
28

martin's avatar
track    
martin committed
29
30
31
    /**
     * @ORM\Column(type="integer")
     */
Clouard Regis's avatar
Clouard Regis committed
32
    private ?int $totalTime;
martin's avatar
track    
martin committed
33
34
35
36

    /**
     * @ORM\Column(type="array")
     */
Clouard Regis's avatar
Clouard Regis committed
37
    private array $controlPoints = [];
martin's avatar
track    
martin committed
38
39
40
41

    /**
     * @ORM\Column(type="text")
     */
Clouard Regis's avatar
Clouard Regis committed
42
    private ?string $trace;
martin's avatar
track    
martin committed
43
44
45
46
47

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Course", inversedBy="orienteer")
     * @ORM\JoinColumn(nullable=false)
     */
Clouard Regis's avatar
Clouard Regis committed
48
    private ?Course $course;
martin's avatar
track    
martin committed
49

50
51
52
53
54
    /**
     * @ORM\Column(type="boolean")
     */
    private bool $imported = false;

SuliacLavenant's avatar
SuliacLavenant committed
55
56
57
    /**
     * @ORM\OneToMany(targetEntity="App\Entity\ParticipantMakeEventCourse", mappedBy="track")
     */
Regis's avatar
Regis committed
58
    private ?ParticipantMakeEventCourse $ParticipantMakeEventCourses;
SuliacLavenant's avatar
SuliacLavenant committed
59

martin's avatar
track    
martin committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
    public function getId(): ?int
    {
        return $this->id;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

    public function setName(string $name): self
    {
        $this->name = $name;

        return $this;
    }

Clouard Regis's avatar
Clouard Regis committed
77
78
79
80
81
82
83
84
85
86
87
88
    public function getFormat(): ?int
    {
        return $this->format;
    }

    public function setFormat(int $format): self
    {
        $this->format = $format;

        return $this;
    }

martin's avatar
track    
martin committed
89
90
91
92
93
    public function getTotalTime(): ?int
    {
        return $this->totalTime;
    }

Regis's avatar
Regis committed
94
    public function getTotalTimeAsString(): string
95
96
    {
        $sec = (int)($this->totalTime / 1000);
Regis's avatar
Regis committed
97
        $hrs = 0;
98
99
100
        $min = 0;

        if ($sec >= 3600) {
Regis's avatar
Regis committed
101
            $hrs = floor($sec / 3600);
102
103
104
105
106
107
108
            $sec = $sec % 3600;
        }
        if ($sec >= 60) {
            $min = floor($sec / 60);
            $sec = $sec % 60;
        }

Regis's avatar
Regis committed
109
110
        if (strlen((string)$hrs) === 1) {
            $hrs = "0".$hrs;
111
112
113
114
115
116
117
118
        }
        if (strlen((string)$min) === 1) {
            $min = "0".$min;
        }
        if (strlen((string)$sec) === 1) {
            $sec = "0".$sec;
        }

Regis's avatar
Regis committed
119
        return $hrs.":".$min.":".$sec;
120
121
    }

martin's avatar
track    
martin committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
    public function setTotalTime(int $totalTime): self
    {
        $this->totalTime = $totalTime;

        return $this;
    }

    public function getControlPoints(): ?array
    {
        return $this->controlPoints;
    }

    public function setControlPoints(array $controlPoints): self
    {
        $this->controlPoints = $controlPoints;

        return $this;
    }

    public function getTrace(): ?string
    {
        return $this->trace;
    }

    public function setTrace(string $trace): self
    {
        $this->trace = $trace;

        return $this;
    }

    public function getCourse(): ?Course
    {
        return $this->course;
    }

    public function setCourse(?Course $course): self
    {
        $this->course = $course;

        return $this;
    }
164
165
166
167
168
169
170
171
172
173
174
175

    public function getImported(): ?bool
    {
        return $this->imported;
    }

    public function setImported(bool $imported): self
    {
        $this->imported = $imported;

        return $this;
    }
SuliacLavenant's avatar
SuliacLavenant committed
176

Regis's avatar
Regis committed
177
    public function nbPM(): int
SuliacLavenant's avatar
SuliacLavenant committed
178
179
180
181
182
183
184
185
186
187
188
    {
        $pm = 0;
        foreach ($this->controlPoints as $controlPoint) {
            if ($controlPoint->controlPoint !== 0) {
                if ($controlPoint->punchTime === 0) {
                    $pm+=1;
                }
            }
        }
        return $pm;
    }
martin's avatar
track    
martin committed
189
}