-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSlot.php
97 lines (93 loc) · 2.36 KB
/
Slot.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
<?php
abstract class State{ //state as object pattern
//private static $state; //singleton pattern
function __construct(){}
abstract function getState();
// abstract function goAvailable(Slot $slot);
// abstract function goOccupied(Slot $slot);
// abstract function goConsulted(Slot $slot);
}
class OccupiedState extends State{
function goConsulted(Slot $slot){
$slot.setState(new ConsultedState());
}
function goAvailable(Slot $slot){
$slot.setState(new AvailableState());
}
public function getState(){
// if ($this->state==null){
// $state=new OccupiedState();
// }
return 1;
}
}
class ConsultedState extends State{
function getState(){
// if ($this->state==null){
// $state=new ConsultedState();
// }
return 2;
}
}
class AvailableState extends State{
function goOccupied($slot){
$slot->setState(new OccupiedState());
}
function getState(){
// if ($this->state==null){
// $state=new AvailableState();
// }
// echo "avail";
return 0;
}
function asd(){
echo "rrr";
return 4;
}
}
class Slot{
private $sesID;
public $userID;
public $current=null;
function __construct($sesID,$status,$userID){
$this->sesID=$sesID;
$this->userID=$userID;
if($status==0){ $this->current=new AvailableState();}
if($status==1){ $this->current=new OccupiedState();}
if($status==2){ $this->current=new ConsultedState();}
}
function setState($state){
$this->current=$state;
echo $state;
}
function updateUser($userID){
$this->userID=$userID;
}
function getUserID(){
return $this->userID;
}
function goCon(){
$this->current->goConsulted($this);
// echo "gg";
}
function goOcc(){
$this->current->goOccupied($this);
}
function goAvailable(){
$this->current->goAvailable($this);
}
function getState(){
$this->current->getState();
}
function aaa(){
$this->current->asd();
}
}
$ss=new Slot(4,0,1);
$r=$ss->aaa();
$e=$ss->getState();
// $q=$ss->getUserID();
echo $r;
// echo $ss->current->asd();
// $s->goCon();
?>