Flatten mockup repo
This commit is contained in:
111
application/controllers/mockup/masterdata/Qontakconfig.php
Normal file
111
application/controllers/mockup/masterdata/Qontakconfig.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
class Qontakconfig extends MY_Controller
|
||||
{
|
||||
var $db_onedev;
|
||||
var $load;
|
||||
var $hostname;
|
||||
|
||||
public function index()
|
||||
{
|
||||
echo "Config Qontak WA API";
|
||||
}
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->db_onedev = $this->load->database('onedev', TRUE);
|
||||
$this->hostname = "cpone.aplikasi.web.id";
|
||||
}
|
||||
|
||||
function getlatestdata()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "SELECT * from x_qontak_api ORDER BY XQontakApiLastUpdated DESC LIMIT 1";
|
||||
$query = $this->db_onedev->query($sql);
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$message['qry'] = $this->db_onedev->last_query();
|
||||
$this->sys_error($message);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = [
|
||||
"total" => $query->num_rows(),
|
||||
"records" => $query->result_array()
|
||||
];
|
||||
|
||||
$this->sys_ok($result);
|
||||
}
|
||||
|
||||
function updateconfig()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
// die(var_dump($prm));
|
||||
|
||||
$this->db_onedev->trans_begin();
|
||||
|
||||
$sql = "UPDATE x_qontak_api SET
|
||||
XQontakApiToken = ?,
|
||||
XQontakApiWaIntegrationID = ?,
|
||||
XQontakApiLastUpdated = NOW()
|
||||
WHERE XQontakApiID = ?";
|
||||
$query = $this->db_onedev->query($sql, array($prm['newApiToken'], $prm['newWaIntegrationID'], $prm['configID']));
|
||||
|
||||
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$message['qry'] = $this->db_onedev->last_query();
|
||||
$this->db_onedev->trans_rollback();
|
||||
$this->sys_error([$message]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->db_onedev->trans_commit();
|
||||
$this->sys_ok("Berhasil update config");
|
||||
}
|
||||
|
||||
function addnewconfig()
|
||||
{
|
||||
if (!$this->isLogin) {
|
||||
$this->sys_error("Invalid Token");
|
||||
exit;
|
||||
}
|
||||
|
||||
$prm = $this->sys_input;
|
||||
|
||||
$sql = "INSERT INTO x_qontak_api (
|
||||
XQontakApiToken,
|
||||
XQontakApiWaIntegrationID,
|
||||
XQontakApiTemplateID,
|
||||
XQontakApiTemplateName,
|
||||
XQontakApiCreated,
|
||||
XQontakApiLastUpdated
|
||||
) VALUES (?, ?, ?, ?, NOW(), NOW())";
|
||||
|
||||
|
||||
if ($prm['newApiToken'] !== null && $prm['newWaIntegrationID'] !== null && $prm['newTemplateID'] !== null && $prm['newTemplateName'] !== null) {
|
||||
$this->db_onedev->trans_begin();
|
||||
$query = $this->db_onedev->query($sql, array($prm['newApiToken'], $prm['newWaIntegrationID'], $prm['newTemplateID'], $prm['newTemplateName']));
|
||||
if (!$query) {
|
||||
$message = $this->db_onedev->error();
|
||||
$message['qry'] = $this->db_onedev->last_query();
|
||||
$this->sys_error([$message]);
|
||||
$this->db_onedev->trans_rollback();
|
||||
exit;
|
||||
}
|
||||
$this->db_onedev->trans_commit();
|
||||
$this->sys_ok("Berhasil tambah config");
|
||||
} else {
|
||||
$this->sys_error("Missing parameter");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user