-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModel.php
133 lines (106 loc) · 4.28 KB
/
Model.php
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
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
class Model extends Database
{
public $response;
public $mail;
public function send_mail($address, $subject = 'subject', $body = 'body', $AltBody = 'AltBody')
{
# code...
$this->mail = new PHPMailer(true);
try {
$this->mail->isSMTP();
$this->mail->CharSet = "UTF-8";
$this->mail->Host = $_ENV['MAIL_HOST'] || $this->settings('smtp_server');
$this->mail->SMTPAuth = true;
$this->mail->Username = $_ENV['MAIL_USERNAME'] || $this->settings('smtp_user');
$this->mail->Password = $_ENV['MAIL_PASSWORD'] || $this->settings('smtp_pass');
$this->mail->SMTPSecure = $_ENV['MAIL_ENCRYPTION'] || $this->settings('smtp_protocol');
$this->mail->Port = $_ENV['MAIL_PORT'] || $this->settings('smtp_port');
$this->mail->setFrom($_ENV['MAIL_FROM_ADDRESS'], $_ENV['MAIL_FROM_NAME']);
$this->mail->addBCC(trim($address), $_ENV['MAIL_FROM_NAME']);
$this->mail->isHTML(true);
$this->mail->Subject = $subject;
$this->mail->Body = $body;
$this->mail->AltBody = $AltBody;
$send = $this->mail->send();
if ($send) {
return true;
}
} catch (Exception $e) {
$this->response['status'] = false;
$this->response['data'] = $address;
$this->response['message'] = $e->getMessage();
die(json_encode($this->response));
}
}
public function get_item($query)
{
# code...
$this->response['data'] = $this->get_row($query);
die(json_encode($this->response));
}
public function add_item($table, $data_insert, $data_required = [])
{
# code...
if (!empty($data_required)) {
$result = array_filter($data_required, 'myFilter');
} else {
$result = array_filter($data_insert, 'myFilter');
}
if (!$result) {
$is_insert = $this->insert($table, $data_insert);
if ($is_insert) {
$this->response['status'] = true;
$this->response['message'] = 'Thêm dữ liệu thành công!';
$this->response['data'] = $data_insert;
} else {
$this->response['status'] = false;
$this->response['message'] = 'Thêm dữ liệu thất bại!';
}
} else {
$this->response['status'] = false;
$this->response['message'] = 'Không để trống dữ liệu!';
}
die(json_encode($this->response));
}
public function delete_item($table, $where)
{
# code...
$result = $this->remove($table, $where);
if ($result) {
$this->response['status'] = true;
$this->response['message'] = 'Xóa dữ liệu thành công!';
} else {
$this->response['status'] = false;
$this->response['message'] = 'Xóa dữ liệu thất bại!';
}
die(json_encode($this->response));
}
public function update_item($table, $data_post, $where, $data_required = [])
{
# code...
$result = array_filter($data_post, 'myFilter');
if (!empty($data_required)) {
$result = array_filter($data_required, 'myFilter');
} else {
$result = array_filter($data_post, 'myFilter');
}
if (!($result)) {
$result = $this->update_value($table, $data_post, $where);
if ($result) {
$this->response['status'] = true;
$this->response['message'] = 'Cập nhật dữ liệu thành công!';
} else {
$this->response['status'] = false;
$this->response['message'] = 'Cập nhật dữ liệu thất bại!';
}
} else {
$this->response['status'] = false;
$this->response['message'] = 'Không để trống dữ liệu!';
}
die(json_encode($this->response));
}
}