/
Control.php
255 lines (215 loc) · 8.34 KB
/
Control.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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
namespace Concrete\Core\Page\Type\Composer\Control;
use Concrete\Core\Page\Type\Type;
use Loader;
use Concrete\Core\Foundation\ConcreteObject;
use Concrete\Core\Page\Page;
use Controller;
use Concrete\Core\Page\Type\Composer\FormLayoutSet as PageTypeComposerFormLayoutSet;
use Concrete\Core\Page\Type\Composer\FormLayoutSetControl as PageTypeComposerFormLayoutSetControl;
use Concrete\Core\Page\Type\Composer\Control\Type\Type as PageTypeComposerControlType;
use HtmlObject\Element;
abstract class Control extends ConcreteObject
{
protected $ptComposerControlIdentifier;
protected $ptComposerControlName;
protected $ptComposerControlIconSRC;
protected $ptComposerControlIconFormatter;
protected $ptComposerControl;
protected $ptComposerControlRequiredByDefault = false;
protected $ptComposerControlRequiredOnThisRequest = false;
protected $ptComposerControlCustomLabel;
protected $ptComposerControlDescription;
abstract public function getPageTypeComposerControlCustomTemplates();
abstract public function render($label, $customTemplate, $description);
abstract public function publishToPage(Page $c, $data, $controls);
abstract public function validate();
abstract public function getPageTypeComposerControlDraftValue();
abstract public function addAssetsToRequest(Controller $cnt);
abstract public function export($node);
abstract public function shouldPageTypeComposerControlStripEmptyValuesFromPage();
abstract public function isPageTypeComposerControlValueEmpty();
abstract public function removePageTypeComposerControlFromPage();
public function pageTypeComposerFormControlSupportsValidation()
{
return false;
}
public function onPageDraftCreate(Page $c)
{
return false;
}
public function setPageTypeComposerControlName($ptComposerControlName)
{
$this->ptComposerControlName = $ptComposerControlName;
}
public function setPageTypeComposerFormControlRequired($req)
{
$this->ptComposerControlRequiredOnThisRequest = $req;
}
public function setPageTypeComposerControlCustomLabel($label)
{
$this->ptComposerControlCustomLabel = $label;
}
public function getPageTypeComposerControlCustomLabel()
{
return $this->ptComposerControlCustomLabel;
}
public function setPageTypeComposerControlDescription($description)
{
$this->ptComposerControlDescription = $description;
}
public function getPageTypeComposerControlDescription()
{
return $this->ptComposerControlDescription;
}
public function setPageObject($page)
{
$this->page = $page;
}
public function getPageObject()
{
return $this->page;
}
public function setTargetParentPageID($ptTargetParentPageID)
{
$this->ptTargetParentPageID = $ptTargetParentPageID;
}
public function getTargetParentPageID()
{
return $this->ptTargetParentPageID;
}
public function isPageTypeComposerFormControlRequiredOnThisRequest()
{
return $this->ptComposerControlRequiredOnThisRequest;
}
public function getPageTypeComposerControlName()
{
return $this->ptComposerControlName;
}
public function getPageTypeComposerControlDisplayName($format = 'html')
{
$value = $this->getPageTypeComposerControlName();
switch ($format) {
case 'html':
return h($value);
case 'text':
default:
return $value;
}
}
public function setPageTypeComposerControlIconSRC($ptComposerControlIconSRC)
{
$this->ptComposerControlIconSRC = $ptComposerControlIconSRC;
}
public function setPageTypeComposerControlIconFormatter($ptComposerControlIconFormatter)
{
$this->ptComposerControlIconFormatter = $ptComposerControlIconFormatter;
}
public function getPageTypeComposerControlIcon()
{
if (isset($this->ptComposerControlIconSRC)) {
$img = new Element('img');
$img->src($this->ptComposerControlIconSRC);
return $img;
} else {
return $this->ptComposerControlIconFormatter->getListIconElement();
}
}
public function setPageTypeComposerControlIdentifier($ptComposerControlIdentifier)
{
$this->ptComposerControlIdentifier = $ptComposerControlIdentifier;
}
public function getPageTypeComposerControlIdentifier()
{
return $this->ptComposerControlIdentifier;
}
public function getPageTypeComposerControlTypeObject()
{
return PageTypeComposerControlType::getByHandle($this->ptComposerControlTypeHandle);
}
public function getPageTypeComposerControlTypeHandle()
{
return $this->ptComposerControlTypeHandle;
}
public function setPageTypeComposerFormLayoutSetControlObject(PageTypeComposerFormLayoutSetControl $setcontrol)
{
$this->ptComposerFormLayoutSetControlObject = $setcontrol;
}
public function getPageTypeComposerFormLayoutSetControlObject()
{
return $this->ptComposerFormLayoutSetControlObject;
}
public function field($key)
{
return 'ptComposer['.$this->ptComposerFormLayoutSetControlObject->getPageTypeComposerFormLayoutSetControlID().']['.$key.']';
}
public function getRequestValue($args = false)
{
if (!$args) {
$args = $_POST;
}
$result = null;
if (isset($args['ptComposer'])) {
$lscID = $this->ptComposerFormLayoutSetControlObject->getPageTypeComposerFormLayoutSetControlID();
if (isset($args['ptComposer'][$lscID])) {
$result = $args['ptComposer'][$lscID];
}
}
return $result;
}
/**
* @param PageTypeComposerFormLayoutSet $set
*
* @return \Concrete\Core\Page\Type\Composer\FormLayoutSetControl
*/
public function addToPageTypeComposerFormLayoutSet(PageTypeComposerFormLayoutSet $set)
{
$db = Loader::db();
$displayOrder = $db->GetOne('select count(ptComposerFormLayoutSetControlID) from PageTypeComposerFormLayoutSetControls where ptComposerFormLayoutSetID = ?', array($set->getPageTypeComposerFormLayoutSetID()));
if (!$displayOrder) {
$displayOrder = 0;
}
$ptComposerFormLayoutSetControlRequired = 0;
if ($this->isPageTypeComposerControlRequiredByDefault()) {
$ptComposerFormLayoutSetControlRequired = 1;
}
$controlType = $this->getPageTypeComposerControlTypeObject();
$customLabel = $this->getPageTypeComposerControlCustomLabel();
$description = $this->getPageTypeComposerControlDescription();
$db->Execute('insert into PageTypeComposerFormLayoutSetControls (ptComposerFormLayoutSetID, ptComposerControlTypeID, ptComposerControlObject, ptComposerFormLayoutSetControlDisplayOrder, ptComposerFormLayoutSetControlCustomLabel, ptComposerFormLayoutSetControlDescription, ptComposerFormLayoutSetControlRequired) values (?, ?, ?, ?, ?, ?, ?)', array(
$set->getPageTypeComposerFormLayoutSetID(), $controlType->getPageTypeComposerControlTypeID(), serialize($this), $displayOrder, $customLabel, $description, $ptComposerFormLayoutSetControlRequired,
));
return PageTypeComposerFormLayoutSetControl::getByID($db->Insert_ID());
}
public function canPageTypeComposerControlSetPageName()
{
return false;
}
public function getPageTypeComposerControlPageNameValue(Page $c)
{
return false;
}
public static function getList(Type $pagetype)
{
$sets = PageTypeComposerFormLayoutSet::getList($pagetype);
$controls = array();
foreach ($sets as $s) {
$setControls = PageTypeComposerFormLayoutSetControl::getList($s);
foreach ($setControls as $sc) {
$cnt = $sc->getPageTypeComposerControlObject();
$cnt->setPageTypeComposerFormLayoutSetControlObject($sc);
$cnt->setPageTypeComposerFormControlRequired($sc->isPageTypeComposerFormLayoutSetControlRequired());
$controls[] = $cnt;
}
}
return $controls;
}
public function isPageTypeComposerControlRequiredByDefault()
{
return $this->ptComposerControlRequiredByDefault;
}
public function objectExists()
{
return true;
}
}