-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClasses.php
More file actions
225 lines (192 loc) · 4.5 KB
/
Classes.php
File metadata and controls
225 lines (192 loc) · 4.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
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
<?php
include 'connect.php';
include 'helper_functions.php';
class db_Object extends db_io
/*
* Generic object for interactions with mysql databases.
*
* Parameter:
* database ... Database: defined in __construct
* db_table ... The database table: defined in the __construct of childs.
*
* Creation of database rows:
* db_Object::create_db_entry($row);
* where row can be a single parameter or an array.
*
* Access rows of the database:
* db_Object::access_db_entry($id);
* where $id is the id of the row.
* By default the $this->row variable is filled with the returned row, by $this->setter. The
* setter function can be overriden in child classes to access certain entries.
*
*/
{
protected $id;
protected $row;
public function __construct($db_table)
{
$year = date("Y");
$database = "Zieger_Miete_" . $year;
parent::__construct($database, $db_table);
}
// to create a new database entry:
public static function create_db_entry($row)
{
$instance = new static();
$instance->row = $row;
$instance->write_on_db($row);
return $instance;
}
// to open new object
public static function access_db_entry($id)
{
$instance = new static();
$instances = array();
$instance->read_from_db($what = "*", $where = $id);
while ($instance->row = $instance->result->fetch(PDO::FETCH_ASSOC)) {
if (isset($instance->row["id"])) {
$instance->id = $instance->row["id"];
}
$instances[] = clone $instance;
}
return returner($instances);
}
/**
*
* @return mixed
*/
public function getRow()
{
return $this->row;
}
public function getId()
{
return $this->id;
}
}
class mainObject extends db_Object
/*
* Hauptobjekte:
*
* Wohungen, Häuser
*
*/
{
public function __construct()
{
parent::__construct("main_objects");
}
/**
*
* @return mixed
*/
public function getName()
{
return $this->row["name"];
}
public function objects(){
return subObject::access_db_entry("main_id=" . $this->id);
}
}
class subObject extends db_Object
/*
* Mietobjekte:
*
* Zimmer in Wohungen, Wohnungen in Häusern
*
* new parameter:
* main_id ... id of main object, the sub_object belongs to
*
*/
{
public function __construct()
{
parent::__construct("sub_objects");
}
/**
*
* @return mixed
*/
public function getName()
{
return $this->row["name"];
}
public function tenant()
{
$contract = contract::access_db_entry("object_id=" . $this->id);
$tenant = tenant::access_db_entry("id=" . $contract->getTenantId());
}
}
class tenant extends db_Object
/*
* Tenant basic information.
*/
{
private $contracts;
public function __construct()
{
parent::__construct("tenants");
}
/**
*
* @return mixed
*/
public function getName()
{
return $this->$this->row["name"];
}
public function getfName()
{
return $this->row["fName"];
}
public function contracts()
{
return contract::access_db_entry("tenant_id=" . $this->id);
}
public function objects()
// returns all subObjects rented by tentant
{
$contracts = $this->contracts();
foreach ($contracts as $contract) {
$object = subObject::access_db_entry("id=" . $contract->getObjectId());
$objects[] = clone $object;
}
return returner($objects);
}
public function payments()
// returns all payments of selected year, of the actual tentant
{
$payments = payment::access_db_entry("tenant_id=" . $this->id);
return $payments;
}
}
class payment extends db_Object
{
public function __construct()
{
parent::__construct("payments");
}
}
class contract extends db_Object
{
public function __construct()
{
parent::__construct("contracts");
}
protected function getTenantId()
{
return $this->row["tenant_id"];
}
protected function getObjectId()
{
return $this->row["object_id"];
}
public function getData()
{
$data=array();
$data["rent"]=$this->row["rent"];
$data["deposit"]=$this->row["deposit"];
$data["enter_date"]=$this->row["enter_date"];
return $data;
}
}