Passed
Push — master ( 97a77b...03b721 )
by Jean-Christophe
02:18
created

Toast::setActions()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 8
c 1
b 0
f 1
nc 6
nop 1
dl 0
loc 12
rs 10
1
<?php
2
3
namespace Ajax\semantic\components;
4
5
use Ajax\JsUtils;
6
7
/**
8
 * Ajax\semantic\components$Toast
9
 * This class is part of phpMv-ui
10
 * @author jcheron <[email protected]>
11
 * @version 1.0.0
12
 * @since 2.3.0
13
 * @see https://fomantic-ui.com/modules/toast.html
14
 */
15
class Toast extends SimpleSemExtComponent {
16
17
	public function __construct(JsUtils $js=NULL) {
18
		parent::__construct($js);
19
		$this->uiName='toast';
20
	}
21
22
	public function close(){
23
		return $this->addBehavior('close');
24
	}
25
26
	public function setClass($value){
27
		$this->params['class']=$value;
28
		return $this;
29
	}
30
	
31
	public function setCloseIcon(){
32
		$this->params['closeIcon']=true;
33
		return $this;
34
	}
35
	
36
	public function setShowIcon($value=false){
37
		$this->params['showIcon']=$value;
38
		return $this;
39
	}
40
	
41
	public function setCloseOnClick($value){
42
		$this->params['closeOnClick']=$value;
43
		return $this;
44
	}
45
	
46
	public function setTitle($title){
47
		$this->params['title']=$title;
48
		return $this;
49
	}
50
51
	public function setActions(array $actions){
52
		foreach ($actions as &$action){
53
			if(isset($action['click'])){
54
				$js=\str_ireplace("\"","%quote%", $action['click']);
55
				$action['click']="%function(){".$js."}%";
0 ignored issues
show
Bug introduced by
Are you sure $js of type array|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
				$action['click']="%function(){"./** @scrutinizer ignore-type */ $js."}%";
Loading history...
56
			}
57
		}
58
		$this->params['actions']=$actions;
59
		if(count($actions)>0) {
60
			$this->params['displayTime'] = 0;
61
		}
62
		return $this;
63
	}
64
	
65
	public function setMessage($message){
66
		$this->params['message']=$message;
67
		return $this;
68
	}
69
	
70
	public function setPosition($position){
71
		$this->params['position']=$position;
72
		return $this;
73
	}
74
	
75
	public function setDisplayTime($time){
76
		$this->params['displayTime']=$time;
77
		return $this;
78
	}
79
	
80
	public function setShowProgress($value='top'){
81
		$this->params['showProgress']=$value;
82
		return $this;
83
	}
84
	
85
	public function setClassProgress($value){
86
		$this->params['classProgress']=$value;
87
		return $this;
88
	}
89
90
	public function setOnShow($jsCode) {
91
		$this->addComponentEvent('onShow', $jsCode);
92
	}
93
	
94
	public function setOnHide($jsCode) {
95
		$this->addComponentEvent('onHide', $jsCode);
96
		return $this;
97
	}
98
	
99
	public function setOnApprove($jsCode) {
100
		$this->addComponentEvent('onApprove', $jsCode);
101
		return $this;
102
	}
103
	
104
	public function setOnDeny($jsCode) {
105
		$this->addComponentEvent('onDeny', $jsCode);
106
		return $this;
107
	}
108
}
109