ResolutionDAO::setResolutionsForRelease()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 2
dl 0
loc 18
rs 9.8666
c 0
b 0
f 0
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Game/Resolution.php" ;
6
7
/**
8
 * DAO for resolutions
9
 */
10
class ResolutionDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all resolutions
19
     *
20
     * @return \AL\Common\Model\Game\Resolution[] An array of resolutions
21
     */
22
    public function getAllResolutions() {
23
        $stmt = \AL\Db\execute_query(
24
            "ResolutionDAO: getAllResolutions",
25
            $this->mysqli,
26
            "SELECT id, name FROM resolution ORDER BY id",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "ResolutionDAO: getAllResolutions",
32
            $stmt,
33
            $id, $name
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
34
        );
35
36
        $resolutions = [];
37
        while ($stmt->fetch()) {
38
            $resolutions[] = new \AL\Common\Model\Game\Resolution(
39
                $id, $name
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $resolutions;
46
    }
47
48
    /**
49
     * Get a map containing all resolutions, indexed by ID
50
     *
51
     * @return \AL\Common\Model\Game\Resolution[] A map of resolutions
52
     */
53
    public function getAllResolutionsAsMap() {
54
        $resolutions = $this->getAllResolutions();
55
        $resolutionsMap = array();
56
        foreach ($resolutions as $resolution) {
57
            $resolutionsMap[$resolution->getId()] = $resolution;
58
        }
59
60
        return $resolutionsMap;
61
    }
62
63
    /**
64
     * Get list of resolution IDs for a release
65
     *
66
     * @param integer Release ID
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\Release was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
67
     */
68
    public function getResolutionsForRelease($release_id) {
69
        $stmt = \AL\Db\execute_query(
70
            "ResolutionDAO: getResolutionsForRelease",
71
            $this->mysqli,
72
            "SELECT resolution_id FROM game_release_resolution WHERE game_release_id = ?",
73
            "i", $release_id
74
        );
75
76
        \AL\Db\bind_result(
77
            "ResolutionDAO: getResolutionsForRelease",
78
            $stmt,
79
            $resolution_id
80
        );
81
82
        $resolutions = [];
83
        while ($stmt->fetch()) {
84
            $resolutions[] = $resolution_id;
85
        }
86
87
        $stmt->close();
88
89
        return $resolutions;
90
    }
91
92
    /**
93
     * Set the list of resolutions supported by a release
94
     *
95
     * @param integer Release ID
96
     * @param integer[] List of resolution IDs
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\List was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
97
     */
98
99
    public function setResolutionsForRelease($release_id, $resolutions) {
100
        $stmt = \AL\Db\execute_query(
101
            "ResolutionDAO: setResolutionsForRelease",
102
            $this->mysqli,
103
            "DELETE FROM game_release_resolution WHERE game_release_id = ?",
104
            "i", $release_id
105
        );
106
107
        foreach ($resolutions as $id) {
108
            $stmt = \AL\Db\execute_query(
109
                "ResolutionDAO: setResolutionsForRelease",
110
                $this->mysqli,
111
                "INSERT INTO game_release_resolution (game_release_id, resolution_id) VALUES (?, ?)",
112
                "ii", $release_id, $id
113
            );
114
        }
115
116
        $stmt->close();
117
    }
118
    
119
     /**
120
     * add a resolution to the database
121
     *
122
     * @param varchar resolution
123
     */
124
    public function addResolution($resolution) {
125
        $stmt = \AL\Db\execute_query(
126
            "ResolutionDAO: addResolution",
127
            $this->mysqli,
128
            "INSERT INTO resolution (`name`) VALUES (?)",
129
            "s", $resolution
130
        );
131
132
        $stmt->close();
133
    }
134
    
135
    /**
136
     * delete a resolution
137
     *
138
     * @param int resolution_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\resolution_id was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
139
     */
140
    public function deleteResolution($resolution_id) {
141
        $stmt = \AL\Db\execute_query(
142
            "ResolutionDAO: deleteResolution",
143
            $this->mysqli,
144
            "DELETE FROM resolution WHERE id = ?",
145
            "i", $resolution_id
146
        );
147
148
        $stmt->close();
149
    }
150
    
151
        /**
152
     * update a resolution
153
     *
154
     * @param int resolution_id
155
     * @param varchar resolution_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\resolution_name was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
156
     */
157
    public function updateResolution($resolution_id, $resolution_name) {
158
        $stmt = \AL\Db\execute_query(
159
            "ResolutionDAO: updateResolution",
160
            $this->mysqli,
161
            "UPDATE resolution SET name = ? WHERE id = ?",
162
            "si", $resolution_name, $resolution_id
163
        );
164
        
165
        $stmt->close();
166
    }
167
}
168