Completed
Push — master ( 541276...03d1b2 )
by Jean-Christophe
03:16
created

HtmlButton::setInverted()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Ajax\semantic\html\elements;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
7
/**
8
 * Semantic Button component
9
 * @see http://semantic-ui.com/elements/button.html
10
 * @author jc
11
 * @version 1.001
12
 */
13
class HtmlButton extends HtmlSemDoubleElement {
14
15
	/**
16
	 * Constructs an HTML Semantic button
17
	 * @param string $identifier HTML id
18
	 * @param string $value value of the Button
19
	 * @param string $cssStyle btn-default, btn-primary...
20
	 * @param string $onClick JS Code for click event
21
	 */
22 View Code Duplication
	public function __construct($identifier, $value="", $cssStyle=null, $onClick=null) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
		parent::__construct($identifier, "button");
24
		$this->setProperty("class", "ui button");
25
		$this->content=$value;
26
		if (isset($cssStyle)) {
27
			$this->setStyle($cssStyle);
28
		}
29
		if (isset($onClick)) {
30
			$this->onClick($onClick);
31
		}
32
	}
33
34
	/**
35
	 * Set the button value
36
	 * @param string $value
37
	 * @return \Ajax\semantic\html\HtmlButton
38
	 */
39
	public function setValue($value) {
40
		$this->content=$value;
41
		return $this;
42
	}
43
44
	/**
45
	 * define the button style
46
	 * @param string|int $cssStyle
47
	 * @return \Ajax\semantic\html\HtmlButton default : ""
48
	 */
49
	public function setStyle($cssStyle) {
50
		return $this->addToProperty("class",$cssStyle);
51
	}
52
53
	public function setFocusable(){
54
		$this->setProperty("tabindex", "0");
55
	}
56
57
	public function setAnimated($content,$animation=""){
58
		$this->setTagName("div");
59
		$this->addToProperty("class", "animated ".$animation);
60
		$visible=new HtmlSemDoubleElement("visible-".$this->identifier,"div");
61
		$visible->setClass("visible content");
62
		$visible->setContent($this->content);
63
		$hidden=new HtmlSemDoubleElement("hidden-".$this->identifier,"div");
64
		$hidden->setClass("hidden content");
65
		$hidden->setContent($content);
66
		$this->content=$visible.$hidden;
67
	}
68
69
	/**
70
	 * @param string|HtmlIcon $icon
71
	 * @return \Ajax\semantic\html\elements\HtmlButton
72
	 */
73
	public function asIcon($icon){
74
		$iconO=$icon;
75
		if(\is_string($icon)){
76
			$iconO=new HtmlIcon("icon-".$this->identifier, $icon);
77
		}
78
		$this->addToProperty("class", "icon");
79
		$this->content=$iconO;
80
		return $this;
81
	}
82
83
	/**
84
	 * Add and return a button label
85
	 * @param string $caption
86
	 * @param string $before
87
	 * @return \Ajax\semantic\html\elements\HtmlLabel
88
	 */
89
	public function addLabel($caption,$before=false){
90
		$this->tagName="div";
91
		$this->addToProperty("class", "labeled");
92
		$this->content=new HtmlButton("button-".$this->identifier,$this->content);
93
		$this->content->setTagName("div");
94
		$label=new HtmlLabel("label-".$this->identifier,$caption,"a");
95
		$label->setBasic();
96
		$this->addContent($label,$before);
0 ignored issues
show
Bug introduced by
It seems like $before defined by parameter $before on line 89 can also be of type string; however, Ajax\common\html\HtmlDoubleElement::addContent() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
97
		return $label;
98
	}
99
	/*
100
	 * (non-PHPdoc)
101
	 * @see \Ajax\common\html\BaseHtml::fromArray()
102
	 */
103
	public function fromArray($array) {
104
		$array=parent::fromArray($array);
105
		foreach ( $array as $key => $value ) {
106
			$this->setProperty($key, $value);
107
		}
108
		return $array;
109
	}
110
111
	/**
112
	 *  show it is currently the active user selection
113
	 * @return \Ajax\semantic\html\elements\HtmlButton
114
	 */
115
	public function setActive(){
116
		return $this->addToProperty("class", "active");
117
	}
118
119
	/**
120
	 * hint towards a positive consequence
121
	 * @return \Ajax\semantic\html\elements\HtmlButton
122
	 */
123
	public function setPositive(){
124
		return $this->addToProperty("class", "positive");
125
	}
126
127
	/**
128
	 * hint towards a negative consequence
129
	 * @return \Ajax\semantic\html\elements\HtmlButton
130
	 */
131
	public function setNegative(){
132
		return $this->addToProperty("class", "negative");
133
	}
134
135
	/**
136
	 * formatted to toggle on/off
137
	 * @return \Ajax\semantic\html\elements\HtmlButton
138
	 */
139
	public function setToggle(){
140
		return $this->addToProperty("class", "toggle");
141
	}
142
143
	/**
144
	 * @return \Ajax\semantic\html\elements\HtmlButton
145
	 */
146
	public function setCircular(){
147
		return $this->addToProperty("class", "circular");
148
	}
149
150
	/**
151
	 *  button is less pronounced
152
	 * @return \Ajax\semantic\html\elements\HtmlButton
153
	 */
154
	public function setBasic(){
155
		return $this->addToProperty("class", "basic");
156
	}
157
}