SHARE
TWEET

Untitled

riandaka_ Dec 3rd, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2.  
  3. class Workbook_model extends CI_Model
  4. {
  5.     private $_table = "workbook";
  6.  
  7.     public $workbook_id;
  8.     public $stage_id;
  9.     public $modul_id;
  10.     public $employee_id;
  11.     public $employee_name;
  12.     public $status;
  13.     public $image = "default.jpg";
  14.  
  15.     public function rules()
  16.     {
  17.         return [
  18.  
  19.             ['field' => 'stage_id',
  20.             'label'  => 'Stage',
  21.             'rules'  => 'required'],
  22.  
  23.             ['field' => 'modul_id',
  24.             'label'  => 'Modul',
  25.             'rules'  => 'required'],
  26.  
  27.             ['field' => 'status',
  28.              'label' => 'Status',
  29.              'rules' => 'required'],
  30.  
  31.             ['field' => 'employee_id',
  32.             'label'  => 'No. Pekerja',
  33.             'rules'  => 'required'],
  34.  
  35.             ['field' => 'employee_name',
  36.             'label'  => 'Nama Pekerja',
  37.             'rules'  => 'required'],
  38.  
  39.             ['field' => 'status',
  40.              'label' => 'Status',
  41.              'rules' => 'required']
  42.         ];
  43.     }
  44.  
  45.     public function getAll()
  46.     {
  47.         return $this->db->get($this->_table)->result();
  48.     }
  49.  
  50.     public function getById($id)
  51.     {
  52.         return $this->db->get_where($this->_table, ["workbook_id" => $id])->row();
  53.     }
  54.  
  55.     public function get_data_stage()
  56.     {
  57.         $query = $this->db->get('stage');
  58.         return $query;
  59.     }
  60.  
  61.     public function save()
  62.     {
  63.         $post = $this->input->post();
  64.         print_r($post); die;
  65.         // $this->workbook_id = $post["workbook_id"];
  66.         $this->stage_id = $post["stage_id"];
  67.         $this->modul_id = $post["modul_id"];
  68.         $this->employee_id = $post["employee_id"];
  69.         $this->employee_name = $post["employee_name"];
  70.         $this->progress = $post["progress"];
  71.         $this->status = $post["status"];
  72.         $this->image = $this->_uploadImage();
  73.         $this->db->insert($this->_table, $this);
  74.     }
  75.    
  76.     public function update()
  77.     {
  78.         $post = $this->input->post();
  79.         $this->workbook_id = $post["workbook_id"];
  80.         $this->stage_id = $post["stage_id"];
  81.         $this->modul_id = $post["modul_id"];
  82.         $this->employee_id = $post["employee_id"];
  83.         $this->employee_name = $post["employee_name"];
  84.         $this->progress = $post["progress"];
  85.         $this->status = $post["status"];
  86.  
  87.         if (!empty($_FILES["image"]["name"])) {
  88.             $this->image = $this->_uploadImage();
  89.         } else {
  90.             $this->image = $post["old_image"];
  91.         }
  92.  
  93.         $this->db->update($this->_table, $this, array('workbook_id' => $post['workbook_id']));
  94.     }
  95.  
  96.     public function delete($id)
  97.     {
  98.         return $this->db->delete($this->_table, array("workbook_id" => $id));
  99.     }
  100.  
  101.     private function _uploadImage()
  102. {
  103.     $config['upload_path']          = './upload/workbook/';
  104.     $config['allowed_types']        = 'gif|jpg|png';
  105.     $config['file_name']            = $this->workbook_id;
  106.     $config['overwrite']            = true;
  107.     $config['max_size']             = 10240; // 10MB
  108.     // $config['max_width']            = 1024;
  109.     // $config['max_height']           = 768;
  110.  
  111.     $this->load->library('upload', $config);
  112.  
  113.     if ($this->upload->do_upload('image')) {
  114.         return $this->upload->data("file_name");
  115.     }
  116.    
  117.     return "default.jpg";
  118. }
  119. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top