Completed
Push — fm-support ( 22a3ee...72ded1 )
by Konstantinos
04:30
created

Map::countMatches()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 1
cp 0
rs 9.4285
cc 1
eloc 5
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 status of the map
29
     * @var string
30
     */
31
    protected $status;
32
33
    /**
34
     * The name of the database table used for queries
35
     */
36
    const TABLE = "maps";
37
38
    /**
39
     * The location where avatars will be stored
40
     */
41
    const AVATAR_LOCATION = "/web/assets/imgs/avatars/maps/";
42
43
    const CREATE_PERMISSION = Permission::ADD_MAP;
44
    const EDIT_PERMISSION = Permission::EDIT_MAP;
45
    const SOFT_DELETE_PERMISSION = Permission::SOFT_DELETE_MAP;
46
    const HARD_DELETE_PERMISSION = Permission::HARD_DELETE_MAP;
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 View Code Duplication
    protected function assignResult($map)
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...
52
    {
53
        $this->name = $map['name'];
54
        $this->description = $map['description'];
55
        $this->alias = $map['alias'];
56
        $this->avatar = $map['avatar'];
57
        $this->status = $map['status'];
58
    }
59
60
    /**
61
     * Add a new map
62
     *
63
     * @param string      $name        The name of the map
64
     * @param string|null $alias       The custom API-friendly alias of the map
65
     * @param string      $description The description of the map
66
     * @param string|null $avatar      An image of the map
67
     * @param string      $status      The status of the map (active, hidden, disabled or deleted)
68
     *
69
     * @return static
70
     */
71
    public static function addMap($name, $alias = null, $description = '', $avatar = null, $status = 'active')
72
    {
73
        return self::create(array(
74
            'name'        => $name,
75
            'alias'       => $alias,
76
            'description' => $description,
77
            'avatar'      => $avatar,
78
            'status'      => $status
79
        ));
80
    }
81
82
    /**
83
     * Get the name of the map
84
     *
85
     * @return string
86
     */
87
    public function getName()
88
    {
89
        return $this->name;
90
    }
91
92
    /**
93
     * Get the description of the map
94
     *
95
     * @return string
96
     */
97
    public function getDescription()
98
    {
99
        return $this->description;
100
    }
101
102
    /**
103
     * Set the name of the map
104
     *
105
     * @param string $name The new name
106
     * @return self
107
     */
108
    public function setName($name)
109
    {
110
        return $this->updateProperty($this->name, 'name', $name);
111
    }
112
113
    /**
114
     * Set the description of the map
115
     *
116
     * @param string $description The new description
117
     * @return self
118
     */
119
    public function setDescription($description)
120
    {
121
        return $this->updateProperty($this->description, 'description', $description);
122
    }
123
124
    /**
125
     * Get the number of matches played on this map
126
     *
127
     * @return int
128
     */
129
    public function countMatches()
130
    {
131
        return Match::getQueryBuilder()
132
            ->active()
133
            ->where('map')->is($this)
134
            ->count();
135
    }
136 1
137
    /**
138 1
     * {@inheritdoc}
139
     */
140
    public static function getActiveStatuses()
141
    {
142 1
        return array('active');
143
    }
144
145
    /**
146
     * Get a query builder for news
147
     * @return QueryBuilder
148
     */
149 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...
150
    {
151
        return new QueryBuilder('Map', array(
152
            'columns' => array(
153
                'name'   => 'name',
154
                'status' => 'status'
155
            ),
156
            'name' => 'name'
157
        ));
158
    }
159
}
160