81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Models;
|
||
|
|
||
|
use Illuminate\Database\Eloquent\Model;
|
||
|
use Illuminate\Support\Facades\Auth;
|
||
|
use Illuminate\Support\Facades\DB;
|
||
|
use Yajra\DataTables\DataTables;
|
||
|
|
||
|
class ModelingTaskModel extends Model
|
||
|
{
|
||
|
protected $primaryKey = 'id';
|
||
|
protected $table = 'rel_model_task';
|
||
|
public $timestamps = false;
|
||
|
|
||
|
public function initData($request,$route)
|
||
|
{
|
||
|
// INIT DB
|
||
|
$data['title'] = 'Referensi Modelling Task';
|
||
|
$data['actButton'] = ['edit', 'hapus'];
|
||
|
$data['tableHead'] =
|
||
|
array(
|
||
|
["Nama Model","all","model_name"],
|
||
|
["Nama Task","all","task_name"],
|
||
|
["Nama Perusahaan","all","company_name"],
|
||
|
["Act","all","action"]
|
||
|
);
|
||
|
|
||
|
|
||
|
$data['db'] = $this->table;
|
||
|
$data['db_key'] = $this->primaryKey;
|
||
|
$data['route'] = $route;
|
||
|
$data['timestamps'] = false;
|
||
|
$data['bisaAdd'] = true;
|
||
|
$data['adaDetail'] = false;
|
||
|
$data['idManual'] = true;
|
||
|
$data['seq'] = false;
|
||
|
$data['serial'] = true;
|
||
|
|
||
|
|
||
|
$dtable = DB::select("SELECT rmt.*, rt.task_name, mm.description as model_name, mc.company_name
|
||
|
FROM rel_model_task rmt
|
||
|
LEFT JOIN ref_task rt ON rt.id::int = rmt.task_id::int
|
||
|
LEFT JOIN master_model mm ON mm.id::int = rmt.model_id::int
|
||
|
LEFT JOIN master_company mc ON mc.id::int = rmt.company_id::int
|
||
|
ORDER BY rmt.model_id");
|
||
|
|
||
|
|
||
|
// LIST DATA TABLE
|
||
|
$data['data_table'] = $dtable;
|
||
|
|
||
|
// FORM FIELD FOR STORE
|
||
|
|
||
|
$data['set_field'] = [
|
||
|
'model_id' => $request->post('model_id'),
|
||
|
'task_id' => $request->post('task_id'),
|
||
|
'company_id' => Auth::user()->company_id,
|
||
|
];
|
||
|
|
||
|
// GET DATA FOR EDIT
|
||
|
if ($request->post('id')) {
|
||
|
$data['get_data_edit'] = DB::selectOne("SELECT * FROM {$this->table} where id = ?",[$request->post('id')]);
|
||
|
}
|
||
|
|
||
|
foreach($data['tableHead'] as $v){
|
||
|
$arrHead[] = $v[2];
|
||
|
}
|
||
|
$data['head'] = implode(",",$arrHead);
|
||
|
|
||
|
return $data;
|
||
|
}
|
||
|
|
||
|
public function getDT($data,$init)
|
||
|
{
|
||
|
$dt = DataTables::of($data);
|
||
|
|
||
|
|
||
|
return $dt;
|
||
|
}
|
||
|
}
|