Skip to content

Commit a7566da

Browse files
committed
Update HtmlModal.php
1 parent 243a1c8 commit a7566da

File tree

1 file changed

+117
-80
lines changed

1 file changed

+117
-80
lines changed
Lines changed: 117 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Ajax\semantic\html\modules;
43

54
use Ajax\semantic\html\base\HtmlSemDoubleElement;
@@ -10,188 +9,226 @@
109
use Ajax\semantic\html\elements\HtmlImage;
1110
use Ajax\semantic\html\elements\HtmlIcon;
1211

12+
/**
13+
*
14+
* @author jc
15+
*
16+
*/
1317
class HtmlModal extends HtmlSemDoubleElement {
14-
protected $_params=array();
15-
protected $_paramParts=array();
1618

17-
public function __construct($identifier, $header="", $content="", $actions=null) {
18-
parent::__construct($identifier, "div","ui modal");
19-
if(isset($header)){
19+
protected $_params = [];
20+
21+
protected $_paramParts = [];
22+
23+
public function __construct($identifier, $header = '', $content = '', $actions = null) {
24+
parent::__construct($identifier, 'div', 'ui modal');
25+
if (isset($header)) {
2026
$this->setHeader($header);
2127
}
22-
if(isset($content)){
28+
if (isset($content)) {
2329
$this->setContent($content);
2430
}
25-
if(isset($actions)){
31+
if (isset($actions)) {
2632
$this->setActions($actions);
2733
}
2834
}
2935

3036
public function setHeader($value) {
31-
$this->content["header"]=new HtmlSemDoubleElement("header-" . $this->identifier, "a", "header", $value);
37+
$this->content['header'] = new HtmlSemDoubleElement('header-' . $this->identifier, 'a', 'header', $value);
3238
return $this;
3339
}
3440

3541
public function setContent($value) {
36-
$this->content["content"]=new HtmlSemDoubleElement("content-" . $this->identifier, "div", "content", $value);
42+
$this->content['content'] = new HtmlSemDoubleElement('content-' . $this->identifier, 'div', 'content', $value);
3743
return $this;
3844
}
3945

40-
public function setActions($actions) {
41-
$this->content["actions"]=new HtmlSemDoubleElement("content-" . $this->identifier, "div", "actions");
42-
if(\is_array($actions)){
43-
foreach ($actions as $action){
44-
$this->addAction($action);
46+
/**
47+
* Adds the modal actions (buttons).
48+
*
49+
* @param string|array $actions
50+
* @return HtmlButton[]
51+
*/
52+
public function setActions($actions): array {
53+
$this->content['actions'] = new HtmlSemDoubleElement('content-' . $this->identifier, 'div', 'actions');
54+
$r = [];
55+
if (\is_array($actions)) {
56+
foreach ($actions as $action) {
57+
$r[] = $this->addAction($action);
4558
}
59+
} else {
60+
$r[] = $this->addAction($actions);
4661
}
47-
else{
48-
$this->addAction($actions);
49-
}
50-
return $this;
62+
return $r;
5163
}
5264

5365
/**
66+
*
5467
* @param string|BaseHtml $action
5568
* @return HtmlButton
5669
*/
57-
public function addAction($action){
58-
if(!$action instanceof BaseHtml){
59-
$class="";
60-
if(\array_search($action, ["Okay","Yes","Validate"])!==false){
61-
$class="approve";
70+
public function addAction($action) {
71+
if (! $action instanceof BaseHtml) {
72+
$class = '';
73+
if (\array_search($action, [
74+
'Okay',
75+
'Yes',
76+
'Validate'
77+
]) !== false) {
78+
$class = 'approve';
6279
}
63-
if(\array_search($action, ["Close","Cancel","No"])!==false){
64-
$class="cancel";
80+
if (\array_search($action, [
81+
'Close',
82+
'Cancel',
83+
'No'
84+
]) !== false) {
85+
$class = 'cancel';
6586
}
66-
$action=new HtmlButton("action-".$this->identifier."-".JArray::count($this->content["actions"]->getContent()),$action);
67-
if($class!=="")
68-
$action->addToProperty("class", $class);
87+
$action = new HtmlButton('action-' . $this->identifier . '-' . JArray::count($this->content['actions']->getContent()), $action);
88+
if ($class !== '')
89+
$action->addToProperty('class', $class);
6990
}
70-
return $this->addElementInPart($action, "actions");
91+
return $this->addElementInPart($action, 'actions');
7192
}
7293

7394
/**
95+
*
7496
* @param int $index
7597
* @return HtmlButton
7698
*/
77-
public function getAction($index){
78-
return $this->content["actions"]->getContent()[$index];
99+
public function getAction($index) {
100+
return $this->content['actions']->getContent()[$index];
79101
}
80102

81-
public function addContent($content,$before=false){
82-
$this->content["content"]->addContent($content,$before);
103+
public function addContent($content, $before = false) {
104+
$this->content['content']->addContent($content, $before);
83105
return $this;
84106
}
85107

86-
public function addImageContent($image,$description=NULL){
87-
$content=$this->content["content"];
88-
if(isset($description)){
89-
$description=new HtmlSemDoubleElement("description-".$this->identifier,"div","description",$description);
90-
$content->addContent($description,true);
108+
public function addImageContent($image, $description = NULL) {
109+
$content = $this->content['content'];
110+
if (isset($description)) {
111+
$description = new HtmlSemDoubleElement('description-' . $this->identifier, 'div', 'description', $description);
112+
$content->addContent($description, true);
91113
}
92-
if($image!==""){
93-
$img=new HtmlImage("image-".$this->identifier,$image,"","medium");
94-
$content->addContent($img,true);
95-
$content->addToProperty("class","image");
114+
if ($image !== '') {
115+
$img = new HtmlImage('image-' . $this->identifier, $image, '', 'medium');
116+
$content->addContent($img, true);
117+
$content->addToProperty('class', 'image');
96118
}
97119
return $this;
98120
}
99121

100-
public function addIconContent($icon,$description=NULL){
101-
$content=$this->content["content"];
102-
if(isset($description)){
103-
$description=new HtmlSemDoubleElement("description-".$this->identifier,"div","description",$description);
104-
$content->addContent($description,true);
122+
public function addIconContent($icon, $description = NULL) {
123+
$content = $this->content['content'];
124+
if (isset($description)) {
125+
$description = new HtmlSemDoubleElement('description-' . $this->identifier, 'div', 'description', $description);
126+
$content->addContent($description, true);
105127
}
106-
if($icon!==""){
107-
$img=new HtmlIcon("image-".$this->identifier,$icon);
108-
$content->addContent($img,true);
109-
$content->addToProperty("class","image");
128+
if ($icon !== '') {
129+
$img = new HtmlIcon('image-' . $this->identifier, $icon);
130+
$content->addContent($img, true);
131+
$content->addToProperty('class', 'image');
110132
}
111133
return $this;
112134
}
113135

114-
private function addElementInPart($element,$part) {
136+
private function addElementInPart($element, $part) {
115137
$this->content[$part]->addContent($element);
116138
return $element;
117139
}
118140

119-
public function showDimmer($value){
120-
$value=$value?"show":"hide";
121-
$this->_paramParts[]=["'".$value." dimmer'"];
141+
public function showDimmer($value) {
142+
$value = $value ? 'show' : 'hide';
143+
$this->_paramParts[] = [
144+
"'" . $value . " dimmer'"
145+
];
122146
return $this;
123147
}
124148

125-
public function setInverted($recursive=true){
126-
$this->_params["inverted"]=true;
149+
public function setInverted($recursive = true) {
150+
$this->_params['inverted'] = true;
127151
return $this;
128152
}
129153

130-
public function setBasic(){
131-
return $this->addToProperty("class", "basic");
154+
public function setBasic() {
155+
return $this->addToProperty('class', 'basic');
132156
}
133157

134-
135-
public function setTransition($value){
136-
$this->_paramParts[]=["'setting'","'transition'","'".$value."'"];
158+
public function setTransition($value) {
159+
$this->_paramParts[] = [
160+
"'setting'",
161+
"'transition'",
162+
"'" . $value . "'"
163+
];
137164
}
138165

139166
/**
140167
* render the content of an existing view : $controller/$action and set the response to the modal content
168+
*
141169
* @param JsUtils $js
142170
* @param object $initialController
143171
* @param string $viewName
144-
* @param array $params The parameters to pass to the view
172+
* @param array $params
173+
* The parameters to pass to the view
145174
*/
146-
public function renderView(JsUtils $js,$initialController,$viewName, $params=array()) {
147-
return $this->setContent($js->renderContent($initialController, $viewName,$params));
175+
public function renderView(JsUtils $js, $initialController, $viewName, $params = array()) {
176+
return $this->setContent($js->renderContent($initialController, $viewName, $params));
148177
}
149178

150179
/**
151180
* render the content of $controller::$action and set the response to the modal content
181+
*
152182
* @param JsUtils $js
153183
* @param object $initialControllerInstance
154-
* @param string $controllerName the controller name
155-
* @param string $actionName the action name
184+
* @param string $controllerName
185+
* the controller name
186+
* @param string $actionName
187+
* the action name
156188
* @param array $params
157189
*/
158-
public function forward(JsUtils $js,$initialControllerInstance,$controllerName,$actionName,$params=NULL){
159-
return $this->setContent($js->forward($initialControllerInstance, $controllerName, $actionName,$params));
190+
public function forward(JsUtils $js, $initialControllerInstance, $controllerName, $actionName, $params = NULL) {
191+
return $this->setContent($js->forward($initialControllerInstance, $controllerName, $actionName, $params));
160192
}
161193

162194
/**
163195
*
164-
* {@inheritDoc}
196+
* {@inheritdoc}
165197
*
166198
* @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile()
167199
*/
168-
public function compile(JsUtils $js=NULL, &$view=NULL) {
169-
$this->content=JArray::sortAssociative($this->content, ["header","content","actions" ]);
170-
if(isset($this->_params["inverted"]) && $this->_params["inverted"]){
200+
public function compile(JsUtils $js = NULL, &$view = NULL) {
201+
$this->content = JArray::sortAssociative($this->content, [
202+
'header',
203+
'content',
204+
'actions'
205+
]);
206+
if (isset($this->_params['inverted']) && $this->_params['inverted']) {
171207
parent::setInverted(true);
172208
}
173209
return parent::compile($js, $view);
174210
}
211+
175212
/*
176213
* (non-PHPdoc)
177214
* @see BaseHtml::run()
178215
*/
179216
public function run(JsUtils $js) {
180-
if(isset($this->_bsComponent)===false)
181-
$this->_bsComponent=$js->semantic()->modal("#".$this->identifier,$this->_params,$this->_paramParts);
217+
if (isset($this->_bsComponent) === false)
218+
$this->_bsComponent = $js->semantic()->modal('#' . $this->identifier, $this->_params, $this->_paramParts);
182219
$this->addEventsOnRun($js);
183220
return $this->_bsComponent;
184221
}
185222

186223
public function jsDo($behavior) {
187-
return "$('#".$this->identifier."').modal('".$behavior."');";
224+
return "$('#" . $this->identifier . "').modal('" . $behavior . "');";
188225
}
189226

190227
public function jsHide() {
191-
return $this->jsDo("hide");
228+
return $this->jsDo('hide');
192229
}
193230

194-
public function onHidden($js){
195-
$this->_params["onHidden"]=$js;
231+
public function onHidden($js) {
232+
$this->_params['onHidden'] = $js;
196233
}
197234
}

0 commit comments

Comments
 (0)