Completed
Push — master ( da7bd7...a4feba )
by Jean-Christophe
03:22
created

TableTrait   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 0
dl 0
loc 79
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
getTable() 0 1 ?
addEvent() 0 1 ?
getOn() 0 1 ?
A addToPropertyTable() 0 3 1
A setCelled() 0 3 1
A setBasic() 0 6 2
A setCompact() 0 6 2
A setCollapsing() 0 3 1
A setDefinition() 0 3 1
A setStructured() 0 3 1
A setSortable() 0 7 3
A setSingleLine() 0 3 1
A setFixed() 0 3 1
A setSelectable() 0 3 1
A setStriped() 0 3 1
A onRowClick() 0 3 1
A onRow() 0 3 1
A getOnRow() 0 4 1
1
<?php
2
namespace Ajax\semantic\html\collections\table\traits;
3
4
trait TableTrait{
5
	/**
6
	 * @return HtmlTable
7
	 */
8
	abstract protected function getTable();
9
	abstract public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false);
10
	abstract public function getOn($event, $url, $responseElement="", $parameters=array());
11
12
	protected function addToPropertyTable($property,$value){
13
		return $this->getTable()->addToProperty($property, $value);
14
	}
15
16
	public function setCelled() {
17
		return $this->addToPropertyTable("class", "celled");
18
	}
19
20
	public function setBasic($very=false) {
21
		$table=$this->getTable();
22
		if ($very)
23
			$table->addToPropertyCtrl("class", "very", array ("very" ));
24
		return $table->addToPropertyCtrl("class", "basic", array ("basic" ));
25
	}
26
27
	public function setCompact($very=false) {
28
		$table=$this->getTable();
29
		if ($very)
30
			$table->addToPropertyCtrl("class", "very", array ("very" ));
31
		return $table->addToPropertyCtrl("class", "compact", array ("compact" ));
32
	}
33
34
	public function setCollapsing() {
35
		return $this->addToPropertyTable("class", "collapsing");
36
	}
37
38
	public function setDefinition() {
39
		return $this->addToPropertyTable("class", "definition");
40
	}
41
42
	public function setStructured() {
43
		return $this->addToPropertyTable("class", "structured");
44
	}
45
46
	public function setSortable($colIndex=NULL) {
47
		$table=$this->getTable();
48
		if (isset($colIndex) && $table->hasPart("thead")) {
49
			$table->getHeader()->sort($colIndex);
50
		}
51
		return $table->addToProperty("class", "sortable");
52
	}
53
54
	public function setSingleLine() {
55
		return $this->addToPropertyTable("class", "single line");
56
	}
57
58
	public function setFixed() {
59
		return $this->addToPropertyTable("class", "fixed");
60
	}
61
62
	public function setSelectable() {
63
		return $this->addToPropertyTable("class", "selectable");
64
	}
65
66
	public function setStriped() {
67
		return $this->addToPropertyTable("class", "striped");
68
	}
69
70
	public function onRowClick($jsCode, $stopPropagation=false, $preventDefault=false){
71
		$this->onRowClick($jsCode,$stopPropagation,$preventDefault);
72
	}
73
74
	public function onRow($event,$jsCode, $stopPropagation=false, $preventDefault=false){
75
		$this->getTable()->addEvent($event,"{{tr}}".$jsCode,$stopPropagation,$preventDefault);
76
	}
77
78
	public function getOnRow($event, $url, $responseElement="", $parameters=array()){
79
		$parameters=\array_merge($parameters,["eventItemSelector"=>"tbody tr","stopPropagation"=>false,"preventDefault"=>false]);
80
		return $this->getTable()->getOn($event, $url,$responseElement,$parameters);
81
	}
82
}