Completed
Push — master ( e9bdcb...b0560a )
by Jean-Christophe
04:52
created

HtmlTD::setSelectable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\content\table;
4
5
use Ajax\semantic\html\base\HtmlSemDoubleElement;
6
use Ajax\semantic\html\base\traits\TextAlignmentTrait;
7
use Ajax\semantic\html\base\constants\Variation;
8
use Ajax\semantic\html\base\constants\State;
9
use Ajax\semantic\html\base\traits\TableElementTrait;
10
use Ajax\semantic\html\elements\html5\HtmlLink;
11
12
class HtmlTD extends HtmlSemDoubleElement {
13
	use TextAlignmentTrait,TableElementTrait;
14
	private $_container;
15
	private $_row;
16
	private $_col;
17
18
	/**
19
	 *
20
	 * @param string $identifier
21
	 * @param mixed $content
22
	 * @param string $tagName
23
	 */
24
	public function __construct($identifier, $content=NULL, $tagName="td") {
25
		parent::__construct($identifier, $tagName, "", $content);
26
		$this->_variations=[ Variation::COLLAPSING ];
27
		$this->_states=[ State::ACTIVE,State::POSITIVE,State::NEGATIVE,State::WARNING,State::ERROR,State::DISABLED ];
28
	}
29
30
	public function setContainer($container, $row, $col) {
31
		$this->_container=$container;
32
		$this->_row=$row;
33
		$this->_col=$col;
34
	}
35
36
	public function setValue($value) {
37
		$this->content=$value;
38
		return $this;
39
	}
40
41
	public function setRowspan($rowspan) {
42
		$to=min($this->_container->count(), $this->_row + $rowspan - 1);
43 View Code Duplication
		for($i=$to; $i > $this->_row; $i--) {
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...
44
			$this->_container->delete($i, $this->_col);
45
		}
46
		$this->setProperty("rowspan", $rowspan);
47
		return $this->_container;
48
	}
49
50
	public function mergeRow() {
51
		return $this->setRowspan($this->_container->count());
52
	}
53
54
	public function mergeCol() {
55
		return $this->setColspan($this->_container->getRow($this->_row)->count());
56
	}
57
58
	public function setColspan($colspan) {
59
		$to=min($this->_container->getRow($this->_row)->count(), $this->_col + $colspan - 1);
60 View Code Duplication
		for($i=$to; $i > $this->_col; $i--) {
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...
61
			$this->_container->delete($this->_row, $this->_col + 1);
62
		}
63
		$this->setProperty("colspan", $colspan);
64
		return $this->_container;
65
	}
66
67
	public function getColspan() {
68
		$colspan=1;
69
		if (\array_key_exists("colspan", $this->properties))
70
			$colspan=$this->getProperty("colspan");
71
		return $colspan;
72
	}
73
74
	public function getRowspan() {
75
		$rowspan=1;
76
		if (\array_key_exists("rowspan", $this->properties))
77
			$rowspan=$this->getProperty("rowspan");
78
		return $rowspan;
79
	}
80
81
	public function conditionalCellFormat($callback, $format) {
82
		if ($callback($this)) {
83
			$this->addToProperty("class", $format);
84
		}
85
		return $this;
86
	}
87
88
	public function apply($callback) {
89
		$callback($this);
90
		return $this;
91
	}
92
93
	public function setSelectable($href="#") {
94
		if (\is_string($this->content)) {
95
			$this->content=new HtmlLink("", $href, $this->content);
96
		}
97
		return $this->addToProperty("class", "selectable");
98
	}
99
}