1
|
|
|
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
2
|
|
|
|
3
|
|
|
class Status_model extends CI_Model {
|
4
|
|
|
|
5
|
|
|
public function __construct() {
|
6
|
|
|
parent::__construct();
|
7
|
|
|
}
|
8
|
|
|
|
9
|
|
|
public function view() {
|
10
|
|
|
|
11
|
|
|
$this->db->order_by("category", "asc");
|
12
|
|
|
$this->db->order_by("name", "asc");
|
13
|
|
|
$query = $this->db->get('status');
|
14
|
|
|
return $query->result_array();
|
15
|
|
|
}
|
16
|
|
|
|
17
|
|
|
public function auto() {
|
18
|
|
|
|
19
|
|
|
$data = array(
|
|
|
|
|
20
|
|
|
'id', 'name', 'status', 'url', 'auto_status'
|
21
|
|
|
);
|
22
|
|
|
|
23
|
|
|
$query = $this->db->get('status');
|
24
|
|
|
return $query->result_array();
|
25
|
|
|
}
|
26
|
|
|
|
27
|
|
View Code Duplication |
public function auto_update_ok($service_id, $service_status) {
|
|
|
|
|
28
|
|
|
|
29
|
|
|
$data = array(
|
30
|
|
|
'auto_status' => $service_status,
|
31
|
|
|
);
|
32
|
|
|
|
33
|
|
|
$this->db->where('id', $service_id);
|
34
|
|
|
return $this->db->update('status', $data);
|
35
|
|
|
}
|
36
|
|
|
|
37
|
|
View Code Duplication |
public function auto_update_bad($service_id, $service_status) {
|
|
|
|
|
38
|
|
|
|
39
|
|
|
$data = array(
|
40
|
|
|
'auto_status' => $service_status,
|
41
|
|
|
);
|
42
|
|
|
|
43
|
|
|
$this->db->where('id', $service_id);
|
44
|
|
|
return $this->db->update('status', $data);
|
45
|
|
|
}
|
46
|
|
|
|
47
|
|
|
public function auto_update_timestamp($service_id) {
|
48
|
|
|
|
49
|
|
|
$data = array(
|
50
|
|
|
'status_since' => date("Y-m-d H:i:s", time()),
|
51
|
|
|
);
|
52
|
|
|
|
53
|
|
|
$this->db->where('id', $service_id);
|
54
|
|
|
return $this->db->update('status', $data);
|
55
|
|
|
}
|
56
|
|
|
|
57
|
|
|
public function log($service_id, $service_status) {
|
58
|
|
|
|
59
|
|
|
$data = array(
|
60
|
|
|
'sid' => $service_id,
|
61
|
|
|
'auto_status' => $service_status
|
62
|
|
|
);
|
63
|
|
|
|
64
|
|
|
return $this->db->insert('status_logs', $data);
|
65
|
|
|
}
|
66
|
|
|
|
67
|
|
|
public function percentage($sid) {
|
68
|
|
|
|
69
|
|
|
$this->db->select('sid');
|
70
|
|
|
$this->db->where('sid', $sid);
|
71
|
|
|
$this->db->order_by('id', 'DESC');
|
72
|
|
|
$this->db->limit('5000');
|
73
|
|
|
$this->db->from('status_logs');
|
74
|
|
|
$total = $this->db->get()->num_rows();
|
75
|
|
|
|
76
|
|
|
$this->db->select('sid');
|
77
|
|
|
$this->db->where('sid', $sid);
|
78
|
|
|
$this->db->where('auto_status', 1);
|
79
|
|
|
$this->db->order_by('id', 'DESC');
|
80
|
|
|
$this->db->limit('5000');
|
81
|
|
|
$this->db->from('status_logs');
|
82
|
|
|
$up = $this->db->get()->num_rows();
|
83
|
|
|
|
84
|
|
|
if (empty($total)) {
|
85
|
|
|
|
86
|
|
|
$percentage = 'No Data';
|
87
|
|
|
return $percentage;
|
88
|
|
|
|
89
|
|
|
} else {
|
90
|
|
|
|
91
|
|
|
$percentage = round($up / $total * 100, 1).'%';
|
92
|
|
|
return $percentage;
|
93
|
|
|
|
94
|
|
|
}
|
95
|
|
|
|
96
|
|
|
}
|
97
|
|
|
|
98
|
|
|
public function reset($sid) {
|
99
|
|
|
|
100
|
|
|
$this->db->select('sid');
|
101
|
|
|
$this->db->where('sid', $sid);
|
102
|
|
|
$this->db->from('status_logs');
|
103
|
|
|
$this->db->delete();
|
104
|
|
|
|
105
|
|
|
}
|
106
|
|
|
|
107
|
|
|
public function edit_get($sid) {
|
108
|
|
|
|
109
|
|
|
$this->db->select();
|
110
|
|
|
$this->db->where('id', $sid);
|
111
|
|
|
$this->db->from('status');
|
112
|
|
|
$query = $this->db->get();
|
113
|
|
|
return $query->result_array();
|
114
|
|
|
}
|
115
|
|
|
|
116
|
|
|
public function edit_update($id, $name, $icon, $url, $comment, $category, $status, $username) {
|
117
|
|
|
|
118
|
|
|
if (empty($comment)) {
|
119
|
|
|
$comment = 'No information available';
|
120
|
|
|
}
|
121
|
|
|
|
122
|
|
|
$data = array(
|
123
|
|
|
'name' => $name,
|
124
|
|
|
'icon' => $icon,
|
125
|
|
|
'url' => $url,
|
126
|
|
|
'comments' => $comment,
|
127
|
|
|
'category' => $category,
|
128
|
|
|
'status' => $status,
|
129
|
|
|
'auto_status' => $status,
|
130
|
|
|
'last_update' => date("Y-m-d H:i:s", time()),
|
131
|
|
|
'by' => $username,
|
132
|
|
|
);
|
133
|
|
|
|
134
|
|
|
$this->db->where('id', $id);
|
135
|
|
|
return $this->db->update('status', $data);
|
136
|
|
|
}
|
137
|
|
|
|
138
|
|
|
public function create($name, $icon, $url, $category, $status) {
|
139
|
|
|
|
140
|
|
|
$data = array(
|
141
|
|
|
'name' => $name,
|
142
|
|
|
'icon' => $icon,
|
143
|
|
|
'url' => $url,
|
144
|
|
|
'category' => $category,
|
145
|
|
|
'status' => $status,
|
146
|
|
|
'auto_status' => $status,
|
147
|
|
|
'last_update' => date("Y-m-d H:i:s", time()),
|
148
|
|
|
'by' => $username,
|
|
|
|
|
149
|
|
|
);
|
150
|
|
|
|
151
|
|
|
return $this->db->insert('status', $data);
|
152
|
|
|
}
|
153
|
|
|
|
154
|
|
|
public function delete($sid) {
|
155
|
|
|
|
156
|
|
|
$this->db->select('sid');
|
157
|
|
|
$this->db->where('sid', $sid);
|
158
|
|
|
$this->db->from('status_logs');
|
159
|
|
|
$this->db->delete();
|
160
|
|
|
|
161
|
|
|
$this->db->select('id');
|
162
|
|
|
$this->db->where('id', $sid);
|
163
|
|
|
$this->db->from('status');
|
164
|
|
|
$this->db->delete();
|
165
|
|
|
|
166
|
|
|
}
|
167
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.