-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmainModel.php
More file actions
59 lines (52 loc) · 1.79 KB
/
mainModel.php
File metadata and controls
59 lines (52 loc) · 1.79 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
<?php
use DataBase as DB;
class MainModel {
protected function setConnectDB(){
return (new DB);
}
public function playerDetails($row, $id){
return (object) array_merge([
'id' => $row["id"],
'level' => $row["level"],
'experience' => $row["experience"],
'name' => $row["name"]
], $this->getAttributes($id));
}
public function find($id){
$result = $this->setConnectDB()->queryRun("SELECT * FROM " . strtolower(get_class($this)) . " where id=" . $id);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
return $this->playerDetails($row, $id);
}
} else {
return (object) [];
}
}
public function all(){
$resultArray = [];
$result = $this->setConnectDB()->queryRun("SELECT * FROM " . strtolower(get_class($this)));
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
array_push($resultArray, $this->playerDetails($row, $row["id"]));
}
} else {
return (object) $resultArray;
}
return (object) $resultArray;
}
protected function getAttributes($id){
$attributes = [];
$result = self::setConnectDB()->queryRun("SELECT * FROM attributes_max_min where subject_type = '" . strtolower(get_class($this)) . "' and subject_id=" . $id);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$attributes[$row["subject_attribute"]] = (object) [
'min' => $row["min"],
'max' => $row["max"],
];
}
} else {
return [];
}
return $attributes;
}
}