/
server-json.php
95 lines (72 loc) · 1.82 KB
/
server-json.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
<?php
//added standard php/mysql config file with host, user and password info
require "config.php";
//models and collections
require "domain/models/filter-result-model.php";
require "domain/collection/filter-result-collection.php";
//domain
require "domain/action.php";
require "domain/sorting.php";
require "domain/pagination.php";
require "domain/filtering.php";
require "domain/server.php";
//controls
require "controls/sortdropdown.php";
require "controls/textbox.php";
require "controls/checkboxgroupfilter.php";
require "controls/filterdropdown.php";
require "controls/filterselect.php";
require "controls/button-text-filter.php";
class jPListJSON extends jPListServer{
/**
* get the whole content with wrapper
* it used for pagination count
* @param {string} $itemsJSON - items json
* @return {string} html
*/
function getWrapper($itemsJSON){
$json = "";
$json .= "{";
$json .= "\"count\":" . $this->pagination->numberOfPages;
$json .= ",\"data\":" . $itemsJSON;
$json .= "}";
return $json;
}
/**
* constructor
*/
public function __construct(){
try{
$json = "";
$counter = 0;
parent::__construct();
if(isset($this->statuses)){
$items = $this->getData();
$json .= "[";
if($items){
foreach($items as $item){
if($counter > 0){
$json .= ",";
}
$json .= json_encode($item);
$counter++;
}
}
$json .= "]";
ob_clean();
//print json
echo($this->getWrapper($json));
}
//close the database connection
$this->db = NULL;
}
catch(PDOException $ex){
print "Exception: " . $ex->getMessage();
}
}
}
/**
* start
*/
new jPListJSON();
?>