Skip to content

Commit 800691f

Browse files
authored
Merge pull request #29 from Abhishke391/feature/service-centre
re configure missing parts
2 parents 0bb28bf + c6e1a46 commit 800691f

23 files changed

+291
-30
lines changed

controllers/AuthController.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
//use app\core\Response;
1313
use app\models\CustomerRegisterModel;
14+
use app\models\ServiceCenter;
1415
use app\models\ServiceCenterLogin;
1516
use app\models\Technician;
1617
use app\models\ServiceCentre;
@@ -116,7 +117,7 @@ public function technicianLogOut(Request $request, Response $response)
116117

117118
public function serviceCentreSignup(Request $request)
118119
{
119-
$registerModel = new ServiceCentre();
120+
$registerModel = new ServiceCenter();
120121
if ($request->isPost()) {
121122
$registerModel->loadData($request->getBody());
122123

@@ -145,7 +146,7 @@ public function serviceCentreLogin(Request $request, Response $response)
145146
$serviceCenterLogin->loadData($request->getBody());
146147
if ($serviceCenterLogin->validate() && $serviceCenterLogin->loginServiceCenter()) {
147148
$response->redirect('/service-centre-dashboard');
148-
$service_centre = new ServiceCentre();
149+
$service_centre = new ServiceCenter();
149150
$service_centre->serviceCentreAddressGeocoding();
150151
return;
151152
}

controllers/ProductController.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

controllers/ServiceCentreController.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22

33
namespace app\controllers;
4-
54
use app\core\Application;
65
use app\core\Controller;
76
use app\core\Request;
8-
use app\models\ServiceCentre;
7+
use app\models\ServiceCenter;
98

109
class ServiceCentreController extends Controller
1110
{
@@ -59,15 +58,16 @@ public function serviceCentreProfile()
5958

6059
public function updateServiceCenter(Request $request)
6160
{
62-
$serviceCenter = new ServiceCentre();
61+
$serviceCenter = new ServiceCenter();
6362

6463
if ($request->isPost()) {
6564
$serviceCenter->loadData($request->getBody());
6665
if ($serviceCenter->updateValidate()) {
6766
$serviceCenter->updateServiceCenter();
6867
Application::$app->session->setFlash('update-success', 'Update is successful');
6968
Application::$app->response->redirect('/service-centre-profile');
70-
} else {
69+
}
70+
else {
7171
Application::$app->session->setFlash('update-error', 'Update is failed');
7272
Application::$app->response->redirect('/service-centre-profile');
7373
}

core/Application.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ public function __construct($rootPath, array $config)
5555
$this->customer = null;
5656
}
5757

58+
5859
$primaryValueServiceCentre = $this->session->get('service_center');
60+
5961
if ($primaryValueServiceCentre) {
6062
$serviceCenterInstance = new $this->serviceCenterClass;
6163
$primaryKey = $serviceCenterInstance->primaryKey();
@@ -121,14 +123,14 @@ public function loginServiceCenter(DbModel $serviceCenter)
121123
$this->serviceCenter = $serviceCenter;
122124
$primaryKey = $serviceCenter->primaryKey();
123125
$primaryValue = $serviceCenter->{$primaryKey};
124-
$this->session->set('service_center', $primaryValue);
126+
$this->session->set('serviceCenter', $primaryValue);
125127
return true;
126128
}
127129

128130
public function logoutServiceCenter()
129131
{
130132
$this->serviceCenter = null;
131-
$this->session->remove('service_center');
133+
$this->session->remove('serviceCenter');
132134
}
133135

134136
}

models/Product.php

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
use app\core\DbModel;
6+
7+
class Product extends DbModel
8+
{
9+
public int $ser_cen_id;
10+
public string $description = '';
11+
public float $price;
12+
public string $media;
13+
public ?string $created_at = null;
14+
public ?string $updated_at = null;
15+
16+
public function tableName(): string
17+
{
18+
return 'product';
19+
}
20+
21+
public function attributes(): array
22+
{
23+
return ['ser_cen_id', 'description', 'price', 'media'];
24+
}
25+
public function primaryKey(): string
26+
{
27+
return 'product_id';
28+
}
29+
30+
// public function loadData($data)
31+
// {
32+
// parent::loadData($data); // TODO: Change the autogenerated stub
33+
// }
34+
35+
public function save()
36+
{
37+
$this->media = $_FILES['media']['name'];
38+
move_uploaded_file($_FILES['media']['tmp_name'], 'assets/uploads/' . $this->media);
39+
return parent::save();
40+
}
41+
42+
public static function getAllProducts(): array
43+
{
44+
$sql = 'SELECT p.*, s.name AS seller_name
45+
FROM product p
46+
JOIN service_center s ON p.ser_cen_id = s.ser_cen_id
47+
ORDER BY p.created_at DESC';
48+
$stmt = (new Product)->prepare($sql);
49+
$stmt->execute();
50+
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
51+
}
52+
public function editProduct(): bool
53+
{
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+
");
60+
$stmt->bindValue(':description', $this->description);
61+
$stmt->bindValue(':price', $this->price);
62+
$stmt->bindValue(':media', $this->media);
63+
$stmt->bindValue(':product_id', $this->product_id);
64+
$stmt->bindValue(':ser_cen_id', $this->ser_cen_id);
65+
return $stmt->execute();
66+
}
67+
public function deleteProduct(int $product_id, int $ser_cen_id): bool
68+
{
69+
$tableName = self::tableName();
70+
$statement = self::prepare("
71+
DELETE FROM $tableName
72+
WHERE product_id = :product_id AND ser_cen_id = :ser_cen_id
73+
");
74+
$statement->bindValue(':product_id', $product_id);
75+
$statement->bindValue(':seller_id', $ser_cen_id);
76+
return $statement->execute();
77+
}
78+
public function productRules(): array
79+
{
80+
return [
81+
'seller_id' => [self::RULE_REQUIRED],
82+
'name' => [self::RULE_REQUIRED, [self::RULE_MAX, 'max' => 255]],
83+
'description' => [self::RULE_REQUIRED, [self::RULE_MAX, 'max' => 1000]],
84+
'price' => [self::RULE_REQUIRED]
85+
];
86+
}
87+
}
88+
89+
?>

models/ServiceCentre.php models/ServiceCenter.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
use app\core\Application;
77
use app\core\DbModel;
88

9-
class ServiceCentre extends DbModel
9+
class ServiceCenter extends DbModel
10+
1011
{
1112

1213
public string $name = '';
@@ -91,7 +92,10 @@ public function rules(): array
9192
return [
9293
'name' => [self::RULE_REQUIRED],
9394
// 'nic' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 15]],
94-
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL],
95+
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL, [
96+
self::RULE_UNIQUE,
97+
'class' => self::class
98+
]],
9599
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
96100
'address' => [self::RULE_REQUIRED],
97101
'password' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 8]],
@@ -101,7 +105,11 @@ public function rules(): array
101105

102106
public function updateRules(): array
103107
{
104-
return [];
108+
return [
109+
'name' => [self::RULE_REQUIRED],
110+
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
111+
'address' => [self::RULE_REQUIRED]
112+
];
105113
}
106114

107115
public function attributes(): array

models/ServiceCenterLogin.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ class ServiceCenterLogin extends Model
99
{
1010
public string $email = '';
1111
public string $password = '';
12-
1312
public function rules(): array
1413
{
1514
// TODO: Implement rules() method.
@@ -26,14 +25,15 @@ public function updateRules(): array
2625

2726
public function loginServiceCenter()
2827
{
29-
$service_centerModel = new ServiceCentre;
28+
$service_centerModel = new ServiceCenter;
3029
$service_center = $service_centerModel->findOne(['email' => $this->email]);
3130
if (!$service_center) {
3231
$this->addError('email', 'service center not exist with this email');
3332
return false;
3433
}
3534

3635
if (!password_verify($this->password, $service_center->password)) {
36+
$this->addError('password', 'wrong password');
3737
return false;
3838
}
3939

public/assets/market-images/tire.png

416 KB
Loading
329 KB
Loading
+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.body-section {
2+
display: flex;
3+
flex-wrap: wrap;
4+
margin: 0 auto;
5+
padding: 15px;
6+
max-width: 1200px; /* Adjust as per your needs */
7+
}
8+
9+
.product-section {
10+
flex-grow: 1;
11+
max-width: 75%;
12+
box-sizing: border-box;
13+
padding: 15px;
14+
display: flex;
15+
flex-wrap: wrap;
16+
gap: 15px; /* Spacing between product cards */
17+
}
18+
19+
.sidenav-section {
20+
max-width: 25%;
21+
flex-grow: 1;
22+
padding: 15px;
23+
box-sizing: border-box;
24+
background-color: #f5f5f5; /* Light background for side nav */
25+
border-radius: 5px;
26+
}
27+
28+
.product-card {
29+
background-color: #ffffff;
30+
border: 1px solid #ddd;
31+
padding: 15px;
32+
border-radius: 5px;
33+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
34+
width: calc(33.33% - 15px); /* Adjust card width */
35+
box-sizing: border-box;
36+
text-align: center; /* Center content */
37+
}
38+
39+
.product-card img.product-image {
40+
width: 100%;
41+
height: auto;
42+
max-height: 200px; /* Limit the image height */
43+
object-fit: cover; /* Ensure image maintains aspect ratio and fills */
44+
border-radius: 5px; /* Optional: match border radius */
45+
margin-bottom: 10px; /* Spacing below the image */
46+
}
47+
48+
.product-card h3 {
49+
margin: 0 0 10px;
50+
}
51+
52+
.product-card p {
53+
margin: 0;
54+
}
55+
56+
.category-list {
57+
list-style-type: none;
58+
padding: 0;
59+
margin: 0;
60+
}
61+
62+
.category-list li {
63+
margin: 10px 0;
64+
}
65+
66+
.category-list li a {
67+
text-decoration: none;
68+
color: #007bff; /* Bootstrap default blue */
69+
}
70+
71+
.category-list li a:hover {
72+
text-decoration: underline;
73+
}

public/css/service-center/service-centre-login.css

+22
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,28 @@
192192
}
193193
}
194194

195+
/* Highlight invalid input fields */
196+
.container .box-2 .wrapper .login-form .input-element .invalid {
197+
border-color: #dc3545; /* Red border for error */
198+
background-color: #f8d7da; /* Light red background for error */
199+
}
200+
201+
.container .box-2 .wrapper .login-form .input-element .invalid {
202+
color: #dc3545; /* Red color for label to indicate error */
203+
}
204+
205+
/* Error feedback message */
206+
.container .box-2 .wrapper .login-form .input-element .invalid-feedback {
207+
color: #dc3545;
208+
font-size: 0.8rem;
209+
margin-top: 0.4rem;
210+
/*display: none; /* Hide by default, show only when invalid */
211+
}
212+
213+
/* Display error feedback when invalid */
214+
.container .box-2 .wrapper .login-form .input-element.invalid .invalid-feedback {
215+
display: block;
216+
}
195217

196218
.alert {
197219
position: relative;

public/index.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$config = [
2222
'technicianClass' => \app\models\Technician::class,
2323
'customerClass' => \app\models\Customer::class,
24-
'serviceCenterClass' => \app\models\ServiceCentre::class,
24+
'serviceCenterClass' => \app\models\ServiceCenter::class,
2525
'db' => [
2626
'dsn' => $_ENV['DB_DSN'],
2727
'user' => $_ENV['DB_USER'],
@@ -92,7 +92,6 @@
9292
$app->router->post('/service-centre-sign-up', [AuthController::class, 'serviceCentreSignup']);
9393
$app->router->get('/service-centre-login', [AuthController::class, 'serviceCentreLogin']);
9494
$app->router->post('/service-centre-login', [AuthController::class, 'serviceCentreLogin']);
95-
$app->router->get('/technician-logout', [AuthController::class, 'technicianLogOut']);
9695
$app->router->get('/service-center-logout', [AuthController::class, 'serviceCenterLogout']);
9796

9897
/* routes related to the by Post */

views/service-centre/components/header.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
2+
23
use app\core\Application;
4+
35
?>
46

57

@@ -27,4 +29,5 @@
2729
<div class="user">
2830
<img src="/assets/select-user-service-centre.png" alt="">
2931
</div>
32+
3033
</div>

views/service-centre/components/sidebar.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
</li>
5050

5151
<li>
52-
<a href="/technician-messages">
52+
<a href="#">
5353
<span class="icon">
5454
<ion-icon name="chatbubble-outline"></ion-icon>
5555
</span>
@@ -58,7 +58,7 @@
5858
</li>
5959

6060
<li>
61-
<a href="/technician-messages">
61+
<a href="#">
6262
<span class="icon">
6363
<ion-icon name="bag-outline"></ion-icon>
6464
</span>

0 commit comments

Comments
 (0)