IndividualRoleDAO::getAllIndividualRoles()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 15
nc 2
nop 0
dl 0
loc 24
rs 9.7666
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/Individual/IndividualRole.php" ;
6
7
/**
8
 * DAO for Individual Roles
9
 */
10
class IndividualRoleDAO {
11
    private $mysqli;
12
13
    public function __construct($mysqli) {
14
        $this->mysqli = $mysqli;
15
    }
16
17
    /**
18
     * Get all Roles
19
     *
20
     * @return \AL\Common\Model\Individual\IndividualRole[] An array of genres
21
     */
22
    public function getAllIndividualRoles() {
23
        $stmt = \AL\Db\execute_query(
24
            "IndividualRoleDAO: getAllIndividualRoles",
25
            $this->mysqli,
26
            "SELECT id, name FROM individual_role ORDER BY name",
27
            null, null
28
        );
29
30
        \AL\Db\bind_result(
31
            "IndividualRoleDAO: getAllIndividualRoles",
32
            $stmt,
33
            $id, $role
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $role seems to be never defined.
Loading history...
34
        );
35
36
        $individual_roles = [];
37
        while ($stmt->fetch()) {
38
            $individual_roles[] = new \AL\Common\Model\Individual\IndividualRole(
39
                $id, $role
40
            );
41
        }
42
43
        $stmt->close();
44
45
        return $individual_roles;
46
    }
47
    
48
    /**
49
     * Get role for a role id
50
     *
51
     * @param integer role ID
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\role 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...
52
     */
53
    public function getRoleForId($id) {
54
        $stmt = \AL\Db\execute_query(
55
            "IndividualRoleDAO: getRoleForId",
56
            $this->mysqli,
57
            "SELECT id, name
58
            FROM individual_role 
59
            WHERE id = ?",
60
            "i", $id
61
        );
62
63
        \AL\Db\bind_result(
64
            "IndividualRoleDAO: getRoleForId",
65
            $stmt,
66
            $id, $role
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $role seems to be never defined.
Loading history...
67
        );
68
69
        $individual_roles = null;
70
        while ($stmt->fetch()) {
71
            $individual_roles = new \AL\Common\Model\Individual\IndividualRole(
72
                $id, $role
73
            );
74
        }
75
76
        $stmt->close();
77
78
        return $individual_roles;
79
    }
80
    
81
    /**
82
     * add a role to the database
83
     *
84
     * @param varchar role
85
     */
86
    public function addIndividualRole($role) {
87
        $stmt = \AL\Db\execute_query(
88
            "IndividualRoleDAO: addIndividualRole",
89
            $this->mysqli,
90
            "INSERT INTO individual_role (`name`) VALUES (?)",
91
            "s", $role
92
        );
93
94
        $stmt->close();
95
    }
96
    
97
    /**
98
     * delete a role
99
     *
100
     * @param int role_id
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\role_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...
101
     */
102
    public function deleteIndividualRole($role_id) {
103
        $stmt = \AL\Db\execute_query(
104
            "IndividualRoleDAO: deleteIndividualRole",
105
            $this->mysqli,
106
            "DELETE FROM individual_role WHERE id = ?",
107
            "i", $role_id
108
        );
109
110
        $stmt->close();
111
    }
112
    
113
        /**
114
     * update a role
115
     *
116
     * @param int role_id
117
     * @param varchar role_name
0 ignored issues
show
Bug introduced by
The type AL\Common\DAO\role_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...
118
     */
119
    public function updateIndividualRole($role_id, $role_name) {
120
        $stmt = \AL\Db\execute_query(
121
            "IndividualRoleDAO: updateIndividualRole",
122
            $this->mysqli,
123
            "UPDATE individual_role SET name = ? WHERE id = ?",
124
            "si", $role_name, $role_id
125
        );
126
        
127
        $stmt->close();
128
    }
129
}
130