1
|
|
|
<?php defined('BASEPATH') OR exit('No direct script access allowed'); |
2
|
|
|
|
3
|
|
|
class Private_drive_model extends CI_Model { |
4
|
|
|
|
5
|
|
|
public function __construct() { |
6
|
|
|
parent::__construct(); |
7
|
|
|
} |
8
|
|
|
|
9
|
|
|
public function create($requester, $user, $user_un, $path, $access, $approver) { |
10
|
|
|
|
11
|
|
|
$data = array( |
12
|
|
|
'requester' => $_SESSION['ldap']['full_name'], |
13
|
|
|
'requester_un' => $_SESSION['username'], |
14
|
|
|
'requested_at' => date("Y-m-d H:i:s", time()), |
15
|
|
|
'user' => $this->input->post('user'), |
16
|
|
|
'user_un' => $user_un, |
17
|
|
|
'path' => $this->input->post('path'), |
18
|
|
|
'access' => $this->input->post('access'), |
19
|
|
|
'approver' => $this->input->post('approver'), |
20
|
|
|
); |
21
|
|
|
|
22
|
|
|
return $this->db->insert('private_drive', $data); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function get_pending() { |
26
|
|
|
$this->db->where('status', '0')->or_where('status', '1'); |
27
|
|
|
$query = $this->db->get('private_drive'); |
28
|
|
|
return $query->result_array(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function get_all() { |
32
|
|
|
$query = $this->db->get('private_drive'); |
33
|
|
|
return $query->result_array(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function check_status() { |
37
|
|
|
$this->db->where('requester_un', $_SESSION['username'])->or_where('user_un', $_SESSION['username'])->or_where('approver', $_SESSION['ldap']['full_name']); |
38
|
|
|
$query = $this->db->get('private_drive'); |
39
|
|
|
return $query->result_array(); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function match_id_user($id) { |
43
|
|
|
$this->db->where('id', $id); |
44
|
|
|
$query = $this->db->get('private_drive'); |
45
|
|
|
return $query->result_array(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function get_email_username($username) { |
|
|
|
|
49
|
|
|
|
50
|
|
|
$this->db->select('email'); |
51
|
|
|
$this->db->from('users_ad'); |
52
|
|
|
$this->db->where('username', $username); |
53
|
|
|
return $this->db->get()->row('email'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function get_request($id) { |
57
|
|
|
$this->db->where('id', $id); |
58
|
|
|
$query = $this->db->get('private_drive'); |
59
|
|
|
return $query->result_array(); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
public function get_email_approver($full_name) { |
|
|
|
|
63
|
|
|
|
64
|
|
|
$this->db->select('email'); |
65
|
|
|
$this->db->from('users_ad'); |
66
|
|
|
$this->db->where('full_name', $full_name); |
67
|
|
|
return $this->db->get()->row('email'); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
View Code Duplication |
public function cancel($id) { |
|
|
|
|
71
|
|
|
|
72
|
|
|
$this->db->where('id', $id); |
73
|
|
|
$this->db->from('private_drive'); |
74
|
|
|
$data = array( |
75
|
|
|
'status' => '5', |
76
|
|
|
'canceled_by' => $_SESSION['ldap']['full_name'], |
77
|
|
|
'canceled_at' => date("Y-m-d H:i:s", time()), |
78
|
|
|
); |
79
|
|
|
return $this->db->update('private_drive', $data); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
View Code Duplication |
public function fh_reject($id) { |
|
|
|
|
83
|
|
|
|
84
|
|
|
$this->db->where('id', $id); |
85
|
|
|
$this->db->from('private_drive'); |
86
|
|
|
$data = array( |
87
|
|
|
'status' => '3', |
88
|
|
|
'approved_at' => date("Y-m-d H:i:s", time()), |
89
|
|
|
); |
90
|
|
|
return $this->db->update('private_drive', $data); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
View Code Duplication |
public function fh_approve($id) { |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->db->where('id', $id); |
96
|
|
|
$this->db->from('private_drive'); |
97
|
|
|
$data = array( |
98
|
|
|
'status' => '1', |
99
|
|
|
'approved_at' => date("Y-m-d H:i:s", time()), |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
return $this->db->update('private_drive', $data); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
View Code Duplication |
public function cs_reject($id) { |
|
|
|
|
106
|
|
|
|
107
|
|
|
$this->db->where('id', $id); |
108
|
|
|
$this->db->from('private_drive'); |
109
|
|
|
$data = array( |
110
|
|
|
'status' => '4', |
111
|
|
|
'actioned_at' => date("Y-m-d H:i:s", time()), |
112
|
|
|
'actioned_by' => $_SESSION['ldap']['full_name'], |
113
|
|
|
); |
114
|
|
|
return $this->db->update('private_drive', $data); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
View Code Duplication |
public function cs_approve($id) { |
|
|
|
|
118
|
|
|
|
119
|
|
|
$this->db->where('id', $id); |
120
|
|
|
$this->db->from('private_drive'); |
121
|
|
|
$data = array( |
122
|
|
|
'status' => '2', |
123
|
|
|
'actioned_at' => date("Y-m-d H:i:s", time()), |
124
|
|
|
'actioned_by' => $_SESSION['ldap']['full_name'], |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
return $this->db->update('private_drive', $data); |
128
|
|
|
} |
129
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.