-
Notifications
You must be signed in to change notification settings - Fork 0
/
review.class.php
115 lines (93 loc) · 2.54 KB
/
review.class.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
<?php
class ReviewCategory implements JsonSerializable {
public $description = "";
public $max_points = 0;
public function __construct($desc, $max_points) {
$this->description = $desc;
$this->max_points = $max_points;
}
public function jsonSerialize() {
return [
"description" => $this->description,
"max_points" => $this->max_points
];
}
}
class ReviewObject implements JsonSerializable {
public $categories = array();
public $name = "";
public function __construct($categories, $name) {
$this->categories = $categories;
$this->name = $name;
}
public function jsonSerialize() {
return [
"name" => $this->name,
"categories" => $this->categories
];
}
}
class Review implements JsonSerializable {
public $objects = array();
public $name = "";
public function __construct($name, $objects) {
$this->objects = $objects;
$this->name = $name;
}
public static function fromJSON($name, $json) {
if(strlen($json) < 5) {
return new self(null);
}
if(is_string($json) || !is_array($json)) {
$json = json_decode($json, JSON_UNESCAPED_UNICODE);
}
$objects = array();
foreach ($json as $object) {
$sectionName = $object['name'];
$categories = array();
foreach ($object['categories'] as $cat) {
$categories[] = new ReviewCategory($cat['description'],((int)$cat['max_points']));
}
$objects[] = new ReviewObject($categories, $sectionName);
}
return new self($name, $objects);
}
public function jsonSerialize() {
return $this->objects;
}
}
/*class ReviewScheme implements JsonSerializable {
public $reviews = array();
public function __construct($reviews) {
$this->reviews = $reviews;
}
public static function fromJSON($json) {
if(strlen($json) < 5) {
return new self(null);
}
if(is_string($json) || !is_array($json)) {
$json = json_decode($json, JSON_UNESCAPED_UNICODE);
}
$reviews = array();
foreach ($json as $review) {
$objects = array();
foreach ($review['sections'] as $object) {
$name = $object['name'];
$categories = array();
foreach ($object['categories'] as $cat) {
$categories[] = new ReviewCategory($cat['description'],((int)$cat['max_points']));
}
$objects[] = new ReviewObject($categories, $name);
}
$reviews[] = new Review($objects);
}
return new self($reviews);
}
public function addReview($obj) {
$this->reviews[] = $obj;
}
public function jsonSerialize() {
return $this->reviews;
}
}*/
?>