Completed
Push — master ( 13e33a...7c2796 )
by Vladimir
17s
created

Map::getActiveStatuses()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file contains functionality relating to a BZFS world file
4
 *
5
 * @package    BZiON\Models
6
 * @license    https://github.com/allejo/bzion/blob/master/LICENSE.md GNU General Public License Version 3
7
 */
8
9
/**
10
 * A BZFlag server map
11
 * @package    BZiON\Models
12
 */
13
class Map extends AvatarModel implements NamedModel
14
{
15
    /**
16
     * The name of the map
17
     * @var string
18
     */
19
    protected $name;
20
21
    /**
22
     * A description of the map
23
     * @var string
24
     */
25
    protected $description;
26
27
    /**
28
     * The number of a shots this map has
29
     * @var int
30
     */
31
    protected $shot_count;
32
33
    /**
34
     * Whether or not this map has ricochet
35
     * @var bool
36
     */
37
    protected $ricochet;
38
39
    /**
40
     * Whether or not this map has jumping
41
     * @var bool
42
     */
43
    protected $jumping;
44
45
    /**
46
     * The status of the map
47
     * @var string
48
     */
49
    protected $status;
50
51
    /**
52
     * The name of the database table used for queries
53
     */
54
    const TABLE = "maps";
55
56
    /**
57
     * The location where avatars will be stored
58
     */
59
    const AVATAR_LOCATION = "/web/assets/imgs/avatars/maps/";
60
61
    const CREATE_PERMISSION = Permission::ADD_MAP;
62
    const EDIT_PERMISSION = Permission::EDIT_MAP;
63
    const SOFT_DELETE_PERMISSION = Permission::SOFT_DELETE_MAP;
64
    const HARD_DELETE_PERMISSION = Permission::HARD_DELETE_MAP;
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    protected function assignResult($map)
70
    {
71
        $this->name = $map['name'];
72
        $this->description = $map['description'];
73
        $this->alias = $map['alias'];
74
        $this->avatar = $map['avatar'];
75
        $this->shot_count = $map['shot_count'];
76
        $this->ricochet = $map['ricochet'];
77
        $this->jumping = $map['jumping'];
78
        $this->status = $map['status'];
79
    }
80
81
    /**
82
     * Add a new map
83
     *
84
     * @param string      $name        The name of the map
85
     * @param string|null $alias       The custom API-friendly alias of the map
86
     * @param string      $description The description of the map
87 21
     * @param string|null $avatar      An image of the map
88
     * @param string      $status      The status of the map (active, hidden, disabled or deleted)
89 21
     *
90
     * @return static
91
     */
92
    public static function addMap($name, $alias = null, $description = '', $avatar = null, $status = 'active')
93
    {
94
        return self::create(array(
95
            'name'        => $name,
96
            'alias'       => $alias,
97
            'description' => $description,
98
            'avatar'      => $avatar,
99
            'status'      => $status
100
        ));
101
    }
102
103
    /**
104
     * Get the name of the map
105
     *
106
     * @return string
107
     */
108
    public function getName()
109
    {
110
        return $this->name;
111
    }
112
113
    /**
114
     * Get the description of the map
115
     *
116
     * @return string
117
     */
118
    public function getDescription()
119
    {
120
        return $this->description;
121
    }
122
123
    /**
124
     * Get the number of shots this map has
125
     *
126
     * @return int
127
     */
128
    public function getShotCount()
129
    {
130
        return $this->shot_count;
131
    }
132
133
    /**
134
     * Get whether or not ricochet is enabled
135
     *
136
     * @return bool
137
     */
138
    public function isRicochetEnabled()
139
    {
140
        return (bool)$this->ricochet;
141
    }
142
143
    /**
144
     * Get whether or not jumping is enabled
145
     *
146
     * @return bool
147
     */
148
    public function isJumpingEnabled()
149 1
    {
150
        return (bool)$this->jumping;
151 1
    }
152 1
153
    /**
154
     * Set the name of the map
155
     *
156
     * @param string $name The new name
157
     * @return self
158
     */
159
    public function setName($name)
160
    {
161
        return $this->updateProperty($this->name, 'name', $name);
162
    }
163
164
    /**
165
     * Set the description of the map
166
     *
167
     * @param string $description The new description
168
     * @return self
169
     */
170
    public function setDescription($description)
171
    {
172
        return $this->updateProperty($this->description, 'description', $description);
173
    }
174
175
    /**
176
     * Set the number of shots this map has
177
     *
178
     * @param int $shot_count
179
     *
180
     * @return self
181
     */
182
    public function setShotCount($shot_count)
183
    {
184
        return $this->updateProperty($this->shot_count, 'shot_count', $shot_count);
185
    }
186
187
    /**
188
     * Set whether or not this map supports ricochet
189
     *
190
     * @param bool $ricochet
191
     *
192
     * @return self
193
     */
194
    public function setRicochetEnabled($ricochet)
195
    {
196
        return $this->updateProperty($this->ricochet, 'ricochet', $ricochet);
197
    }
198
199
    /**
200
     * Set whether or not this map supports jumping
201
     *
202
     * @param bool $jumping
203
     *
204
     * @return self
205
     */
206
    public function setJumpingEnabled($jumping)
207
    {
208
        return $this->updateProperty($this->jumping, 'jumping', $jumping);
209
    }
210
211
    /**
212
     * Get the number of matches played on this map
213
     *
214
     * @return int
215
     */
216
    public function countMatches()
217
    {
218
        return Match::getQueryBuilder()
219
            ->active()
220
            ->where('map')->is($this)
221
            ->count();
222
    }
223
224
    /**
225
     * Get a query builder for news
226
     * @return QueryBuilder
227
     */
228 View Code Duplication
    public static function getQueryBuilder()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
229
    {
230
        return new QueryBuilder('Map', array(
231
            'columns' => array(
232
                'name'   => 'name',
233
                'status' => 'status'
234
            ),
235
            'name' => 'name'
236
        ));
237
    }
238
}
239