MediaDAO::addMediaToRelease()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 0
loc 9
rs 10
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/Dump/Media.php" ;
6
require_once __DIR__."/../Model/Dump/MediaType.php" ;
7
8
/**
9
 * DAO for Media
10
 */
11
class MediaDAO {
12
    private $mysqli;
13
14
    public function __construct($mysqli) {
15
        $this->mysqli = $mysqli;
16
    }
17
18
    /**
19
     * Get all Media from Release
20
     *
21
     * @return \AL\Common\Model\Dump\Media[] An array of media
22
     */
23
    public function getAllMediaFromRelease($release_id) {
24
        $stmt = \AL\Db\execute_query(
25
            "MediaTypeDAO: getAllMediaFromRelease",
26
            $this->mysqli,
27
            "SELECT media.id, media.label, media.media_type_id, media_type.name FROM media
28
            LEFT JOIN media_type ON (media.media_type_id = media_type.id)
29
            WHERE release_id = ? order by media.media_type_id, media.id",
30
            "i", $release_id
31
        );
32
33
        \AL\Db\bind_result(
34
            "MediaDAO: getAllMediaFromRelease",
35
            $stmt,
36
            $id, $label, $type_id, $name
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $name seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $label seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $type_id seems to be never defined.
Loading history...
37
        );
38
39
        $media = [];
40
        while ($stmt->fetch()) {
41
            $media[] = new \AL\Common\Model\Dump\Media(
42
                $id, $label,
43
                ($type_id != null)
44
                    ? new \AL\Common\Model\dump\MediaType($type_id, $name)
45
                    : null
46
            );
47
        }
48
49
        $stmt->close();
50
51
        return $media;
52
    }
53
54
     /**
55
     * Add a media to a release
56
     *
57
     * @param int release_id
58
     * @param int media_type_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\media_type_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...
59
     */
60
    public function addMediaToRelease($release_id, $type_id, $label) {
61
        $stmt = \AL\Db\execute_query(
62
            "MediaDAO: AddMediaToRelease",
63
            $this->mysqli,
64
            "INSERT INTO media (`release_id`, `media_type_id`, `label` ) VALUES (?, ?, ?)",
65
            "iis", $release_id, $type_id, $label
66
        );
67
68
        $stmt->close();
69
    }
70
71
     /**
72
     * delete a media from a release
73
     *
74
     * @param int media_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\media_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...
75
     */
76
    public function deleteMediaFromRelease($media_id) {
77
        $stmt = \AL\Db\execute_query(
78
            "MediaDAO: deleteMediaToRelease",
79
            $this->mysqli,
80
            "DELETE FROM media WHERE id = ?",
81
            "i", $media_id
82
        );
83
84
        $stmt->close();
85
    }
86
87
     /**
88
     * update a media label
89
     *
90
     * @param int media_id
91
     * @param varchar label
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\label 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...
92
     */
93
    public function updateMedia($media_id, $label, $media_type_id) {
94
        $stmt = \AL\Db\execute_query(
95
            "MediaDAO: setLabelFromMedia",
96
            $this->mysqli,
97
            "UPDATE media SET label = ?, media_type_id = ? WHERE id = ?",
98
            "sii", $label, $media_type_id, $media_id
99
        );
100
101
        $stmt->close();
102
    }
103
}
104