-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpectacle.php
More file actions
143 lines (126 loc) · 4.4 KB
/
Spectacle.php
File metadata and controls
143 lines (126 loc) · 4.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
class Spectacle
{
protected $db = null;
public function __construct($DB)
{
$this->db = $DB;
}
public function addSpectacle($spectacle_name)
{
if (count($this->db->selectCol('SELECT id FROM spectacles WHERE spectacle_name = ?',$spectacle_name))==0) {
$this->db->query('INSERT INTO spectacles(id,spectacle_name) VALUES(NULL,?)', $spectacle_name);
}
else
{
echo 'that spectacle('.$spectacle_name.') already exist<br>';
}
}
public function addRole($spectacle_name,$role_name)
{
$id_spectacle = $this->db->selectCell('SELECT id FROM spectacles WHERE spectacle_name = ?',$spectacle_name);
//$spectacleArray = $this->db->selectCol('SELECT spectacle_name FROM spectacles');
if (isset($id_spectacle)) {
if (count($this->db->selectCol('SELECT id FROM roles WHERE role = ?',$role_name)) == 0) {
$this->db->query("INSERT INTO roles(id,id_spectacle,role,id_session) VALUES(NULL,?,?,?)", $id_spectacle, $role_name, '');
}
else
{
echo 'that role ('.$role_name.') alredy exist in '.$spectacle_name.'<br>';
}
}
else
{
echo $spectacle_name.' not found<br >';
}
}
public function delRoleById($spectacle_id, $role_name)
{
}
public function delRole($spectacle_name,$role_name)
{
$id_spectacle = $this->db->selectCell('SELECT id FROM spectacles WHERE spectacle_name = ? LIMIT 1', $spectacle_name);
if (isset($id_spectacle)){
$id_role = $this->db->selectCell(
'SELECT id FROM roles WHERE id_spectacle = ? AND role = ?',
$id_spectacle,
$role_name
);
if ( isset($id_role) ) {
$this->db->query('DELETE FROM roles WHERE id = ?d', $id_role);
}
else
{
//throw new Exception('tra-ta-ta');
echo 'that role ('.$role_name.') does not exist<br>';
}
}
else
{
echo 'that spectacle ('.$spectacle_name.') does not exist<br>';
}
}
public function delSpectacle($spectacle_name)
{
$id_spectacle = $this->db->selectCell('SELECT id FROM spectacles WHERE spectacle_name = ? LIMIT 1',$spectacle_name);
if (isset($id_spectacle)){
$roles_array = $this->db->selectCol('SELECT role FROM roles WHERE id_spectacle = ?',$id_spectacle);
//if (count($roles_array)>0){
foreach($roles_array as $role){
$this->delRole($spectacle_name, $role);
}
//}
$this->db->query('DELETE FROM spectacles WHERE id = ?',$id_spectacle);
}
else
{
echo 'that spectacle ('.$spectacle_name.') does not exist<br>';
}
}
public function selectFreeRolesId($spectacle_name)
{
$id_spectacle = $this->db->selectCell('SELECT id FROM spectacles WHERE spectacle_name = ? LIMIT 1',$spectacle_name);
if ( isset($id_spectacle) ) {
$roleArray = $this->db->selectCol('SELECT id FROM roles WHERE id_spectacle = ? AND id_session = ""',$id_spectacle);
if (count($roleArray) == 0){
//all roles busy
return 0;
}
else
{
return $roleArray;
}
}
else
{
//spectacle not exist
return -1;
}
}
public function spectacleList()
{
$list = $this->db->selectCol('SELECT spectacle_name FROM spectacles');
if (count($list) > 0){
return $list;
}
else
{
//table of spectacles empty
return 0;
}
}
public function checkId($spectacle_name, $id_session)
{
$id_spectacle = $this->db->selectCell('SELECT id FROM spectacles WHERE spectacle_name = ?',$spectacle_name);
$role = $this->db->selectCell('SELECT role FROM roles WHERE id_spectacle = ? AND id_session = ?',$id_spectacle,$id_session);
return ( empty($role) ? 0 : $role );
}
public function setUserToRole($session, $role_id)
{
$this->db->query(
'UPDATE roles SET id_session=? WHERE id = ?d',
$session,
$role_id
);
}
}