Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

re configure missing parts #29

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

//use app\core\Response;
use app\models\CustomerRegisterModel;
use app\models\ServiceCenter;
use app\models\ServiceCenterLogin;
use app\models\Technician;
use app\models\ServiceCentre;
Expand Down Expand Up @@ -116,7 +117,7 @@ public function technicianLogOut(Request $request, Response $response)

public function serviceCentreSignup(Request $request)
{
$registerModel = new ServiceCentre();
$registerModel = new ServiceCenter();
if ($request->isPost()) {
$registerModel->loadData($request->getBody());

Expand Down Expand Up @@ -145,7 +146,7 @@ public function serviceCentreLogin(Request $request, Response $response)
$serviceCenterLogin->loadData($request->getBody());
if ($serviceCenterLogin->validate() && $serviceCenterLogin->loginServiceCenter()) {
$response->redirect('/service-centre-dashboard');
$service_centre = new ServiceCentre();
$service_centre = new ServiceCenter();
$service_centre->serviceCentreAddressGeocoding();
return;
}
Expand Down
1 change: 1 addition & 0 deletions controllers/ProductController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php
8 changes: 4 additions & 4 deletions controllers/ServiceCentreController.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace app\controllers;

use app\core\Application;
use app\core\Controller;
use app\core\Request;
use app\models\ServiceCentre;
use app\models\ServiceCenter;

class ServiceCentreController extends Controller
{
Expand Down Expand Up @@ -59,15 +58,16 @@ public function serviceCentreProfile()

public function updateServiceCenter(Request $request)
{
$serviceCenter = new ServiceCentre();
$serviceCenter = new ServiceCenter();

if ($request->isPost()) {
$serviceCenter->loadData($request->getBody());
if ($serviceCenter->updateValidate()) {
$serviceCenter->updateServiceCenter();
Application::$app->session->setFlash('update-success', 'Update is successful');
Application::$app->response->redirect('/service-centre-profile');
} else {
}
else {
Application::$app->session->setFlash('update-error', 'Update is failed');
Application::$app->response->redirect('/service-centre-profile');
}
Expand Down
6 changes: 4 additions & 2 deletions core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ public function __construct($rootPath, array $config)
$this->customer = null;
}


$primaryValueServiceCentre = $this->session->get('service_center');

if ($primaryValueServiceCentre) {
$serviceCenterInstance = new $this->serviceCenterClass;
$primaryKey = $serviceCenterInstance->primaryKey();
Expand Down Expand Up @@ -121,14 +123,14 @@ public function loginServiceCenter(DbModel $serviceCenter)
$this->serviceCenter = $serviceCenter;
$primaryKey = $serviceCenter->primaryKey();
$primaryValue = $serviceCenter->{$primaryKey};
$this->session->set('service_center', $primaryValue);
$this->session->set('serviceCenter', $primaryValue);
return true;
}

public function logoutServiceCenter()
{
$this->serviceCenter = null;
$this->session->remove('service_center');
$this->session->remove('serviceCenter');
}

}
89 changes: 89 additions & 0 deletions models/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace app\models;

use app\core\DbModel;

class Product extends DbModel
{
public int $ser_cen_id;
public string $description = '';
public float $price;
public string $media;
public ?string $created_at = null;
public ?string $updated_at = null;

public function tableName(): string
{
return 'product';
}

public function attributes(): array
{
return ['ser_cen_id', 'description', 'price', 'media'];
}
public function primaryKey(): string
{
return 'product_id';
}

// public function loadData($data)
// {
// parent::loadData($data); // TODO: Change the autogenerated stub
// }

public function save()
{
$this->media = $_FILES['media']['name'];
move_uploaded_file($_FILES['media']['tmp_name'], 'assets/uploads/' . $this->media);
return parent::save();
}

public static function getAllProducts(): array
{
$sql = 'SELECT p.*, s.name AS seller_name
FROM product p
JOIN service_center s ON p.ser_cen_id = s.ser_cen_id
ORDER BY p.created_at DESC';
$stmt = (new Product)->prepare($sql);
$stmt->execute();
return $stmt->fetchAll(\PDO::FETCH_ASSOC);
}
public function editProduct(): bool
{
$tableName = self::tableName();
$stmt = self::prepare("
UPDATE $tableName
SET description = :description, price = :price, media = :media, updated_at = NOW()
WHERE product_id = :product_id AND ser_cen_id = :ser_cen_id
");
$stmt->bindValue(':description', $this->description);
$stmt->bindValue(':price', $this->price);
$stmt->bindValue(':media', $this->media);
$stmt->bindValue(':product_id', $this->product_id);
$stmt->bindValue(':ser_cen_id', $this->ser_cen_id);
return $stmt->execute();
}
public function deleteProduct(int $product_id, int $ser_cen_id): bool
{
$tableName = self::tableName();
$statement = self::prepare("
DELETE FROM $tableName
WHERE product_id = :product_id AND ser_cen_id = :ser_cen_id
");
$statement->bindValue(':product_id', $product_id);
$statement->bindValue(':seller_id', $ser_cen_id);
return $statement->execute();
}
public function productRules(): array
{
return [
'seller_id' => [self::RULE_REQUIRED],
'name' => [self::RULE_REQUIRED, [self::RULE_MAX, 'max' => 255]],
'description' => [self::RULE_REQUIRED, [self::RULE_MAX, 'max' => 1000]],
'price' => [self::RULE_REQUIRED]
];
}
}

?>
14 changes: 11 additions & 3 deletions models/ServiceCentre.php → models/ServiceCenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use app\core\Application;
use app\core\DbModel;

class ServiceCentre extends DbModel
class ServiceCenter extends DbModel

{

public string $name = '';
Expand Down Expand Up @@ -91,7 +92,10 @@ public function rules(): array
return [
'name' => [self::RULE_REQUIRED],
// 'nic' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 15]],
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL],
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL, [
self::RULE_UNIQUE,
'class' => self::class
]],
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
'address' => [self::RULE_REQUIRED],
'password' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 8]],
Expand All @@ -101,7 +105,11 @@ public function rules(): array

public function updateRules(): array
{
return [];
return [
'name' => [self::RULE_REQUIRED],
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
'address' => [self::RULE_REQUIRED]
];
}

public function attributes(): array
Expand Down
4 changes: 2 additions & 2 deletions models/ServiceCenterLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class ServiceCenterLogin extends Model
{
public string $email = '';
public string $password = '';

public function rules(): array
{
// TODO: Implement rules() method.
Expand All @@ -26,14 +25,15 @@ public function updateRules(): array

public function loginServiceCenter()
{
$service_centerModel = new ServiceCentre;
$service_centerModel = new ServiceCenter;
$service_center = $service_centerModel->findOne(['email' => $this->email]);
if (!$service_center) {
$this->addError('email', 'service center not exist with this email');
return false;
}

if (!password_verify($this->password, $service_center->password)) {
$this->addError('password', 'wrong password');
return false;
}

Expand Down
Binary file added public/assets/market-images/tire.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/uploads/CERTIFICATE-29VJWD.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
73 changes: 73 additions & 0 deletions public/css/service-center/marketplace.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.body-section {
display: flex;
flex-wrap: wrap;
margin: 0 auto;
padding: 15px;
max-width: 1200px; /* Adjust as per your needs */
}

.product-section {
flex-grow: 1;
max-width: 75%;
box-sizing: border-box;
padding: 15px;
display: flex;
flex-wrap: wrap;
gap: 15px; /* Spacing between product cards */
}

.sidenav-section {
max-width: 25%;
flex-grow: 1;
padding: 15px;
box-sizing: border-box;
background-color: #f5f5f5; /* Light background for side nav */
border-radius: 5px;
}

.product-card {
background-color: #ffffff;
border: 1px solid #ddd;
padding: 15px;
border-radius: 5px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
width: calc(33.33% - 15px); /* Adjust card width */
box-sizing: border-box;
text-align: center; /* Center content */
}

.product-card img.product-image {
width: 100%;
height: auto;
max-height: 200px; /* Limit the image height */
object-fit: cover; /* Ensure image maintains aspect ratio and fills */
border-radius: 5px; /* Optional: match border radius */
margin-bottom: 10px; /* Spacing below the image */
}

.product-card h3 {
margin: 0 0 10px;
}

.product-card p {
margin: 0;
}

.category-list {
list-style-type: none;
padding: 0;
margin: 0;
}

.category-list li {
margin: 10px 0;
}

.category-list li a {
text-decoration: none;
color: #007bff; /* Bootstrap default blue */
}

.category-list li a:hover {
text-decoration: underline;
}
22 changes: 22 additions & 0 deletions public/css/service-center/service-centre-login.css
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,28 @@
}
}

/* Highlight invalid input fields */
.container .box-2 .wrapper .login-form .input-element .invalid {
border-color: #dc3545; /* Red border for error */
background-color: #f8d7da; /* Light red background for error */
}

.container .box-2 .wrapper .login-form .input-element .invalid {
color: #dc3545; /* Red color for label to indicate error */
}

/* Error feedback message */
.container .box-2 .wrapper .login-form .input-element .invalid-feedback {
color: #dc3545;
font-size: 0.8rem;
margin-top: 0.4rem;
/*display: none; /* Hide by default, show only when invalid */
}

/* Display error feedback when invalid */
.container .box-2 .wrapper .login-form .input-element.invalid .invalid-feedback {
display: block;
}

.alert {
position: relative;
Expand Down
3 changes: 1 addition & 2 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
$config = [
'technicianClass' => \app\models\Technician::class,
'customerClass' => \app\models\Customer::class,
'serviceCenterClass' => \app\models\ServiceCentre::class,
'serviceCenterClass' => \app\models\ServiceCenter::class,
'db' => [
'dsn' => $_ENV['DB_DSN'],
'user' => $_ENV['DB_USER'],
Expand Down Expand Up @@ -92,7 +92,6 @@
$app->router->post('/service-centre-sign-up', [AuthController::class, 'serviceCentreSignup']);
$app->router->get('/service-centre-login', [AuthController::class, 'serviceCentreLogin']);
$app->router->post('/service-centre-login', [AuthController::class, 'serviceCentreLogin']);
$app->router->get('/technician-logout', [AuthController::class, 'technicianLogOut']);
$app->router->get('/service-center-logout', [AuthController::class, 'serviceCenterLogout']);

/* routes related to the by Post */
Expand Down
3 changes: 3 additions & 0 deletions views/service-centre/components/header.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use app\core\Application;

?>


Expand Down Expand Up @@ -27,4 +29,5 @@
<div class="user">
<img src="/assets/select-user-service-centre.png" alt="">
</div>

</div>
4 changes: 2 additions & 2 deletions views/service-centre/components/sidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</li>

<li>
<a href="/technician-messages">
<a href="#">
<span class="icon">
<ion-icon name="chatbubble-outline"></ion-icon>
</span>
Expand All @@ -58,7 +58,7 @@
</li>

<li>
<a href="/technician-messages">
<a href="#">
<span class="icon">
<ion-icon name="bag-outline"></ion-icon>
</span>
Expand Down
Loading