Skip to content

Commit b8834e8

Browse files
committed
resolving merge conflicts
2 parents 306ed81 + ff4793d commit b8834e8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1472
-148
lines changed

.env

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
DB_DSN = mysql:host=localhost;port=3306;dbname=fixmedb
1+
DB_DSN = "mysql:host=localhost;dbname=fixmedb"
22
DB_USER = root
3-
DB_PASSWORD =
3+
DB_PASSWORD = Nimal@123

controllers/AdminController.php

+19-49
Original file line numberDiff line numberDiff line change
@@ -5,74 +5,44 @@
55
use app\core\Application;
66
use app\core\Controller;
77
use app\core\Request;
8-
use app\models\Admin;
98
use app\models\Customer;
9+
use app\models\Technician;
1010

1111
class AdminController extends Controller
1212
{
13-
public function adminDashboard()
13+
public function dashboard()
1414
{
15-
// Render the admin dashboard view
1615
$this->setLayout('auth');
17-
return $this->render('/admin/admin-dashboard');
16+
return $this->render('/admin/dashboard');
1817
}
19-
20-
public function adminSettings()
18+
public function manageUsers()
2119
{
2220
$this->setLayout('auth');
23-
return $this->render('/admin/admin-settings');
21+
return $this->render('/admin/users');
2422
}
25-
26-
public function adminProfile()
23+
public function settings()
2724
{
2825
$this->setLayout('auth');
29-
return $this->render('/admin/admin-profile');
26+
return $this->render('/admin/settings');
3027
}
31-
32-
public function updateAdminProfile(Request $request)
28+
public function viewReports()
3329
{
34-
$admin = new Admin();
35-
36-
if ($request->isPost()) {
37-
$admin->loadData($request->getBody());
38-
if ($admin->updateValidate()) {
39-
$admin->updateAdmin();
40-
Application::$app->session->setFlash('update-success', 'You have been Updated your account info successfully!');
41-
Application::$app->response->redirect('/admin-profile');
42-
} else {
43-
Application::$app->response->redirect('/admin-profile');
44-
}
45-
}
30+
$this->setLayout('auth');
31+
return $this->render('/admin/reports');
4632
}
47-
48-
49-
public function customers()
33+
public function manageServices()
5034
{
51-
// Fetch all customers records
52-
$customers = Admin::findAllCustomers();
53-
// Render the all the customer in the database
5435
$this->setLayout('auth');
55-
return $this->render('/admin/customers', ['customers' => $customers]);
56-
36+
return $this->render('/admin/services');
5737
}
58-
59-
public function deleteCustomer(Request $request)
38+
public function adminLogin()
6039
{
61-
$data = $request->getBody(); // Assuming this already returns an array
62-
if (isset($data['cus_id'])) {
63-
$cus_id = $data['cus_id'];
64-
65-
// Call the model function to delete the customer
66-
$result = Admin::deleteCustomerById($cus_id);
67-
68-
if ($result) {
69-
echo json_encode(['status' => 'success']);
70-
} else {
71-
echo json_encode(['status' => 'error', 'message' => 'Failed to delete customer']);
72-
}
73-
} else {
74-
echo json_encode(['status' => 'error', 'message' => 'Invalid customer ID']);
75-
}
40+
$this->setLayout('auth');
41+
return $this->render('/admin/admin-login.php');
7642
}
43+
44+
45+
7746

7847
}
48+

controllers/ProductController.php

