Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php defined('BASEPATH') OR exit('No direct script access allowed');
- class Workbook_model extends CI_Model
- {
- private $_table = "workbook";
- public $workbook_id;
- public $stage_id;
- public $modul_id;
- public $employee_id;
- public $employee_name;
- public $status;
- public $image = "default.jpg";
- public function rules()
- {
- return [
- ['field' => 'stage_id',
- 'label' => 'Stage',
- 'rules' => 'required'],
- ['field' => 'modul_id',
- 'label' => 'Modul',
- 'rules' => 'required'],
- ['field' => 'status',
- 'label' => 'Status',
- 'rules' => 'required'],
- ['field' => 'employee_id',
- 'label' => 'No. Pekerja',
- 'rules' => 'required'],
- ['field' => 'employee_name',
- 'label' => 'Nama Pekerja',
- 'rules' => 'required'],
- ['field' => 'status',
- 'label' => 'Status',
- 'rules' => 'required']
- ];
- }
- public function getAll()
- {
- return $this->db->get($this->_table)->result();
- }
- public function getById($id)
- {
- return $this->db->get_where($this->_table, ["workbook_id" => $id])->row();
- }
- public function get_data_stage()
- {
- $query = $this->db->get('stage');
- return $query;
- }
- public function save()
- {
- $post = $this->input->post();
- print_r($post); die;
- // $this->workbook_id = $post["workbook_id"];
- $this->stage_id = $post["stage_id"];
- $this->modul_id = $post["modul_id"];
- $this->employee_id = $post["employee_id"];
- $this->employee_name = $post["employee_name"];
- $this->progress = $post["progress"];
- $this->status = $post["status"];
- $this->image = $this->_uploadImage();
- $this->db->insert($this->_table, $this);
- }
- public function update()
- {
- $post = $this->input->post();
- $this->workbook_id = $post["workbook_id"];
- $this->stage_id = $post["stage_id"];
- $this->modul_id = $post["modul_id"];
- $this->employee_id = $post["employee_id"];
- $this->employee_name = $post["employee_name"];
- $this->progress = $post["progress"];
- $this->status = $post["status"];
- if (!empty($_FILES["image"]["name"])) {
- $this->image = $this->_uploadImage();
- } else {
- $this->image = $post["old_image"];
- }
- $this->db->update($this->_table, $this, array('workbook_id' => $post['workbook_id']));
- }
- public function delete($id)
- {
- return $this->db->delete($this->_table, array("workbook_id" => $id));
- }
- private function _uploadImage()
- {
- $config['upload_path'] = './upload/workbook/';
- $config['allowed_types'] = 'gif|jpg|png';
- $config['file_name'] = $this->workbook_id;
- $config['overwrite'] = true;
- $config['max_size'] = 10240; // 10MB
- // $config['max_width'] = 1024;
- // $config['max_height'] = 768;
- $this->load->library('upload', $config);
- if ($this->upload->do_upload('image')) {
- return $this->upload->data("file_name");
- }
- return "default.jpg";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement