GameReleaseScanDAO   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 128
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getScanTypes() 0 2 1
A getScan() 0 27 2
A __construct() 0 2 1
A addScanToRelease() 0 13 1
A deleteScan() 0 9 1
A getScansForRelease() 0 27 2
1
<?php
2
namespace AL\Common\DAO;
3
4
require_once __DIR__."/../../lib/Db.php" ;
5
require_once __DIR__."/../Model/Game/GameReleaseScan.php" ;
6
7
/**
8
 * DAO for Game Release Scans
9
 */
10
class GameReleaseScanDAO {
11
    private $mysqli;
12
13
    const TYPES = [
14
        "Box front", "Box back", "Goodie", "Other"
15
    ];
16
17
    public function __construct($mysqli) {
18
        $this->mysqli = $mysqli;
19
    }
20
21
    /**
22
     * Get the list of supported scan types
23
     *
24
     * @return string[] List of types
25
     */
26
    public function getScanTypes() {
27
        return self::TYPES;
28
    }
29
30
    /**
31
     * Add a scan to game release
32
     *
33
     * @param int $game_release_id ID of the release to add the scan to
34
     * @param string $type Type of scan
35
     * @param string $imgext Image extension
36
     *
37
     * @return int ID of the newly created scan
38
    */
39
    public function addScanToRelease($game_release_id, $type, $imgext, $notes) {
40
        $stmt = \AL\Db\execute_query(
41
            "GameReleaseScanDAO: addScanToRelease",
42
            $this->mysqli,
43
            "INSERT INTO game_release_scan (`game_release_id`, `type`, `imgext`, `notes`) VALUES (?, ?, ?, ?)",
44
            "isss", $game_release_id, $type, $imgext, $notes
45
        );
46
47
        $last_id = $stmt->insert_id;
48
49
        $stmt->close();
50
51
        return $last_id;
52
    }
53
54
    /**
55
     * Get all scans for a release
56
     *
57
     * @param int $game_release_id ID of the release to get scans for
58
     * @return \AL\Common\Model\Game\GameReleaseScan[] A list of scans
59
     */
60
    public function getScansForRelease($game_release_id) {
61
        $stmt = \AL\Db\execute_query(
62
            "GameReleaseScanDAO: getScansForRelease",
63
            $this->mysqli,
64
            "SELECT id, game_release_id, type, imgext, notes
65
            FROM game_release_scan
66
            WHERE game_release_id = ?",
67
            "i", $game_release_id
68
        );
69
70
        \AL\Db\bind_result(
71
            "GameReleaseScanDAO: getScansForRelease",
72
            $stmt,
73
            $id, $game_release_id, $type, $imgext, $notes
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $notes seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $type seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $imgext seems to be never defined.
Loading history...
74
        );
75
76
        $scans = [];
77
78
        while ($stmt->fetch()) {
79
            $scans[] = new \AL\Common\Model\Game\GameReleaseScan(
80
                $id, $game_release_id, $type, $imgext, $notes
81
            );
82
        }
83
84
        $stmt->close();
85
86
        return $scans;
87
    }
88
89
    /**
90
     * Retrieve a sing scan
91
     *
92
     * @param int $scan_id ID of the scan to retrieve
93
     * @return \AL\Common\Model\Game\GameReleaseScan A scan
94
     */
95
    public function getScan($scan_id) {
96
        $stmt = \AL\Db\execute_query(
97
            "GameReleaseScanDAO: getScan",
98
            $this->mysqli,
99
            "SELECT id, game_release_id, type, imgext, notes
100
            FROM game_release_scan
101
            WHERE id = ?",
102
            "i", $scan_id
103
        );
104
105
        \AL\Db\bind_result(
106
            "GameReleaseScanDAO: getScansForRelease",
107
            $stmt,
108
            $id, $game_release_id, $type, $imgext, $notes
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $game_release_id seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $notes seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $type seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $imgext seems to be never defined.
Loading history...
109
        );
110
111
        $scan = null;
112
113
        if ($stmt->fetch()) {
114
            $scan = new \AL\Common\Model\Game\GameReleaseScan(
115
                $id, $game_release_id, $type, $imgext, $notes
116
            );
117
        }
118
119
        $stmt->close();
120
121
        return $scan;
122
    }
123
124
    /**
125
     * Delete a scan
126
     *
127
     * @param int $scan_id ID of the scan to delete
128
     */
129
    public function deleteScan($scan_id) {
130
        $stmt = \AL\Db\execute_query(
131
            "GameReleaseScanDAO: deleteScan",
132
            $this->mysqli,
133
            "DELETE FROM game_release_scan WHERE id = ?",
134
            "i", $scan_id
135
        );
136
137
        $stmt->close();
138
    }
139
}
140