+122
Original file line numberDiff line numberDiff line change
@@ -1 +1,123 @@
11
<?php
2+
3+
namespace app\controllers;
4+
use app\core\Application;
5+
use app\core\Controller;
6+
use app\core\Request;
7+
use app\core\Response;
8+
use app\models\Product;
9+
10+
class ProductController extends Controller
11+
{
12+
public function create(Request $request)
13+
{
14+
$product = new Product();
15+
$ser_cen_id = Application::$app->session->get('serviceCenter');
16+
17+
if (!$ser_cen_id) {
18+
Application::$app->session->setFlash('error', 'Please log in to create a product.');
19+
Application::$app->response->redirect('/service-centre-login');
20+
return;
21+
}
22+
$product->ser_cen_id = $ser_cen_id;
23+
24+
if ($request->isPost()) {
25+
$product->loadData($request->getBody());
26+
27+
if (!empty($_FILES['media']['name'])) {
28+
$uploadDir = 'assets/uploads/';
29+
$product->media = $_FILES['media']['name'];
30+
$targetFile = $uploadDir . basename($product->media);
31+
32+
if (!move_uploaded_file($_FILES['media']['tmp_name'], $targetFile)) {
33+
Application::$app->session->setFlash('error', 'Failed to upload file.');
34+
return $this->render('service-centre/create-product', [
35+
'model' => $product,
36+
'products' => [] // Ensure products is passed even if empty
37+
]);
38+
}
39+
}
40+
41+
if ($product->validate() && $product->save()) {
42+
Application::$app->session->setFlash('success', 'Product created successfully.');
43+
Application::$app->response->redirect('/service-center-create-product');
44+
return;
45+
}
46+
}
47+
48+
// Fetch products for the logged-in service center
49+
// Output the dump in the HTML
50+
51+
// $products = $product->getProductByServiceCenter($ser_cen_id);
52+
53+
return $this->render('/service-centre/create-product', [
54+
55+
'model' => $product,
56+
// 'products' => $products
57+
// Pass the products to the view
58+
]);
59+
}
60+
61+
public function filterProductsById()
62+
{
63+
$ser_cen_id = Application::$app->session->get('serviceCenter');
64+
$products = (new Product)->getProductByServiceCenter($ser_cen_id);
65+
$this->setLayout('auth');
66+
return $this->render('service-centre/create-product', [
67+
'products' => $products
68+
]);
69+
}
70+
71+
public function index()
72+
{
73+
$products = (new Product)->getAllProducts(); // Fetch all products from the database
74+
$this->setLayout('auth'); // Set layout if needed
75+
return $this->render('/service-centre/market-place-home', [
76+
'products' => $products // Pass products to the view
77+
]);
78+
}
79+
80+
public function update(Request $request)
81+
{
82+
$product = new Product();
83+
$ser_cen_id = Application::$app->session->get('serviceCenter');
84+
85+
if (!$ser_cen_id) {
86+
Application::$app->session->setFlash('error', 'Please log in to create a product.');
87+
Application::$app->response->redirect('/service-centre-login');
88+
}
89+
90+
if ($request->isPost()) {
91+
$product->loadData($request->getBody());
92+
$product->ser_cen_id = $ser_cen_id;
93+
94+
if (!empty($_FILES['media']['name'])) {
95+
$uploadDir = 'assets/uploads/';
96+
$fileName = uniqid() . '_' . basename($_FILES['media']['name']);
97+
$targetFile = $uploadDir . $fileName;
98+
99+
if (!move_uploaded_file($_FILES['media']['tmp_name'], $targetFile)) {
100+
Application::$app->session->setFlash('error', 'Failed to upload file.');
101+
Application::$app->response->redirect('/service-center-create-product');
102+
return;
103+
}
104+
105+
$product->media = $fileName;
106+
}
107+
if ($product->editProduct()){
108+
Application::$app->session->setFlash('success', 'Product updated successfully.');
109+
Application::$app->response->redirect('/service-center-create-product');
110+
}
111+
else {
112+
Application::$app->session->setFlash('error', 'Failed to update product.');
113+
}
114+
Application::$app->response->redirect('/service-center-create-product');
115+
}
116+
}
117+
118+
119+
}
120+
121+
122+
123+
?>

controllers/ServiceCentreController.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,19 @@ public function serviceCenterCommunity()
8989
public function marketPlaceHome()
9090
{
9191
$this->setLayout('auth');
92-
return $this->render('service-centre/market-place/market-place-home');
92+
return $this->render('service-centre/market-place-home');
93+
}
94+
95+
public function serviceCenterCreateProduct()
96+
{
97+
$this->setLayout('auth');
98+
return $this->render('service-centre/create-product');
99+
}
100+
101+
public function update()
102+
{
103+
$this->setLayout('auth');
104+
return $this->render('service-centre/update-product');
93105
}
94106

95107
public function serviceCenterMessages()

models/Product.php

+60-12
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,25 @@ public function primaryKey(): string
2727
return 'product_id';
2828
}
2929

