Skip to content

Commit 781a93c

Browse files
committed
retrieved all the technicians in the admin dashboard
1 parent b6d9115 commit 781a93c

File tree

12 files changed

+447
-112
lines changed

12 files changed

+447
-112
lines changed

controllers/AdminController.php

+29
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public function customers()
7878

7979
}
8080

81+
public function technicians()
82+
{
83+
// Fetch all technicians records
84+
$technicians = Admin::findAllTechnicians();
85+
// Render the all the customer in the database
86+
$this->setLayout('auth');
87+
return $this->render('/admin/technicians', ['technicians' => $technicians]);
88+
89+
}
90+
8191
public function deleteCustomer(Request $request)
8292
{
8393
$data = $request->getBody(); // Assuming this already returns an array
@@ -97,5 +107,24 @@ public function deleteCustomer(Request $request)
97107
}
98108
}
99109

110+
public function deleteTechnician(Request $request)
111+
{
112+
$data = $request->getBody(); // Assuming this already returns an array
113+
if (isset($data['tech_id'])) {
114+
$tech_id = $data['tech_id'];
115+
116+
// Call the model function to delete the technician
117+
$result = Admin::deleteTechnicianById($tech_id);
118+
119+
if ($result) {
120+
echo json_encode(['status' => 'success']);
121+
} else {
122+
echo json_encode(['status' => 'error', 'message' => 'Failed to delete technician']);
123+
}
124+
} else {
125+
echo json_encode(['status' => 'error', 'message' => 'Invalid technician ID']);
126+
}
127+
}
128+
100129
}
101130

controllers/AdminController.php~

-87
This file was deleted.

models/Admin.php

+18
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ public static function findAllCustomers()
8989
return $statement->fetchAll(\PDO::FETCH_ASSOC);
9090
}
9191

92+
public static function findAllTechnicians()
93+
{
94+
$sql = "SELECT tech_id, fname, lname, email, phone_no, address, reg_date FROM technician";
95+
$statement = (new Admin)->prepare($sql);
96+
$statement->execute();
97+
return $statement->fetchAll(\PDO::FETCH_ASSOC);
98+
}
99+
92100
public static function deleteCustomerById($cus_id)
93101
{
94102
$db = Application::$app->db; // Ensure this points to the correct Database instance
@@ -99,4 +107,14 @@ public static function deleteCustomerById($cus_id)
99107

100108
}
101109

110+
public static function deleteTechnicianById($cus_id)
111+
{
112+
$db = Application::$app->db; // Ensure this points to the correct Database instance
113+
$sql = "DELETE FROM technician WHERE tech_id = :tech_id";
114+
$stmt = $db->prepare($sql);
115+
$stmt->bindParam(':tech_id', $tech_id, \PDO::PARAM_INT);
116+
return $stmt->execute();
117+
118+
}
119+
102120
}

models/Admin.php~

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<?php
2+
3+
namespace app\models;
4+
5+
use app\core\Application;
6+
use app\core\DbModel;
7+
8+
class Admin extends DbModel
9+
{
10+
public string $fname = '';
11+
public string $lname = '';
12+
public string $email = '';
13+
public string $phone_no = '';
14+
public string $address = '';
15+
public string $password = '';
16+
public string $confirmPassword = '';
17+
18+
public function tableName(): string
19+
{
20+
return 'admin';
21+
}
22+
23+
public function primaryKey(): string
24+
{
25+
return 'admin_id';
26+
}
27+
28+
public function save()
29+
{
30+
$this->password = password_hash($this->password, PASSWORD_DEFAULT);
31+
return parent::save();
32+
}
33+
34+
public function updateAdmin()
35+
{
36+
$sql = "UPDATE admin SET fname = :fname, lname = :lname, phone_no = :phone_no, address = :address WHERE admin_id = :admin_id";
37+
$stmt = self::prepare($sql);
38+
$stmt->bindValue(':fname', $this->fname);
39+
$stmt->bindValue(':lname', $this->lname);
40+
$stmt->bindValue(':phone_no', $this->phone_no);
41+
$stmt->bindValue(':address', $this->address);
42+
$stmt->bindValue(':admin_id', Application::$app->admin->{'admin_id'});
43+
return $stmt->execute();
44+
}
45+
46+
public function rules(): array
47+
{
48+
return [
49+
'fname' => [self::RULE_REQUIRED],
50+
'lname' => [self::RULE_REQUIRED],
51+
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL, [
52+
self::RULE_UNIQUE,
53+
'class' => self::class
54+
]],
55+
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
56+
'address' => [self::RULE_REQUIRED],
57+
'password' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 8]],
58+
'confirmPassword' => [self::RULE_REQUIRED, [self::RULE_MATCH, 'match' => 'password']],
59+
];
60+
}
61+
62+
public function updateRules(): array
63+
{
64+
return [
65+
'fname' => [self::RULE_REQUIRED],
66+
'lname' => [self::RULE_REQUIRED],
67+
'phone_no' => [self::RULE_REQUIRED, [self::RULE_MIN, 'min' => 10], [self::RULE_MAX, 'max' => 10]],
68+
'address' => [self::RULE_REQUIRED],
69+
];
70+
}
71+
72+
public function attributes(): array
73+
{
74+
return [
75+
'fname',
76+
'lname',
77+
'email',
78+
'phone_no',
79+
'address',
80+
'password',
81+
];
82+
}
83+
84+
public static function findAllCustomers()
85+
{
86+
$sql = "SELECT cus_id, fname, lname, email, phone_no, address, reg_date FROM customer";
87+
$statement = (new Admin)->prepare($sql);
88+
$statement->execute();
89+
return $statement->fetchAll(\PDO::FETCH_ASSOC);
90+
}
91+
92+
public static function findAllTechnicians()
93+
{
94+
$sql = "SELECT cus_id, fname, lname, email, phone_no, address, reg_date FROM technician";
95+
$statement = (new Admin)->prepare($sql);
96+
$statement->execute();
97+
return $statement->fetchAll(\PDO::FETCH_ASSOC);
98+
}
99+
100+
public static function deleteCustomerById($cus_id)
101+
{
102+
$db = Application::$app->db; // Ensure this points to the correct Database instance
103+
$sql = "DELETE FROM customer WHERE cus_id = :cus_id";
104+
$stmt = $db->prepare($sql);
105+
$stmt->bindParam(':cus_id', $cus_id, \PDO::PARAM_INT);
106+
return $stmt->execute();
107+
108+
}
109+
110+
public static function deleteTechnicianById($cus_id)
111+
{
112+
$db = Application::$app->db; // Ensure this points to the correct Database instance
113+
$sql = "DELETE FROM technician WHERE tech_id = :tech_id";
114+
$stmt = $db->prepare($sql);
115+
$stmt->bindParam(':tech_id', $tech_id, \PDO::PARAM_INT);
116+
return $stmt->execute();
117+
118+
}
119+
120+
}
493 KB
Loading

public/assets/uploads/Tools1.jpg

69.6 KB
Loading

0 commit comments

Comments
 (0)