forked from ZerionSoftware/iFormBuilder_PHP
/
ZCPage.php
143 lines (115 loc) · 3.98 KB
/
ZCPage.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
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
<?php
class ZCPage extends ZCObject{
public function __construct($_profileId, $_pageId){
parent::__construct();
$this->PROFILE_ID = $_profileId;
$this->PAGE_ID = $_pageId;
$this->NAME = '';
$this->LABEL = '';
$this->DESCRIPTION = '';
$this->REFERENCE_ID_1 = '';
$this->REFERENCE_ID_2 = '';
$this->REFERENCE_ID_3 = '';
$this->REFERENCE_ID_4 = '';
$this->REFERENCE_ID_5 = '';
//$this->ICON = '';
$this->SORT_ORDER = 1;
$this->JAVASCRIPT = '';
//$this->LABEL_ICONS_URL = '';
$this->ELEMENTS = array();
}
public static function fromServerObj($p){
$_profileId = $p['PROFILE_ID'];
$_pageId = $p['PAGE_ID'];
$instance = new ZCPage($_profileId, $_pageId);
$instance->populateFromServerObj($p);
return $instance;
}
public static function getAllInProfile($profileId){
$api = "profiles/$profileId/pages";
//Sort by ID desc. So the newest is always the first.
$p['SORT'] = 'ID';
$p['SORT_BY'] = 'DESC';
$params = http_build_query($p);
$ifb = iFormBuilder::Instance();
$o = $ifb->sendApiRequest($api, $params, 'GET');
return $o;
}
public static function getPageByName($profileId, $name){
$api = "profiles/$profileId/pages";
$filters = array();
$filter['KEY'] = 'NAME';
$filter['CONDITION'] = '=';
$filter['VALUE'] = $name;
$filters[] = $filter;
$p['FILTER'] = $filters;
$params = http_build_query($p);
$ifb = iFormBuilder::Instance();
$o = $ifb->sendApiRequest($api, $params, 'GET');
//Assume one profile.
$pages = $o['PAGES'];
$pageId = 0;
if (count ($pages)>0) {
$pageId = $pages[0]['ID'];
}
return $pageId;
}
public function pageAssignment($assignTo, $isCollect, $isView){
}
protected function populateFromServerObj($p){
if (isset($p['NAME'])) $this->NAME = $p['NAME'];
if (isset($p['LABEL'])) $this->LABEL = $p['LABEL'];
if (isset($p['DESCRIPTION'])) $this->DESCRIPTION = $p['DESCRIPTION'];
if (isset($p['VERSION'])) $this->VERSION = $p['VERSION'];
if (isset($p['CREATED_DATE'])) $this->CREATED_DATE = $p['CREATED_DATE'];
if (isset($p['CREATED_BY'])) $this->CREATED_BY = $p['CREATED_BY'];
if (isset($p['MODIFIED_DATE'])) $this->MODIFIED_DATE = $p['MODIFIED_DATE'];
if (isset($p['MODIFIED_BY'])) $this->MODIFIED_BY = $p['MODIFIED_BY'];
if (isset($p['_S_ICON_LINK'])) $this->ICON = $p['_S_ICON_LINK'];
if (isset($p['SORT_ORDER'])) $this->SORT_ORDER = $p['SORT_ORDER'];
if (isset($p['PAGE_TYPE'])) $this->PAGE_TYPE = $p['PAGE_TYPE'];
if (isset($p['REFERENCE_ID_1'])) $this->REFERENCE_ID_1 = $p['REFERENCE_ID_1'];
if (isset($p['REFERENCE_ID_2'])) $this->REFERENCE_ID_2 = $p['REFERENCE_ID_2'];
if (isset($p['REFERENCE_ID_3'])) $this->REFERENCE_ID_3 = $p['REFERENCE_ID_3'];
if (isset($p['REFERENCE_ID_4'])) $this->REFERENCE_ID_4 = $p['REFERENCE_ID_4'];
if (isset($p['REFERENCE_ID_5'])) $this->REFERENCE_ID_5 = $p['REFERENCE_ID_5'];
}
public function get(){
$api = "profiles/$this->PROFILE_ID/pages/$this->PAGE_ID";
$params = '';
$ifb = iFormBuilder::Instance();
$o = $ifb->sendApiRequest($api, $params, 'GET');
$p = $o['PAGE'];
$this->populateFromServerObj($p);
//Next populate elements
$eList = $o['ELEMENTS'];
foreach ($eList as $_e){
$_e->PROFILE_ID = $this->PROFILE_ID;
$e = ZCElement::fromServerObj($_e);
$this->ELEMENTS[] = $e;
}
}
public function create(){
$api = "profiles/$this->PROFILE_ID/pages";
$params = json_encode($this);
$ifb = iFormBuilder::Instance();
$o = $ifb->sendApiRequest($api, $params, 'POSTJ');
if ($o['STATUS']==1) $this->PAGE_ID = $o['PAGE_ID'];
return $o;
}
public function edit(){
$api = "profiles/$this->PROFILE_ID/pages/$this->PAGE_ID";
$params = json_encode($this);
$ifb = iFormBuilder::Instance();
$o = $ifb->sendApiRequest($api, $params, 'POSTJ');
return $o;
}
public function delete(){
$api = "profiles/$this->PROFILE_ID/pages/$this->PAGE_ID";
$params = '';
$ifb = iFormBuilder::Instance();
$o = $ifb->sendApiRequest($api, $params, 'DELETE');
return $o;
}
}
?>