Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menambahkan model AnalisisKlasifikasi, terkait pada tabel analisis_klasifikasi #435

Merged
merged 6 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions donjo-app/controllers/Analisis_grafik.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Controllers\BaseController;
use App\Models\AnalisisKlasifikasi;

class Analisis_grafik extends BaseController
{
Expand Down Expand Up @@ -30,6 +31,8 @@ public function leave()

public function index($p = 1, $o = 0)
{
$analisisKlasifikasiModel = new AnalisisKlasifikasi();

unset($_SESSION['cari2']);
$data['p'] = $p;
$data['o'] = $o;
Expand Down Expand Up @@ -70,7 +73,7 @@ public function index($p = 1, $o = 0)
$data['list_dusun'] = $this->analisis_laporan_keluarga_model->list_dusun();
$data['paging'] = $this->analisis_grafik_model->paging($p, $o);
$data['main'] = $this->analisis_grafik_model->list_data($o, $data['paging']->offset, $data['paging']->per_page);
$data['keyword'] = $this->analisis_grafik_model->autocomplete();
$data['keyword'] = $analisisKlasifikasiModel->autocomplete();
$data['analisis_master'] = $this->analisis_grafik_model->get_analisis_master();
$header = $this->header_model->get_data();

Expand All @@ -82,6 +85,8 @@ public function index($p = 1, $o = 0)

public function time($p = 1, $o = 0)
{
$analisisKlasifikasiModel = new AnalisisKlasifikasi();

unset($_SESSION['cari2']);
$data['p'] = $p;
$data['o'] = $o;
Expand All @@ -99,7 +104,7 @@ public function time($p = 1, $o = 0)

$data['paging'] = $this->analisis_grafik_model->paging($p, $o);
$data['main'] = $this->analisis_grafik_model->list_data2($o, $data['paging']->offset, $data['paging']->per_page);
$data['keyword'] = $this->analisis_grafik_model->autocomplete();
$data['keyword'] = $analisisKlasifikasiModel->autocomplete();
$data['analisis_master'] = $this->analisis_grafik_model->get_analisis_master();
$data['periode'] = $this->analisis_grafik_model->list_periode();
$header = $this->header_model->get_data();
Expand Down
31 changes: 22 additions & 9 deletions donjo-app/controllers/Analisis_klasifikasi.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use App\Controllers\BaseController;
use App\Models\AnalisisKlasifikasi;

class Analisis_klasifikasi extends BaseController
{
Expand Down Expand Up @@ -31,6 +32,8 @@ public function leave()

public function index($p = 1, $o = 0)
{
$analisisKlasifikasiModel = new AnalisisKlasifikasi();

unset($_SESSION['cari2']);
$data['p'] = $p;
$data['o'] = $o;
Expand All @@ -48,7 +51,7 @@ public function index($p = 1, $o = 0)

$data['paging'] = $this->analisis_klasifikasi_model->paging($p, $o);
$data['main'] = $this->analisis_klasifikasi_model->list_data($o, $data['paging']->offset, $data['paging']->per_page);
$data['keyword'] = $this->analisis_klasifikasi_model->autocomplete();
$data['keyword'] = $analisisKlasifikasiModel->autocomplete();
$data['analisis_master'] = $this->analisis_klasifikasi_model->get_analisis_master();
$header = $this->header_model->get_data();

Expand All @@ -58,13 +61,15 @@ public function index($p = 1, $o = 0)
view('footer');
}

public function form($p = 1, $o = 0, $id = '')
public function form($p, $o, $id)
{
$analisisKlasifikasiModel = new AnalisisKlasifikasi();

$data['p'] = $p;
$data['o'] = $o;

if ($id) {
$data['analisis_klasifikasi'] = $this->analisis_klasifikasi_model->get_analisis_klasifikasi($id);
$data['analisis_klasifikasi'] = $analisisKlasifikasiModel->get_analisis_klasifikasi($id);
$data['form_action'] = site_url("analisis_klasifikasi/update/{$p}/{$o}/{$id}");
} else {
$data['analisis_klasifikasi'] = null;
Expand All @@ -88,25 +93,33 @@ public function search()

public function insert()
{
$this->analisis_klasifikasi_model->insert();
$analisisKlasifikasiModel = new AnalisisKlasifikasi();

$analisisKlasifikasiModel->insert();
redirect('analisis_klasifikasi');
}

public function update($p = 1, $o = 0, $id = '')
public function update($p, $o, $id)
{
$this->analisis_klasifikasi_model->update($id);
$analisisKlasifikasiModel = new AnalisisKlasifikasi();
$analisisKlasifikasiModel->update($id);

redirect("analisis_klasifikasi/index/{$p}/{$o}");
}

public function delete($p = 1, $o = 0, $id = '')
public function delete($p, $o, $id)
{
$this->analisis_klasifikasi_model->delete($id);
$analisisKlasifikasiModel = new AnalisisKlasifikasi();
$analisisKlasifikasiModel->delete($id);

redirect("analisis_klasifikasi/index/{$p}/{$o}");
}

public function delete_all($p = 1, $o = 0)
{
$this->analisis_klasifikasi_model->delete_all();
$analisisKlasifikasiModel = new AnalisisKlasifikasi();
$analisisKlasifikasiModel->delete_all();

redirect("analisis_klasifikasi/index/{$p}/{$o}");
}
}
96 changes: 96 additions & 0 deletions donjo-app/models/AnalisisKlasifikasi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace App\Models;

use App\Models\BaseModel as Model;

class AnalisisKlasifikasi extends Model
{
protected $table = 'analisis_klasifikasi';

public function insert()
{
$data = $_POST;
$data['id_master'] = $_SESSION['analisis_master'];
$outp = $this->db->insert($this->table, $data);

if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function update(int $id)
{
$data = $_POST;
$data['id_master'] = $_SESSION['analisis_master'];
$this->db->where('id', $id);
$outp = $this->db->update($this->table, $data);
if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function delete(int $id)
{
$this->db->where('id', $id);
$outp = $this->db->delete($this->table);

if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function delete_all()
{
$id_cb = $_POST['id_cb'];

if (count($id_cb)) {
foreach ($id_cb as $id) {
$outp = $this->db->delete($this->table, ['id' => $id]);
}
} else {
$outp = false;
}

if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function get_analisis_klasifikasi(int $id)
{
$query = $this->db->get_where($this->table, ['id' => $id]);

return $query->row_array();
}

/**
* Fungsi ini digunakan untuk menghasilkan data untuk proses autocomplete.
*/
public function autocomplete(): string
{
// Mengambil data nama dari tabel
$query = $this->db->select('nama')->get($this->table);
$data = $query->result_array();

$i = 0;
$outp = '';

// Menggabungkan nama-nama dalam format autocomplete
while ($i < count($data)) {
$outp .= ',"' . $data[$i]['nama'] . '"';
$i++;
}
$outp = strtolower(substr($outp, 1));

return '[' . $outp . ']';
}
}
84 changes: 0 additions & 84 deletions donjo-app/models/Analisis_grafik_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,6 @@

class Analisis_grafik_model extends Model
{
public function autocomplete()
{
$sql = 'SELECT nama FROM analisis_klasifikasi';
$query = $this->db->query($sql);
$data = $query->result_array();

$i = 0;
$outp = '';

while ($i < count($data)) {
$outp .= ',"' . $data[$i]['nama'] . '"';
$i++;
}
$outp = strtolower(substr($outp, 1));

return '[' . $outp . ']';
}

public function search_sql()
{
if (isset($_SESSION['cari'])) {
Expand Down Expand Up @@ -208,72 +190,6 @@ public function list_data2($o = 0, $offset = 0, $limit = 500)
return $data;
}

public function insert()
{
$data = $_POST;
$data['id_master'] = $_SESSION['analisis_master'];
$outp = $this->db->insert('analisis_klasifikasi', $data);

if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function update($id = 0)
{
$data = $_POST;
$data['id_master'] = $_SESSION['analisis_master'];
$this->db->where('id', $id);
$outp = $this->db->update('analisis_klasifikasi', $data);
if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function delete($id = '')
{
$sql = 'DELETE FROM analisis_klasifikasi WHERE id=?';
$outp = $this->db->query($sql, [$id]);

if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function delete_all()
{
$id_cb = $_POST['id_cb'];

if (count($id_cb)) {
foreach ($id_cb as $id) {
$sql = 'DELETE FROM analisis_klasifikasi WHERE id=?';
$outp = $this->db->query($sql, [$id]);
}
} else {
$outp = false;
}

if ($outp) {
$_SESSION['success'] = 1;
} else {
$_SESSION['success'] = -1;
}
}

public function get_analisis_klasifikasi($id = 0)
{
$sql = 'SELECT * FROM analisis_klasifikasi WHERE id=?';
$query = $this->db->query($sql, $id);

return $query->row_array();
}

public function get_analisis_master()
{
$sql = 'SELECT * FROM analisis_master WHERE id=?';
Expand Down
5 changes: 0 additions & 5 deletions donjo-app/models/Analisis_import_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

class Analisis_import_model extends Model
{
public function __construct()
{
parent::__construct();
}

public function import_excel()
{
$data = new Spreadsheet_Excel_Reader($_FILES['userfile']['tmp_name']);
Expand Down
Loading
Loading