122 lines
3.9 KiB
PHP
122 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
use App\Models\BikemodelsModel;
|
|
use App\Models\BikemakeModel;
|
|
|
|
use CodeIgniter\API\ResponseTrait;
|
|
|
|
|
|
class Model extends BaseController
|
|
{
|
|
|
|
public $session;
|
|
use ResponseTrait;
|
|
|
|
public function __construct()
|
|
{
|
|
|
|
$this->session = session();
|
|
$this->BikemodelsModel = new BikemodelsModel();
|
|
$this->BikemakeModel = new BikemakeModel();
|
|
|
|
}
|
|
|
|
public function index($make_id)
|
|
{
|
|
$BikemodelsModel = new BikemodelsModel();
|
|
$BikemakeModel = new BikemakeModel();
|
|
|
|
$make_value = $BikemakeModel->where('make_id',$make_id)->select('make_id,make')->find();
|
|
$make_name= $make_value[0]['make'];
|
|
$make_id= $make_value[0]['make_id'];
|
|
|
|
$model = $BikemodelsModel->where('make_id',$make_id)->findAll();
|
|
$data['model']=$model;
|
|
$data['make_name'] =$make_name;
|
|
$data['make_id'] =$make_id;
|
|
|
|
return view('bike_model_list',$data);
|
|
}
|
|
|
|
|
|
public function create_model($model_id)
|
|
{
|
|
try {
|
|
$make_id = $this->request->getPost('make_id');
|
|
$model_name = $this->request->getPost('modelname');
|
|
|
|
$BikemodelsModel = new BikemodelsModel();
|
|
$data = [
|
|
'make_id' => $make_id,
|
|
'model_name' => $model_name
|
|
];
|
|
|
|
if (!$model_id) {
|
|
|
|
try {
|
|
$inserted = $BikemodelsModel->insert($data);
|
|
} catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) {
|
|
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $e->getMessage()],200);
|
|
}
|
|
if ($inserted) {
|
|
$result = $data;
|
|
$model_list = $BikemodelsModel->where('make_id',$make_id)->orderBy('make','asc')->findAll();
|
|
|
|
return $this->respond(['status' => 'success','code' => 200,'data' => $result,'model_list'=>$model_list],200);
|
|
} else {
|
|
$result = "No Match's";
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
|
}
|
|
}else{
|
|
$updated = $BikemodelsModel->update($model_id ,$data);
|
|
if ($updated) {
|
|
$result = $data;
|
|
return $this->respond(['status' => 'success','code' => 200,'data' => $result],200);
|
|
} else {
|
|
$result = "No Match's";
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
|
}
|
|
}
|
|
|
|
} catch (\Exception $exception) {
|
|
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public function status_model()
|
|
{
|
|
|
|
try {
|
|
$model_id = $this->request->getPost('model_id');
|
|
$isactive = $this->request->getPost('isactive');
|
|
|
|
$BikemodelsModel = new BikemodelsModel();
|
|
$data = [
|
|
'isactive' => $isactive
|
|
];
|
|
|
|
$updated = $BikemodelsModel->update($model_id, $data);
|
|
$model = $BikemodelsModel->where('model_id',$model_id)->first();
|
|
|
|
$models = $BikemodelsModel->where('make_id', $model['make_id'])->orderBy('model_name', 'asc')->findAll();
|
|
if ($updated) {
|
|
|
|
// $result = $data;
|
|
return $this->respond(['status' => 'success','code' => 200,'data' => $models],200);
|
|
} else {
|
|
$result = "No Match's";
|
|
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
|
|
}
|
|
} catch (\Exception $exception) {
|
|
return $this->respond(['status' => 'failed','code' => 500,'data' => $exception],500);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
} |