Skip to content

Commit

Permalink
add events proccess
Browse files Browse the repository at this point in the history
  • Loading branch information
hidayat committed Nov 27, 2019
1 parent 833c9cc commit e96ab04
Show file tree
Hide file tree
Showing 13 changed files with 666 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@
$route['hapusDestinasi/(:num)'] = "destinasi/hapusDestinasi/$1";
// $route['userListing/(:num)'] = "user/userListing/$1";

$route['daftarEvents'] = 'event/daftarEvents';
$route['tambahEvent'] = "event/tambahEvent";
$route['tambahEventProses'] = "event/tambahEventProses";
$route['editEvent/(:num)'] = "event/editEvent/$1";
$route['editEventProses/(:num)'] = "event/editEventProses/$1";
$route['hapusEvent/(:num)'] = "event/hapusEvent/$1";
$route['addNew'] = "user/addNew";
$route['addNewUser'] = "user/addNewUser";
$route['editOld'] = "user/editOld";
Expand Down
224 changes: 224 additions & 0 deletions application/controllers/Event.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

require APPPATH . '/libraries/BaseController.php';

/**
* Class : Destinasi (UserController)
* User Class to control all user related operations.
* @author : Kishor Mali
* @version : 1.1
* @since : 15 November 2016
*/
class Event extends BaseController
{
/**
* This is default constructor of the class
*/
public function __construct()
{
parent::__construct();
$this->load->model('event_model');
$this->isLoggedIn();
}

/**
* This function used to load the first screen of the user
*/
public function index()
{
$this->global['pageTitle'] = 'Desa Wisata : Events';

$this->loadViews("backend/event", $this->global, NULL , NULL);
}

/**
* This function is used to load the user list
*/
function daftarEvents()
{
if($this->isAdmin() == TRUE) {
$this->loadThis();
} else {
$searchText = $this->security->xss_clean($this->input->post('searchText'));
$data['searchText'] = $searchText;

$this->load->library('pagination');

$count = $this->event_model->getJumlahEvents($searchText);

$returns = $this->paginationCompress ( "daftarEvents/", $count, 10 );

$data['daftarEvents'] = $this->event_model->getDaftarEvent($searchText, $returns["page"], $returns["segment"]);

$this->global['pageTitle'] = 'Desa Wisata : Events';

$this->loadViews("backend/event", $this->global, $data, NULL);
}
}

function tambahEvent()
{
if($this->isAdmin() == TRUE)
{
$this->loadThis();
}
else
{
$this->global['pageTitle'] = 'Desa Wisata : Tambah Event';

$this->loadViews("backend/tambahEvent", $this->global, Null, NULL);
}
}

function tambahEventProses()
{
if($this->isAdmin() == TRUE)
{
$this->loadThis();
}
else
{
$config['upload_path'] = './assets/gambar/events';
$config['allowed_types'] = 'gif|jpg|png|jpeg';

$this->load->library('upload', $config);

if (!$this->upload->do_upload('foto')){
$this->session->set_flashdata('error', $this->upload->display_errors());

$this->tambahEvent();
} else {
$this->load->library('form_validation');

$this->form_validation->set_rules('nama','Nama','required');
$this->form_validation->set_rules('deskripsi','Deskripsi','required');
$this->form_validation->set_rules('tgl_acara','Tanggal Acara','required');

if($this->form_validation->run() == FALSE) {
$this->tambahEvent();
} else {
$dataInput = array(
'nama'=> $this->input->post('nama'),
'deskripsi'=> $this->input->post('deskripsi'),
'foto'=> $this->upload->data('file_name'),
'tgl_acara'=> $this->input->post('tgl_acara')
);

$result = $this->event_model->tambahEvent($dataInput);

if($result > 0) {
redirect('daftarEvents');
} else {
$this->session->set_flashdata('error', 'Data gagal ditambah');
$this->tambahEvent();
}
}
}
}
}

function editEvent($id)
{
if($this->isAdmin() == TRUE) {
$this->loadThis();
} else {
$data['daftarEvent'] = $this->event_model->getEventById($id);

$this->global['pageTitle'] = 'Desa Wisata : Edit Event';

$this->loadViews("backend/editEvent", $this->global, $data, NULL);
}
}

function editEventProses($id)
{
if($this->isAdmin() == TRUE) {
$this->loadThis();
} else {
if (empty($_FILES['foto']['name'])) {
$this->load->library('form_validation');

$this->form_validation->set_rules('nama','Nama','required');
$this->form_validation->set_rules('deskripsi','Deskripsi','required');
$this->form_validation->set_rules('tgl_acara','Tanggal Acara','required');

if($this->form_validation->run() == FALSE) {
$this->tambahEvent();
} else {
$dataInput = array(
'nama'=> $this->input->post('nama'),
'deskripsi'=> $this->input->post('deskripsi'),
'tgl_acara'=> $this->input->post('tgl_acara')
);

$this->event_model->editEventById($dataInput, $id);

redirect('daftarEvents');
}
} else {
$data_lama = $this->event_model->getEventById($id);

$config['upload_path'] = './assets/gambar/events';
$config['allowed_types'] = 'gif|jpg|png|jpeg';

$this->load->library('upload', $config);

if (!$this->upload->do_upload('foto')){
$this->session->set_flashdata('error', $this->upload->display_errors());

$this->editEvent();
} else {
unlink('./assets/gambar/events/'.$data_lama->foto.'');

$this->load->library('form_validation');

$this->form_validation->set_rules('nama','Nama','required');
$this->form_validation->set_rules('deskripsi','Deskripsi','required');
$this->form_validation->set_rules('tgl_acara','Tanggal Acara','required');

if($this->form_validation->run() == FALSE) {
$this->tambahEvent();
} else {
$dataInput = array(
'nama'=> $this->input->post('nama'),
'deskripsi'=> $this->input->post('deskripsi'),
'foto'=> $this->upload->data('file_name'),
'tgl_acara'=> $this->input->post('tgl_acara')
);

$this->event_model->editEventById($dataInput, $id);

redirect('daftarEvents');
}
}
}
}
}

function hapusEvent($id)
{
if($this->isAdmin() == TRUE) {
$this->loadThis();
} else {
$data_lama = $this->event_model->getEventById($id);
unlink('./assets/gambar/events/'.$data_lama->foto.'');

$this->event_model->hapusById($id);

redirect('daftarEvents');
}
}


/**
* Page not found : error 404
*/
function pageNotFound()
{
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';

$this->loadViews("backend/404", $this->global, NULL, NULL);
}
}

