From 8eb854ab1926fd2b488d13419addded9dba0d2ae Mon Sep 17 00:00:00 2001 From: heama Date: Tue, 22 Aug 2023 14:18:46 +0530 Subject: [PATCH] heama --- app/Config/Routes.php | 3 +- app/Controllers/Business.php | 60 +++++++++++++++++++++++++----------- app/Models/BusinessModel.php | 2 +- app/Views/auth_login.php | 2 +- app/Views/business.php | 16 +++++----- app/Views/business_list.php | 31 +++++++++---------- 6 files changed, 68 insertions(+), 46 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 773a5842..0eeca8b5 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -51,8 +51,9 @@ $routes->get("edit_book/", "Books::edit_book"); # Business Routes $routes->get("business_list/", "Business::index"); -$routes->get("new_bussiness/", "Business::new_bussiness"); +$routes->get("new_bussiness/(:any)", "Business::new_bussiness/$1"); $routes->post("insert_business/", "Business::insert_business"); +$routes->get("delete_business/(:any)", "Business::delete_business/$1"); $routes->get("subscribers_list/", "Home::subscribers_list"); diff --git a/app/Controllers/Business.php b/app/Controllers/Business.php index b1effcf8..4b5fca83 100644 --- a/app/Controllers/Business.php +++ b/app/Controllers/Business.php @@ -21,9 +21,21 @@ class Business extends BaseController } ## For Business page load add and Update - public function new_bussiness() + public function new_bussiness($id) { - $data['page_name'] = 'Add Business'; + if ($id === '0') { + $data['page_name'] = 'Add User'; + $data['businesses'] = []; + } else if ($id !== '0') { + $data['page_name'] = 'Edit User'; + $model = new BusinessModel(); + $model->setTable('business'); + $edit_user_details = $model->where(['business_id ' => $id])->first(); + + $data['businesses'] = $edit_user_details; + } + + $this->render_page('business', $data); } @@ -38,21 +50,21 @@ class Business extends BaseController 'uploaded[bfile]', 'is_image[bfile]', 'mime_in[bfile,image/jpg,image/jpeg,image/gif,image/png,image/webp]', - + ], ], ]; - if (!$this->validate($validationRule)) { + if (! $this->validate($validationRule)) { $data = ['errors' => $this->validator->getErrors()]; print_r($data); return 'hello'; } $img = $this->request->getFile('bfile'); - if (!$img->hasMoved()) { + if (! $img->hasMoved()) { $filepath = WRITEPATH . 'uploads/' . $img->store(); - - $BusinessModel = new BusinessModel(); + + $BusinessModel = new BusinessModel(); $data = [ 'title' => $this->request->getPost('bname'), 'email' => $this->request->getPost('bmail'), @@ -61,20 +73,32 @@ class Business extends BaseController 'city' => $this->request->getPost('bcity'), 'state' => $this->request->getPost('bstate'), 'postal_code' => $this->request->getPost('bzip'), - 'business_logo' => $this->request->getPost('bfile'), + 'business_logo'=>$this->request->getPost('bfile'), 'isactive' => $this->request->getPost('bcheckbox') ? 1 : 0 ]; - $business_id = $this->request->getPost('business_id'); // Get the business ID for update - - if (empty($business_id)) { - // It's an insert operation + $BusinessModel->insert($data); - } else { - // It's an update operation - $BusinessModel->update($business_id, $data); + } + + $this->index(); + } + public function delete_business($id) + { + $BusinessModel = new BusinessModel(); + + // Check if the business ID exists + $existingBusiness = $BusinessModel->find($id); + if (!$existingBusiness) { + // return redirect()->to(base_url('Business/index'))->with('error', 'Business not found.'); + return redirect()->route('business_list'); + } + + // Delete the business record + $BusinessModel->delete($id); + + // return redirect()->to(base_url('Business/index'))->with('success', 'Business deleted successfully.'); + return redirect()->route('business_list')->with('success', 'Business deleted successfully.'); } - - // business_list } -} + \ No newline at end of file diff --git a/app/Models/BusinessModel.php b/app/Models/BusinessModel.php index 44961cf5..1329aa52 100644 --- a/app/Models/BusinessModel.php +++ b/app/Models/BusinessModel.php @@ -9,7 +9,7 @@ class BusinessModel extends Model { protected $table = 'business'; protected $primaryKey = 'business_id'; - protected $allowedFields = ['title','email','mobile_no','address','city','state','postal_code' ,'business_logo','isactive']; + protected $allowedFields = ['business_id','title','email','mobile_no','address','city','state','postal_code' ,'business_logo','isactive']; public function insertBusiness($data) { diff --git a/app/Views/auth_login.php b/app/Views/auth_login.php index db97aa92..25de0fbc 100755 --- a/app/Views/auth_login.php +++ b/app/Views/auth_login.php @@ -22,7 +22,7 @@ - +
diff --git a/app/Views/business.php b/app/Views/business.php index 021ac0e2..0ab626b0 100644 --- a/app/Views/business.php +++ b/app/Views/business.php @@ -9,31 +9,31 @@
- +
- +
- +
- +
- +
- @@ -42,14 +42,14 @@
- +
- +
diff --git a/app/Views/business_list.php b/app/Views/business_list.php index 575809c5..12dac583 100644 --- a/app/Views/business_list.php +++ b/app/Views/business_list.php @@ -2,11 +2,11 @@
-
+

@@ -27,14 +27,17 @@ State Zip File - edit + Action + - + @@ -45,8 +48,12 @@ - - + + " class="edit-button"> + + + " class="delete-button"> + @@ -56,15 +63,5 @@
- + - \ No newline at end of file