Passed
Push — master ( f8d49f...a1d922 )
by Saepul
02:10
created

Tickets::update_ticket()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 2
eloc 24
c 1
b 1
f 0
nc 2
nop 18
dl 0
loc 27
rs 9.536

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
date_default_timezone_set('Asia/Jakarta');
4
class Tickets
5
{
6
    private $db;
7
8
    public function __construct($database)
9
    {
10
        $this->db = $database;
11
    }
12
13
    public function add_ticket($ticketnumber, $sla, $reporteddate, $reportedby, $telp, $email, $problemsummary, $problemdetail, $ticketstatus, $assignee, $documentedby, $pro)
14
    {
15
        $current = time();
16
        $querystring = 'INSERT INTO `tickets` (`ticketnumber`,`sla`,`reporteddate`, `reportedby`, `telp`, `email`, `problemsummary`,`problemdetail`,`ticketstatus`,`assignee`,`documentedby`,`documenteddate`,`pro`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
17
        $query = $this->db->prepare($querystring);
18
        $query->bindValue(1, $ticketnumber);
19
        $query->bindValue(2, $sla);
20
        $query->bindValue(3, $reporteddate);
21
        $query->bindValue(4, $reportedby);
22
        $query->bindValue(5, $telp);
23
        $query->bindValue(6, $email);
24
        $query->bindValue(7, $problemsummary);
25
        $query->bindValue(8, $problemdetail);
26
        $query->bindValue(9, $ticketstatus);
27
        $query->bindValue(10, $assignee);
28
        $query->bindValue(11, $documentedby);
29
        $query->bindValue(12, $current);
30
        $query->bindValue(13, $pro);
31
32
        try {
33
            $query->execute();
34
        } catch (PDOException $e) {
35
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
36
        }
37
    }
38
39
    public function update_ticket($id, $sla, $reporteddate, $reportedby, $telp, $email, $problemsummary, $problemdetail, $ticketstatus, $assignee, $assigneddate, $pendingby, $pendingdate, $resolution, $resolvedby, $resolveddate, $closedby, $closeddate)
40
    {
41
        $querystring = 'UPDATE `tickets` SET `sla` = ? , `reporteddate` = ? , `reportedby` = ? , `telp` = ? ,`email` = ? , `problemsummary` = ? , `problemdetail` = ? ,`ticketstatus` = ?, `assignee` = ? , `assigneddate` = ?, `pendingby` = ?,`pendingdate` = ?, `resolution` = ? ,`resolvedby` = ?,`resolveddate` = ?,`closedby` = ?,`closeddate` = ? WHERE `id` = ?';
42
        $query = $this->db->prepare($querystring);
43
        $query->bindValue(1, $sla);
44
        $query->bindValue(2, $reporteddate);
45
        $query->bindValue(3, $reportedby);
46
        $query->bindValue(4, $telp);
47
        $query->bindValue(5, $email);
48
        $query->bindValue(6, $problemsummary);
49
        $query->bindValue(7, $problemdetail);
50
        $query->bindValue(8, $ticketstatus);
51
        $query->bindValue(9, $assignee);
52
        $query->bindValue(10, $assigneddate);
53
        $query->bindValue(11, $pendingby);
54
        $query->bindValue(12, $pendingdate);
55
        $query->bindValue(13, $resolution);
56
        $query->bindValue(14, $resolvedby);
57
        $query->bindValue(15, $resolveddate);
58
        $query->bindValue(16, $closedby);
59
        $query->bindValue(17, $closeddate);
60
        $query->bindValue(18, $id);
61
62
        try {
63
            $query->execute();
64
        } catch (PDOException $e) {
65
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
66
        }
67
    }
68
69
    public function delete($id)
70
    {
71
        $sql = 'DELETE FROM `tickets` WHERE `id` = ?';
72
        $query = $this->db->prepare($sql);
73
        $query->bindValue(1, $id);
74
75
        try {
76
            $query->execute();
77
        } catch (PDOException $e) {
78
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
79
        }
80
    }
81
82
    public function ticket_data($id)
83
    {
84
        $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `id`= ?');
85
        $query->bindValue(1, $id);
86
87
        try {
88
            $query->execute();
89
90
            return $query->fetch();
91
        } catch (PDOException $e) {
92
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
93
        }
94
    }
95
96
    public function get_tickets()
97
    {
98
        $query = $this->db->prepare('SELECT * FROM `tickets` ORDER BY `ticketnumber` DESC');
99
100
        try {
101
            $query->execute();
102
        } catch (PDOException $e) {
103
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
104
        }
105
106
        return $query->fetchAll();
107
    }
108
109
    public function get_pro()
110
    {
111
        $query = $this->db->prepare('SELECT pro FROM `tickets`');
112
113
        try {
114
            $query->execute();
115
        } catch (PDOException $e) {
116
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
117
        }
118
119
        return $query->fetchAll();
120
    }
121
122
    public function get_opened_tickets()
123
    {
124
        $query = $this->db->prepare("SELECT * FROM `tickets` WHERE `ticketstatus` <> 'Closed' ORDER BY `ticketnumber` DESC");
125
126
        try {
127
            $query->execute();
128
        } catch (PDOException $e) {
129
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
130
        }
131
132
        return $query->fetchAll();
133
    }
134
135
    public function get_tickets_by_requester($userid)
136
    {
137
        $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `documentedby`= ? ORDER BY `ticketnumber` DESC');
138
        $query->bindValue(1, $userid);
139
140
        try {
141
            $query->execute();
142
        } catch (PDOException $e) {
143
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
144
        }
145
146
        return $query->fetchAll();
147
    }
148
149
    public function get_tickets_by_assignee($userid)
150
    {
151
        $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `assignee`= ? ORDER BY `ticketnumber` DESC');
152
        $query->bindValue(1, $userid);
153
154
        try {
155
            $query->execute();
156
        } catch (PDOException $e) {
157
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
158
        }
159
160
        return $query->fetchAll();
161
    }
162
163
    public function get_tickets_by_resolver($username)
164
    {
165
        $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `resolvedby`= ? ORDER BY `ticketnumber` DESC');
166
        $query->bindValue(1, $username);
167
168
        try {
169
            $query->execute();
170
        } catch (PDOException $e) {
171
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
172
        }
173
174
        return $query->fetchAll();
175
    }
176
177
    public function get_tickets_by_resolver_not_closed($username)
178
    {
179
        $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `resolvedby`=? and `ticketstatus` <> ? ORDER BY `ticketnumber` DESC');
180
        $query->bindValue(1, $username);
181
        $query->bindValue(2, 'Closed');
182
183
        try {
184
            $query->execute();
185
        } catch (PDOException $e) {
186
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
187
        }
188
189
        return $query->fetchAll();
190
    }
191
192
    public function get_tickets_by_status($ticketstatus)
193
    {
194
        $query = $this->db->prepare('SELECT * FROM `tickets` WHERE `ticketstatus`=? ORDER BY `ticketnumber` DESC');
195
        $query->bindValue(1, $ticketstatus);
196
197
        try {
198
            $query->execute();
199
        } catch (PDOException $e) {
200
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
201
        }
202
203
        return $query->fetchAll();
204
    }
205
206
    public function search_closed_ticket($fromperiod, $toperiod)
207
    {
208
        $query = $this->db->prepare("SELECT * FROM `tickets` WHERE `documenteddate` >= ? AND `documenteddate` <= ? AND `ticketstatus` = 'Closed' ORDER BY `documenteddate` DESC");
209
        $query->bindValue(1, $fromperiod);
210
        $query->bindValue(2, $toperiod);
211
212
        try {
213
            $query->execute();
214
        } catch (PDOException $e) {
215
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
216
        }
217
218
        return $query->fetchAll();
219
    }
220
221
    public function count_tickets_by_status()
222
    {
223
        $query = $this->db->prepare('SELECT ticketstatus, count(*) as total FROM `tickets` GROUP BY ticketstatus');
224
225
        try {
226
            $query->execute();
227
        } catch (PDOException $e) {
228
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
229
        }
230
231
        return $query->fetchAll();
232
    }
233
234
    public function count_resolved_tickets_by_month()
235
    {
236
        $sql = "SELECT Month(FROM_UNIXTIME(`documenteddate`)) as Bulan, Count(*) as Total FROM `tickets` WHERE (`ticketstatus`='Resolved' OR `ticketstatus`='Closed') AND FROM_UNIXTIME(`documenteddate`) >= CURDATE() - INTERVAL 1 YEAR GROUP BY Month(FROM_UNIXTIME(`documenteddate`))";
237
        $query = $this->db->prepare($sql);
238
239
        try {
240
            $query->execute();
241
        } catch (PDOException $e) {
242
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
243
        }
244
245
        return $query->fetchAll();
246
    }
247
248
    public function count_inprogress_tickets_by_month()
249
    {
250
        $sql = "SELECT Month(FROM_UNIXTIME(`documenteddate`)) as Bulan, Count(*) as Total FROM `tickets` WHERE (`ticketstatus`='Assigned' OR `ticketstatus`='Pending') AND FROM_UNIXTIME(`documenteddate`) >= CURDATE() - INTERVAL 1 YEAR GROUP BY Month(FROM_UNIXTIME(`documenteddate`))";
251
        $query = $this->db->prepare($sql);
252
253
        try {
254
            $query->execute();
255
        } catch (PDOException $e) {
256
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
257
        }
258
259
        return $query->fetchAll();
260
    }
261
262
    public function get_last_ticket()
263
    {
264
        $query = $this->db->prepare('SELECT * FROM `tickets` ORDER BY id DESC LIMIT 1');
265
266
        try {
267
            $query->execute();
268
269
            return $query->fetch();
270
        } catch (PDOException $e) {
271
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
272
        }
273
    }
274
275
    /*
276
        public function notify_assignee($id,$ticketnumber,$email_assignee)
277
        {	if (substr(php_uname(), 0, 7) == "Windows"){
278
                $cmd = "D:\mowes_portable\www\helpdesk\batch\sendemail.bat";
279
                $WshShell = new COM("WScript.Shell");
280
                $oExec = $WshShell->Run("cmd /C $cmd", 0, false);
281
                return $oExec == 0 ? true : false;
282
            }
283
            else {
284
                $cmd = "php /batch/sendemail.bat";
285
                exec($cmd . " > /dev/null &");
286
            }
287
        }*/
288
289
    public function log_tickets($id, $sla, $reporteddate, $reportedby, $telp, $email, $problemsummary, $problemdetail, $ticketstatus, $assignee, $assigneddate, $pendingby, $pendingdate, $resolution, $resolvedby, $resolveddate, $closedby, $closeddate, $changes, $changeby)
290
    {
291
        $changedate = time();
292
        $querystring = 'INSERT INTO `log_tickets` (`id`,`sla`,`reporteddate`, `reportedby`, `telp`, `email`, `problemsummary`,`problemdetail`,`ticketstatus`,`assignee`,`assigneddate`,`pendingby`,`pendingdate`,`resolution`,`resolvedby`,`resolveddate`,`closedby`,`closeddate`,`changes`,`changeby`,`changedate`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
293
        $query = $this->db->prepare($querystring);
294
        $query->bindValue(1, $id);
295
        $query->bindValue(2, $sla);
296
        $query->bindValue(3, $reporteddate);
297
        $query->bindValue(4, $reportedby);
298
        $query->bindValue(5, $telp);
299
        $query->bindValue(6, $email);
300
        $query->bindValue(7, $problemsummary);
301
        $query->bindValue(8, $problemdetail);
302
        $query->bindValue(9, $ticketstatus);
303
        $query->bindValue(10, $assignee);
304
        $query->bindValue(11, $assigneddate);
305
        $query->bindValue(12, $pendingby);
306
        $query->bindValue(13, $pendingdate);
307
        $query->bindValue(14, $resolution);
308
        $query->bindValue(15, $resolvedby);
309
        $query->bindValue(16, $resolveddate);
310
        $query->bindValue(17, $closedby);
311
        $query->bindValue(18, $closeddate);
312
        $query->bindValue(19, $changes);
313
        $query->bindValue(20, $changeby);
314
        $query->bindValue(21, $changedate);
315
316
        try {
317
            $query->execute();
318
        } catch (PDOException $e) {
319
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
320
        }
321
    }
322
323
    public function get_audit_trail($id)
324
    {
325
        $query = $this->db->prepare('SELECT * FROM `log_tickets` WHERE `id`= ? ORDER BY `changedate` DESC');
326
        $query->bindValue(1, $id);
327
328
        try {
329
            $query->execute();
330
        } catch (PDOException $e) {
331
            die($e->getMessage());
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
332
        }
333
334
        return $query->fetchAll();
335
    }
336
}
337