30-
// public function loadData($data)
31-
// {
32-
// parent::loadData($data); // TODO: Change the autogenerated stub
33-
// }
3430

3531
public function save()
3632
{
33+
// if (!empty($_FILES['media']['name'])) {
34+
// $uploadDir = 'assets/uploads/';
35+
// $fileName = uniqid() . '_' . basename($_FILES['media']['name']); // Generate unique name
36+
// $targetFile = $uploadDir . $fileName;
37+
//
38+
// // Validate file type and size (example: images only, max 5MB)
39+
// $allowedTypes = ['image/jpeg', 'image/png', 'image/gif'];
40+
// if (in_array($_FILES['media']['type'], $allowedTypes) && $_FILES['media']['size'] <= 5 * 1024 * 1024) {
41+
// if (!move_uploaded_file($_FILES['media']['tmp_name'], $targetFile)) {
42+
// throw new \Exception('File upload failed.');
43+
// }
44+
// $this->media = $fileName;
45+
// } else {
46+
// throw new \Exception('Invalid file type or size.');
47+
// }
48+
// }
3749
$this->media = $_FILES['media']['name'];
3850
move_uploaded_file($_FILES['media']['tmp_name'], 'assets/uploads/' . $this->media);
3951
return parent::save();
@@ -49,21 +61,43 @@ public static function getAllProducts(): array
4961
$stmt->execute();
5062
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
5163
}
64+
65+
public function getProductByServiceCenter(int $ser_cen_id): array
66+
{
67+
try {
68+
$sql = 'SELECT * FROM product WHERE ser_cen_id = :ser_cen_id ORDER BY created_at DESC';
69+
$stmt = self::prepare($sql);
70+
$stmt->bindValue(':ser_cen_id', $ser_cen_id);
71+
$stmt->execute();
72+
73+
$products = $stmt->fetchAll(\PDO::FETCH_ASSOC);
74+
75+
// Debugging: Check the fetched data
76+
if (!$products) {
77+
throw new \Exception("No products found for service center ID: $ser_cen_id");
78+
}
79+
80+
return $products;
81+
} catch (\Exception $e) {
82+
// Log the error (optional) and return an empty array
83+
error_log($e->getMessage());
84+
return [];
85+
}
86+
}
87+
5288
public function editProduct(): bool
5389
{
54-
$tableName = self::tableName();
55-
$stmt = self::prepare("
56-
UPDATE $tableName
57-
SET description = :description, price = :price, media = :media, updated_at = NOW()
58-
WHERE product_id = :product_id AND ser_cen_id = :ser_cen_id
59-
");
90+
$sql = "UPDATE product SET description = :description, price = :price, media = :media, updated_at = NOW() WHERE product_id = :product_id AND ser_cen_id = :ser_cen_id";
91+
$stmt = self::prepare($sql);
6092
$stmt->bindValue(':description', $this->description);
6193
$stmt->bindValue(':price', $this->price);
6294
$stmt->bindValue(':media', $this->media);
63-
$stmt->bindValue(':product_id', $this->product_id);
64-
$stmt->bindValue(':ser_cen_id', $this->ser_cen_id);
95+
$stmt->bindValue("product_id", $this->product_id);
96+
$stmt->bindValue("ser_cen_id", $this->ser_cen_id);
97+
6598
return $stmt->execute();
6699
}
100+
67101
public function deleteProduct(int $product_id, int $ser_cen_id): bool
68102
{
69103
$tableName = self::tableName();
@@ -84,6 +118,20 @@ public function productRules(): array
84118
'price' => [self::RULE_REQUIRED]
85119
];
86120
}
121+
122+
public function rules(): array
123+
{
124+
return [
125+
126+
];
127+
}
128+
129+
public function updateRules(): array
130+
{
131+
return [
132+
133+
];
134+
}
87135
}
88136

89137
?>
Loading
Loading
172 KB
Loading
Loading
7.3 KB
Loading
5.29 KB
Loading
8.28 KB
Loading
6.68 KB
Loading
8.55 KB
Loading
9.44 KB
Loading
8.5 KB
Loading

public/assets/uploads/download.jpeg

3.37 KB
Loading

0 commit comments

Comments
 (0)