the_mechanic/app/Controllers/Make.php

117 lines
3.8 KiB
PHP
Executable File

<?php
namespace App\Controllers;
use App\Models\BikemodelsModel;
use App\Models\BikemakeModel;
use App\Models\ComplaintModel;
use CodeIgniter\API\ResponseTrait;
class Make extends BaseController
{
public $session;
use ResponseTrait;
public $BikemakeModel;
public $ComplaintModel;
public function __construct()
{
$this->session = session();
$this->BikemakeModel = new BikemakeModel();
$this->ComplaintModel = new ComplaintModel();
}
public function index()
{
$BikemakeModel = new BikemakeModel();
$make = $BikemakeModel->orderBy('make')->findAll();
$data['make']=$make;
$cubiccapacity = $this->ComplaintModel->getCubicCapacityName();
$data['cubiccapacity']=$cubiccapacity;
return view('make_list',$data);
}
public function create_make($make_id)
{
try {
$make_name = $this->request->getPost('makename');
$BikemakeModel = new BikemakeModel();
$data = [
'make' => $make_name
];
if (!$make_id) {
try {
$data['business_id'] = $this->session->get('logged_user_business_id');
$inserted = $BikemakeModel->insert($data);
} catch (\CodeIgniter\Database\Exceptions\DatabaseException $e) {
return $this->respond(['status' => 'failed','code' => 404,'data' => $e->getMessage()],200);
}
if ($inserted) {
$result = $data;
$make_list = $BikemakeModel->orderBy('make','asc')->findAll();
return $this->respond(['status' => 'success','code' => 200,'data' => $result,'make_list'=>$make_list],200);
} else {
$result = "No Match's";
return $this->respond(['status' => 'failed','code' => 404,'data' => $result],404);
}
}else{
$updated = $BikemakeModel->update($make_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 $e) {
return $this->respond(['status' => 'failed','code' => 500,'data' => $e],500);
}
}
public function status_make()
{
try {
$make_id = $this->request->getPost('make_id');
$isactive = $this->request->getPost('isactive');
$BikemakeModel = new BikemakeModel();
$BikemodelsModel = new BikemodelsModel();
$data = [
'isactive' => $isactive
];
$updated = $BikemakeModel->update($make_id, $data);
$make_list = $BikemakeModel->orderBy('make','asc')->findAll();
$model_list = $BikemodelsModel->where('make_id',$make_id)->findAll();
foreach ($model_list as $model) {
$model_id= $model['model_id'];
$model_updated = $BikemodelsModel->update($model_id, $data);
}
if ($updated) {
$result = $data;
return $this->respond(['status' => 'success','code' => 200,'data' => $make_list],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);
}
}
}