Completed
Push — master ( 2aad8b...141d55 )
by Jean-Christophe
03:21
created

HtmlShape::asCube()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Ajax\semantic\html\modules;
3
4
use Ajax\semantic\html\base\HtmlSemCollection;
5
use Ajax\semantic\html\content\HtmlShapeItem;
6
use Ajax\JsUtils;
7
use Ajax\semantic\html\base\HtmlSemDoubleElement;
8
9
10
class HtmlShape extends HtmlSemCollection{
11
12
	protected $_params=array();
13
	protected $_autoActive=true;
14
15
	public function __construct( $identifier, $sides){
16
		parent::__construct( $identifier, "div", "ui shape");
17
		$this->_template="<%tagName% id='%identifier%' %properties%><div class='sides'>%wrapContentBefore%%content%%wrapContentAfter%</div></%tagName%>";
18
		$this->addItems($sides);
19
	}
20
21
	/**
22
	 * {@inheritDoc}
23
	 * @see \Ajax\common\html\HtmlCollection::createItem()
24
	 */
25
	protected function createItem($value){
26
		if(\is_object($value)===false){
27
			$value=new HtmlSemDoubleElement("","div","content",$value);
28
		}
29
		return new HtmlShapeItem("side-".$this->identifier."-".$this->count(), $value);
30
	}
31
32
	/**
33
	 * {@inheritDoc}
34
	 * @see \Ajax\common\html\HtmlCollection::createCondition()
35
	 */
36
	protected function createCondition($value){
37
		return ($value instanceof HtmlShapeItem)===false;
38
	}
39
40
	/**
41
	 * @param int $index
42
	 * @return \Ajax\semantic\html\content\HtmlShapeItem
43
	 */
44
	public function getSide($index){
45
		return $this->getItem($index);
46
	}
47
48
	/**
49
	 * @param int $index
50
	 * @return mixed|NULL
51
	 */
52
	public function getSideContent($index){
53
		$item= $this->getItem($index);
54
		if(isset($item))
55
			return $item->getContent();
56
		return null;
57
	}
58
59
	public function jsDo($action){
60
		return "$('#".$this->identifier."').shape('".$action."');";
61
	}
62
63
	public function jsFlipleft(){
64
		return $this->jsDo("flip left");
65
	}
66
67
	public function setActiveSide($index){
68
		$side=$this->getSide($index);
69
		if(isset($side)){
70
			$side->setActive(true);
71
		}
72
		return $this;
73
	}
74
75
	public function asCube(){
76
		return $this->addToPropertyCtrl("class", "cube", ["cube"]);
77
	}
78
79
	public function asText(){
80
		return $this->addToPropertyCtrl("class", "text", ["text"]);
81
	}
82
83
	/*
84
	 * (non-PHPdoc)
85
	 * @see BaseHtml::run()
86
	 */
87
	public function run(JsUtils $js) {
88 View Code Duplication
		if (isset($this->_bsComponent) === false)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
89
			$this->_bsComponent=$js->semantic()->shape("#" . $this->identifier, $this->_params);
90
		$this->addEventsOnRun($js);
91
		return $this->_bsComponent;
92
	}
93
94
	public function compile(JsUtils $js=NULL, &$view=NULL) {
95
		if($this->_autoActive)
96
			$this->setActiveSide(0);
97
		return parent::compile($js,$view);
98
	}
99
}