?>
102 changes: 102 additions & 0 deletions application/models/Event_model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Class : Destinasi_model (User Model)
* User model class to get to handle user related data
* @author : Kishor Mali
* @version : 1.1
* @since : 15 November 2016
*/
class Event_model extends CI_Model
{
function getJumlahEvents($searchText = '')
{
$this->db->select('id_event, nama, deskripsi, foto, tgl_acara');
$this->db->from('events');

if(!empty($searchText)) {
$likeCriteria = "(nama LIKE '%".$searchText."%'
OR deskripsi LIKE '%".$searchText."%'
OR foto LIKE '%".$searchText."%'
OR tgl_acara LIKE '%".$searchText."%')";
$this->db->where($likeCriteria);
}

$query = $this->db->get();

return $query->num_rows();
}

function getDaftarEvent($searchText = '', $page, $segment)
{
$this->db->select('id_event, nama, deskripsi, foto, tgl_acara');
$this->db->from('events');

if(!empty($searchText)) {
$likeCriteria = "(nama LIKE '%".$searchText."%'
OR deskripsi LIKE '%".$searchText."%'
OR foto LIKE '%".$searchText."%'
OR tgl_acara LIKE '%".$searchText."%')";
$this->db->where($likeCriteria);
}

$this->db->order_by('id_event', 'DESC');
$this->db->limit($page, $segment);
$query = $this->db->get();

$result = $query->result();
return $result;
}

function getSemuaEvent()
{
$this->db->select('*');
$this->db->from('events');

$this->db->order_by('id_event', 'DESC');
$query = $this->db->get();

$result = $query->result();
return $result;
}

function tambahEvent($data)
{
$this->db->trans_start();
$this->db->insert('events', $data);

$insert_id = $this->db->insert_id();

$this->db->trans_complete();

return $insert_id;
}

function getEventById($id)
{
$this->db->select('*');
$this->db->from('events');
$this->db->where("id_event =", $id);

$query = $this->db->get();
return $query->row();
}

function editEventById($data, $id)
{
$this->db->where('id_event', $id);
$this->db->update('events', $data);

return TRUE;
}

function hapusById($id)
{
$this->db->where('id_event', $id);
$this->db->delete('events');

return TRUE;
}
}


Loading

0 comments on commit e96ab04

Please sign in to comment.