forked from KesaviAravinthan/QuickFix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.php
2271 lines (1944 loc) · 60.4 KB
/
classes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include "connection.php";
class Admin
{
private $customers = array();
private static $instance = null;
private function __construct()
{
// $this->customers = array();
$query = "SELECT * FROM customer";
$result = QueryHandler::query($query);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_array($result)) {
$customer = new Customer();
$customer->read($row['customer_id']);
array_push(($this->customers), ($customer));
}
}
}
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new Admin();
}
return self::$instance;
}
public function attach(Customer $customer_object)
{
array_push($customers, $customer_object);
// array_push($customers, $customerNewDetails);
}
public function detach(Customer $customerNewDetails)
{
// $this->customers->detach($customerNewDetails);
}
public function notify($service_name, $newservice_id)
{
foreach ($this->customers as $customer) {
$customer->AddNewServiceNotification($service_name, ($customer->getCustomer_id()), $newservice_id);
// $customer->sendOffer($this);
}
}
public function sendNotificationALL($service_name, $newservice_id)
{
$this->notify($service_name, $newservice_id);
}
// public function addNewService($customer_id, $notificationString, $notificationType)
// {
// $conn = (new Connection())->createConnection();
// $query = " INSERT INTO notification(notification, receiver_id,sender_id ,notification_type ) VALUES ('$notificationString', '$customer_id',0 , '$notificationType')";
// mysqli_query($conn, $query);
// }
}
class Customer
{
private $customer_id;
private $username;
private $firstname;
private $lastname;
private $email;
private $phone_no;
private $address;
private $latitude;
private $longitude;
private $password;
private $is_worker;
private $img;
private $total_hirings_count;
private $total_payment;
private $registered_date;
private $tmp_image;
private $customers;
public function __construct()
{
}
public function AddNewServiceNotification($service_name, $customer_id, $newservice_id)
{
// $conn = (new Connection())->createConnection();
$notificationString = "Admin add new service : " . $service_name;
$query = " INSERT INTO notification(notification, receiver_id,sender_id ,notification_type, service_id ) VALUES ('$notificationString', '$customer_id',0 , 'addnewservice', '$newservice_id')";
QueryHandler::query($query);
}
public static function getInstance($customer_id)
{
if (!array_key_exists($customer_id, self::$customers)) {
$sql = "SELECT `customer_id` FROM `Customer` WHERE customer_id = $customer_id";
if (QueryHandler::query($sql)->num_rows == 0) {
return null;
} else {
self::$customers[$customer_id] = new Customer();
self::$customers[$customer_id]->read($customer_id);
}
}
return self::$customers[$customer_id];
}
//read from database
public function read($customer_id)
{
//$conn = (new Connection())->createConnection();
$result = QueryHandler::query("SELECT * from customer WHERE customer_id='$customer_id'");
$data = mysqli_fetch_assoc($result);
$this->customer_id = $customer_id;
$this->username = $data['username'];
$this->firstname = $data['firstname'];
$this->lastname = $data['lastname'];
$this->email = $data['email'];
$this->phone_no = $data['phone_no'];
$this->address = $data['address'];
$this->latitude = $data['latitude'];
$this->longitude = $data['longitude'];
$this->password = Password::decrypt($data['password']);
$this->is_worker = $data['is_worker'];
$this->img = $data['img'];
$this->total_hirings_count = $data['total_hirings_count'];
$this->total_payment = $data['total_payment'];
$this->registered_date = $data['registered_date'];
}
public function sendOffer(Customer $customer)
{
$customer_id = $customer->getCustomer_id();
}
/**
* Get the value of customer_id
*/
public function getCustomer_id()
{
return $this->customer_id;
}
/**
* Get the value of username
*/
public function getUsername()
{
return $this->username;
}
/**
* Set the value of username
*/
public function setUsername($username)
{
$this->username = $username;
}
/**
* Get the value of firstname
*/
public function getFirstname()
{
return $this->firstname;
}
/**
* Set the value of firstname
*/
public function setFirstname($firstname)
{
QueryHandler::query("UPDATE `customer` SET firstname = '" . $firstname . "' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->firstname = $firstname;
}
/**
* Get the value of lastname
*/
public function getLastname()
{
return $this->lastname;
}
/**
* Set the value of lastname
*/
public function setLastname($lastname)
{
QueryHandler::query("UPDATE `customer` SET lastname = '" . $lastname . "' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->lastname = $lastname;
}
/**
* Get the value of email
*/
public function getEmail()
{
return $this->email;
}
/**
* Set the value of email
*/
public function setEmail($email)
{
$this->email = $email;
}
/**
* Get the value of phone_no
*/
public function getPhone_no()
{
return $this->phone_no;
}
/**
* Set the value of phone_no
*/
public function setPhone_no($phone_no)
{
QueryHandler::query("UPDATE `customer` SET phone_no = '" . $phone_no . "' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->phone_no = $phone_no;
}
/**
* Get the value of address
*/
public function getAddress()
{
return $this->address;
}
/**
* Set the value of address
*/
public function setAddress($address)
{
QueryHandler::query("UPDATE `customer` SET address = '" . QueryHandler::real_escape_string($address) . "' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->address = $address;
}
/**
* Get the value of latitude
*/
public function getLatitude()
{
return $this->latitude;
}
/**
* Set the value of latitude
*/
public function setLatitude($latitude)
{
QueryHandler::query("UPDATE `customer` SET latitude = '" . $latitude . "' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->latitude = $latitude;
}
/**
* Get the value of longitude
*/
public function getLongitude()
{
return $this->longitude;
}
/**
* Set the value of longitude
*/
public function setLongitude($longitude)
{
QueryHandler::query("UPDATE `customer` SET longitude = '" . $longitude . "' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->longitude = $longitude;
}
/**
* Get the value of password
*/
public function getPassword()
{
return $this->password;
}
/**
* Set the value of password
*/
public function setPassword($password)
{
$newpassword = Password::encrypt($password);
QueryHandler::query("UPDATE `customer` SET password = '$newpassword' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->password = $password;
}
/**
* Get the value of is_worker
*/
public function getIs_worker()
{
return $this->is_worker;
}
/**
* Set the value of is_worker
*/
public function setIs_worker($is_worker)
{
QueryHandler::query("UPDATE `customer` SET is_worker = '" . QueryHandler::real_escape_string($is_worker) . "' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->is_worker = $is_worker;
}
/**
* Get the value of img
*/
public function getImg()
{
if (isset($this->tmp_image)) {
return $this->tmp_image;
}
return $this->img;
}
/**
* Set the value of img
*/
public function setImg($img)
{
QueryHandler::query("UPDATE `customer` SET img = '$img' WHERE customer_id = '" . $this->customer_id . "' LIMIT 1");
$this->img = $img;
}
/**
* Get the value of total_hirings_count
*/
public function getTotal_hirings_count()
{
return $this->total_hirings_count;
}
/**
* Set the value of total_hirings_count
*/
public function setTotal_hirings_count($total_hirings_count)
{
$this->total_hirings_count = $total_hirings_count;
}
/**
* Get the value of total_payment
*/
public function getTotal_payment()
{
return $this->total_payment;
}
/**
* Set the value of total_payment
*/
public function setTotal_payment($total_payment)
{
$this->total_payment = $total_payment;
}
/**
* Get the value of registered_date
*/
public function getRegistered_date()
{
return $this->registered_date;
}
/**
* Set the value of registered_date
*/
public function setRegistered_date($registered_date)
{
$this->registered_date = $registered_date;
}
public function editProfile($customerNewDetails)
{
$error = "";
$success = array();
if (array_key_exists("img", $customerNewDetails)) {
rename($customerNewDetails["img"], $this->getImg());
$success[] = "Profile Picture";
}
if ($customerNewDetails["fname"] != $this->getFirstname()) {
$this->setFirstname($customerNewDetails["fname"]);
$success[] = "First Name";
}
if ($customerNewDetails["lname"] != $this->getLastname()) {
$this->setLastname($customerNewDetails["lname"]);
$success[] = "Last Name";
}
if ($customerNewDetails["address"] != $this->getAddress()) {
$this->setAddress($customerNewDetails["address"]);
$this->setLongitude($customerNewDetails["lng"]);
$this->setLatitude($customerNewDetails["lat"]);
$success[] = "Address";
}
if ($customerNewDetails["phoneno"] != $this->getPhone_no()) {
$this->setPhone_no($customerNewDetails["phoneno"]);
$success[] = "Phone Number";
}
if ($customerNewDetails["currentpassword"] != "" && $customerNewDetails["newpassword"] != "") {
if ($customerNewDetails["confirmpassword"] != "") {
if ($this->getPassword() == $customerNewDetails["currentpassword"]) {
if ($customerNewDetails["newpassword"] == $customerNewDetails["confirmpassword"]) {
$this->setPassword($customerNewDetails["newpassword"]);
$success[] = "Password";
} else {
$error = "New password didn't match with confirm password";
}
} else {
$error = "Current password didn't match";
}
} else {
$error = "Confirmation of new password wasn't provided";
}
}
$status = array();
$status["success"] = $success;
$status["error"] = $error;
return $status;
}
public function uploadProfilePic($file)
{
$id = $this->getCustomer_id();
$status = File::upload($file, FileType::IMAGE, "Customer/Assets/customerProfilePic/tmp/$id");
if ($status["errorUploadFile"] == "") {
$this->tmp_image = $status["fileName"];
}
return $status["errorUploadFile"];
}
public function getTmp_image()
{
return $this->tmp_image;
}
public function logout($location)
{
if ($this->getIs_worker() == 1) {
$tradesman = new Tradesman();
$tradesman->read($this->customer_id);
$tradesman->setState(new TradesmanAsTradesman());
$tradesman->setActive_status(new Offline());
}
session_unset();
header("Location: $location");
}
public function registerAsTradesman($tradesmanDetails)
{
$query = "INSERT INTO `tradesman` (`tradesman_id`,`username`,`yrs_of_experience`,`description`) VALUES ('" .
$this->customer_id . "','" .
$this->username . "','" .
$tradesmanDetails["experience"] . "','" .
$tradesmanDetails["description"] . "'" .
")";
if (QueryHandler::query($query)) {
foreach ($tradesmanDetails['works'] as $work) {
$this->addService($work);
}
$this->setIs_worker(1);
header("Location: header.php");
}
}
public function addService($provider_name)
{
$service = new Service();
$service->readByPName($provider_name);
$query = "INSERT INTO `service_of_tradesman` (`tradesman_id`,`service_id`,`service_name`) VALUES ('" .
$this->customer_id . "','" .
$service->getService_id() . "','" .
$service->getService_name() . "'" .
")";
QueryHandler::query($query);
$service->setTotal_tradesman(($service->getTotal_tradesman() + 1));
return $service->getService_id();
}
public function searchService($enteredService)
{
$sql = "SELECT `service_id` FROM `service` WHERE service_name = '$enteredService'";
$result = QueryHandler::query($sql);
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
return $row["service_id"];
} else {
return false;
}
}
public function searchTradesman($enteredTradesman)
{
$sql = "SELECT `tradesman_id` FROM `tradesman` WHERE username = '$enteredTradesman'";
$result = QueryHandler::query($sql);
if ($result->num_rows == 1) {
$row = $result->fetch_assoc();
return $row["tradesman_id"];
} else {
return false;
}
}
public function search($enteredST)
{
if (($service_id = $this->searchService($enteredST))) {
Header("Location: service.php?id=$service_id");
} else if (($tradesman_id = $this->searchTradesman($enteredST))) {
Header("Location: tradesmanProfile.php?id=$tradesman_id");
}
return false;
}
public function findNearTradesmanHireNow($lat1, $lng1, $service_id)
{
$distanceArr = array();
//$tradesman_lat_lng = "SELECT latitude,longitude,customer_id FROM customer WHERE customer_id !=' $this->customer_id'";
//$tradesman_lat_lng2 = "SELECT customer.latitude, customer.longitude, customer.customer_id FROM customer,tradesman,service_of_tradesman WHERE tradesman.tradesman_id !=' $this->customer_id' AND service_of_tradesman.service_id='$service_id' AND tradesman.active_status='online'";
$query_service = "SELECT tradesman_id FROM service_of_tradesman WHERE service_id =' $service_id'";
$query_service_result = QueryHandler::query($query_service);
if (mysqli_num_rows($query_service_result) > 0) {
while ($row1 = mysqli_fetch_assoc($query_service_result)) {
$tradesmanID = $row1['tradesman_id'];
$tradesman_query = "SELECT tradesman_id FROM tradesman WHERE tradesman_id = '$tradesmanID' AND active_status ='online'";
$tradesman_result = QueryHandler::query($tradesman_query);
//echo "<script>console.log($tradesmanID)</script>";
if (mysqli_num_rows($tradesman_result) > 0) {
while ($row2 = mysqli_fetch_assoc($tradesman_result)) {
$tradesmanID2 = $row2['tradesman_id'];
$tradesman_lat_lng = "SELECT latitude,longitude,customer_id FROM customer WHERE customer_id ='$tradesmanID2' AND customer_id !=' $this->customer_id'";
$lat_lng_result = QueryHandler::query($tradesman_lat_lng);
if (mysqli_num_rows($lat_lng_result) > 0) {
while ($row1 = mysqli_fetch_assoc($lat_lng_result)) {
$lat2 = $row1['latitude'];
$lng2 = $row1['longitude'];
$tradesman_id = $row1['customer_id'];
// echo "<script>let x{$tradesman_id};</script>";
// $temp='';
// echo "<script>x{$tradesman_id}=(getDistanceFromLatlngInKm($lat1,$lng1,$lat2,$lng2));</script>";
// $temp = "<script>document.writeln(x{$tradesman_id})</script>";
// echo "<script>alert({$temp})</script>";
$delta_lat = $lat2 - $lat1;
$delta_lon = $lng2 - $lng1;
$earth_radius = 6372.795477598;
$alpha = $delta_lat / 2;
$beta = $delta_lon / 2;
$a = sin(deg2rad($alpha)) * sin(deg2rad($alpha)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin(deg2rad($beta)) * sin(deg2rad($beta));
$c = asin(min(1, sqrt($a)));
$distance = 2 * $earth_radius * $c;
$distance = round($distance, 4);
$distanceArr[$tradesman_id] = $distance;
}
}
}
}
}
}
$js = json_encode($distanceArr);
echo "<script>console.log($js)</script>";
asort($distanceArr);
//echo "<script>let x = initMap2()</script>";
return $distanceArr;
}
public function findNearTradesmanHireSchedule($lat1, $lng1, $service_id)
{
$distanceArr = array();
//$tradesman_lat_lng = "SELECT latitude,longitude,customer_id FROM customer WHERE customer_id !=' $this->customer_id'";
//$tradesman_lat_lng2 = "SELECT customer.latitude, customer.longitude, customer.customer_id FROM customer,tradesman,service_of_tradesman WHERE tradesman.tradesman_id !=' $this->customer_id' AND service_of_tradesman.service_id='$service_id'";
$query_service = "SELECT tradesman_id FROM service_of_tradesman WHERE service_id =' $service_id'";
$query_service_result = QueryHandler::query($query_service);
if (mysqli_num_rows($query_service_result) > 0) {
while ($row1 = mysqli_fetch_assoc($query_service_result)) {
$tradesmanID = $row1['tradesman_id'];
$tradesman_query = "SELECT tradesman_id FROM tradesman WHERE tradesman_id = '$tradesmanID' ";
$tradesman_result = QueryHandler::query($tradesman_query);
if (mysqli_num_rows($tradesman_result) > 0) {
while ($row2 = mysqli_fetch_assoc($tradesman_result)) {
$tradesmanID2 = $row2['tradesman_id'];
$tradesman_lat_lng = "SELECT latitude,longitude,customer_id FROM customer WHERE customer_id ='$tradesmanID2' AND customer_id !=' $this->customer_id'";
$lat_lng_result = QueryHandler::query($tradesman_lat_lng);
if (mysqli_num_rows($lat_lng_result) > 0) {
while ($row1 = mysqli_fetch_assoc($lat_lng_result)) {
$lat2 = $row1['latitude'];
$lng2 = $row1['longitude'];
$tradesman_id = $row1['customer_id'];
$delta_lat = $lat2 - $lat1;
$delta_lon = $lng2 - $lng1;
$earth_radius = 6372.795477598;
$alpha = $delta_lat / 2;
$beta = $delta_lon / 2;
$a = sin(deg2rad($alpha)) * sin(deg2rad($alpha)) + cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * sin(deg2rad($beta)) * sin(deg2rad($beta));
$c = asin(min(1, sqrt($a)));
$distance = 2 * $earth_radius * $c;
$distance = round($distance, 4);
$distanceArr[$tradesman_id] = $distance;
}
}
}
}
}
}
$js = json_encode($distanceArr);
echo "<script>console.log($js)</script>";
asort($distanceArr);
return $distanceArr;
}
}
class Tradesman extends Customer
{
private $tradesman_id;
private $yrs_of_experience;
private $description;
private $active_status;
private $num_of_review;
private $num_of_ratings;
private $average_rating;
private $total_earnings;
private $num_of_hirings;
private $reg_date_as_tradesman;
private $state;
private $services;
private $tradesmans;
private $hiring_list;
public function __construct()
{
}
public static function getInstance($tradesman_id)
{
if (!array_key_exists($tradesman_id, self::$tradesmans)) {
$sql = "SELECT `tradesman_id` FROM `tradesman` WHERE customer_id = $tradesman_id";
if (QueryHandler::query($sql)->num_rows == 0) {
return null;
} else {
self::$tradesmans[$tradesman_id] = new Customer();
self::$tradesmans[$tradesman_id]->read($tradesman_id);
}
}
return self::$tradesmans[$tradesman_id];
}
public function read($tradesman_id)
{
parent::read($tradesman_id);
$this->tradesman_id = $tradesman_id;
$result = QueryHandler::query("SELECT * from tradesman WHERE tradesman_id='$tradesman_id'");
$row = mysqli_fetch_assoc($result);
$this->yrs_of_experience = $row['yrs_of_experience'];
$this->description = $row['description'];
$this->num_of_review = $row['num_of_reviews'];
$this->average_rating = $row['average_rating'];
$this->num_of_ratings = $row['num_of_ratings'];
$this->total_earnings = $row['total_earnings'];
$this->num_of_hirings = $row['num_of_hirings'];
$this->reg_date_as_tradesman = $row['reg_date_as_tradesman'];
if ($row['state'] == "TAT") {
$this->state = new TradesmanAsTradesman();
} else {
$this->state = new TradesmanAsCustomer();
}
if ($row['active_status'] == "ONLINE") {
$this->active_status = new Online();
} else {
$this->active_status = new Offline();
}
$query = "SELECT `service_id` FROM `service_of_tradesman` WHERE tradesman_id = $tradesman_id";
$result = QueryHandler::query($query);
$rows = $result->fetch_all(MYSQLI_ASSOC);
foreach ($rows as $row) {
//$service = new Service();
//$service->read($row['service_id']);
$this->services[] = $row['service_id'];
}
}
public function checkHiringTimeCome($tradesman_id)
{
echo "Tradesman ID is : " . $tradesman_id . " <br>";
$result = QueryHandler::query("SELECT * from hiring WHERE tradesman_id='$tradesman_id'");
while ($row = mysqli_fetch_assoc($result)) {
$html = '';
if (($row['date'] != NULL) && ($row['date'] == date("Y-m-d"))) {
$timeNow = date("H:i:s");
$timeNow = strtotime("+270 minutes", strtotime($timeNow));
$timeNow = date("H:i:s", ($timeNow));
echo $timeNow . " ";
$timeHiring = $row['time'];
$timeHiring = date("H:i:s", strtotime($timeHiring));
echo $timeHiring . " ";
$hiringNotifyStart = strtotime("-60 minutes", strtotime($timeHiring));
$hiringNotifyStart = date("H:i:s", ($hiringNotifyStart));
echo $hiringNotifyStart . " <br>";
echo $row['date'];
echo "<br>";
echo "today....";
if (($timeNow < $timeHiring) && ($hiringNotifyStart < $timeNow)) {
echo "you have an shedule within some time";
}
}
}
return $html;
}
/**
* Get the value of tradesman_id
*/
public function getTradesman_id()
{
return $this->tradesman_id;
}
/**
* Get the value of yrs_of_experience
*/
public function getYrs_of_experience()
{
return $this->yrs_of_experience;
}
/**
* Set the value of yrs_of_experience
*/
public function setYrs_of_experience($yrs_of_experience)
{
$this->yrs_of_experience = $yrs_of_experience;
}
/**
* Get the value of description
*/
public function getDescription()
{
return $this->description;
}
/**
* Set the value of description
*/
public function setDescription($description)
{
QueryHandler::query("UPDATE `tradesman` SET description = '$description' WHERE tradesman_id = '" . $this->tradesman_id . "' LIMIT 1");
$this->description = $description;
}
/**
* Get the value of active_status
*/
public function getActive_status()
{
return $this->active_status;
}
/**
* Set the value of active_status
*/
public function setActive_status($active_status)
{
$stateType = $active_status->getACTIVE_STATUS();
QueryHandler::query("UPDATE `tradesman` SET active_status = '$stateType' WHERE tradesman_id = '" . $this->tradesman_id . "' LIMIT 1");
$this->active_status = $active_status;
}
/**
* Get the value of num_of_review
*/
public function getNum_of_review()
{
return $this->num_of_review;
}
/**
* Set the value of num_of_review
*/
public function setNum_of_review($num_of_review)
{
$this->num_of_review = $num_of_review;
}
/**
* Get the value of num_of_ratings
*/
public function getNum_of_ratings()
{
return $this->num_of_ratings;
}
/**
* Set the value of num_of_ratings
*/
public function setNum_of_ratings($num_of_ratings)
{
$this->num_of_ratings = $num_of_ratings;
}
/**
* Get the value of average_rating
*/
public function getAverage_rating()
{
return $this->average_rating;
}
/**
* Set the value of average_rating
*/
public function setAverage_rating($average_rating)
{
$this->average_rating = $average_rating;
}
/**
* Get the value of total_earnings
*/
public function getTotal_earnings()
{
return $this->total_earnings;
}
/**
* Set the value of total_earnings
*/
public function setTotal_earnings($total_earnings)
{
$this->total_earnings = $total_earnings;
}
/**
* Get the value of num_of_hirings
*/
public function getNum_of_hirings()
{
return $this->num_of_hirings;
}
/**
* Set the value of num_of_hirings
*/
public function setNum_of_hirings($num_of_hirings)
{
$this->num_of_hirings = $num_of_hirings;
}
/**
* Get the value of reg_date_as_tradesman
*/
public function getReg_date_as_tradesman()
{
return $this->reg_date_as_tradesman;
}
public function editProfile($customerNewDetails)
{
$status = parent::editProfile($customerNewDetails);
if ($customerNewDetails["description"] != $this->getDescription()) {
$this->setDescription($customerNewDetails["description"]);
$status["success"][] = "Description";
}
foreach ($customerNewDetails['works'] as $work) {
$this->addService($work);
}
foreach ($this->services as $service_id) {
$service = new Service();
$service->read($service_id);
if (!in_array($service->getProvider_name(), $customerNewDetails['works'])) {
$this->removeService($service->getProvider_name());
}
}
return $status;
}
public function addService($provider_name)
{
$service = new Service();
$service->readByPName($provider_name);
if (!in_array($service->getService_id(), $this->services)) {
$this->services[] = parent::addService($provider_name);
}
}
public function removeService($provider_name)
{
$service = new Service();
$service->readByPName($provider_name);
if (in_array($service->getService_id(), $this->services)) {
$id = $service->getService_id();
$query = "DELETE FROM `service_of_tradesman` WHERE tradesman_id = $this->tradesman_id AND service_id = $id";
QueryHandler::query($query);
unset($this->services[array_search($id, $this->services)]);
$service->setTotal_tradesman(($service->getTotal_tradesman() - 1));
}
}
public function switch()
{
$this->state->switch($this);
}
public function toggle()
{
$this->active_status->toggle($this);
}
public function getState()
{
return $this->state;
}
public function setState($state)
{
$stateType = $state->getSTATE();
QueryHandler::query("UPDATE `tradesman` SET state = '$stateType' WHERE tradesman_id = '" . $this->tradesman_id . "' LIMIT 1");
$this->state = $state;
}
public function isOnline()
{
return $this->active_status instanceof Online;
}
public function login()
{
$this->setActive_status(new Online());
}
public function hasService($service_id)
{
// foreach ($this->services as $service) {
// if ($service->getProvider_name() == $provider_name) {
// return true;
// }
// }
// return false;
return in_array($service_id, $this->services);
}
}
abstract class TradesmanState
{
private $STATE;
public function __construct($STATE)