-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoom.php
More file actions
123 lines (111 loc) · 2.5 KB
/
Copy pathRoom.php
File metadata and controls
123 lines (111 loc) · 2.5 KB
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
<?php
class DataRoom
{
private $parent;
private $list_room_replace = [];
private $list_room_declare = [];
private $list_room_will_replace = [];
private $currentRoom;
private $data = [];
private $CI;
public function __construct($will_replace, $ci, $data)
{
$this->list_room_will_replace = $will_replace;
$this->CI = $ci;
$this->data = $data;
}
public function extend($url)
{
$this->parent = $url;
foreach ($this->list_room_will_replace as $key => $value) {
$this->list_room_replace[$key] = $value;
}
$obj = new DataRoom($this->list_room_replace, $this->CI, $this->data);
$this->CI->load->view($url, ['room' => $obj]);
}
public function declare($room)
{
if (isset($this->list_room_will_replace[$room])) {
echo $this->list_room_will_replace[$room];
unset($this->list_room_will_replace[$room]);
};
}
public function open($room)
{
if ($this->currentRoom != NULL) {
show_error("You must close the room before open the room again");
} else {
$this->currentRoom = $room;
if (!isset($this->list_room_replace[$room])) {
ob_start();
}
}
}
public function close()
{
if ($this->currentRoom == NULL) {
show_error("You currently not open in any Room");
} else {
if (!isset($this->list_room_replace[$this->currentRoom])) {
$html = ob_get_clean();
$this->list_room_replace[$this->currentRoom] = $html;
}
$this->currentRoom = NULL;
}
}
public function include($view, $data = null)
{
$room = new DataRoom([], $this->CI, $data);
$r = $this->CI->load->view($view, ['room' => $room]);
}
public function data($key)
{
return $this->data[$key];
}
public function alldata($params = NULL, $type = NULL)
{
if ($type == NULL) {
$type = 'only';
if ($params == NULL) {
$params = $this->data;
}
}
if ($params == NULL) {
$params = [];
}
$ret = [];
$dict_params = [];
foreach ($params as $key => $value) {
$dict_params[$value] = 0;
}
if ($type == 'except') {
foreach ($this->data as $key => $value) {
if (!isset($dict_params[$key])) {
$ret[$key] = $value;
}
}
return $ret;
} else {
foreach ($this->data as $key => $value) {
if (isset($dict_params[$key])) {
$ret[$key] = $value;
}
}
return $ret;
}
}
}
class Room
{
private $CI;
public function __construct()
{
$this->CI = &get_instance();
}
public function load($view, $data = null)
{
if ($data == null) $data = [];
$room = new DataRoom([], $this->CI, $data);
$this->CI->load->view($view, ['room' => $room]);
}
}