Completed
Push — master ( 5f2e51...f2779d )
by Jean-Christophe
03:46
created

Widget::addItemInToolbar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 4
nc 1
nop 2
1
<?php
2
3
namespace Ajax\common;
4
5
use Ajax\common\html\HtmlDoubleElement;
6
use Ajax\semantic\html\elements\HtmlButton;
7
use Ajax\semantic\widgets\datatable\PositionInTable;
8
use Ajax\semantic\html\collections\menus\HtmlMenu;
9
10
abstract class Widget extends HtmlDoubleElement {
11
12
	/**
13
	 * @var string classname
14
	 */
15
	protected $_model;
16
	protected $_modelInstance;
17
	/**
18
	 * @var InstanceViewer
19
	 */
20
	protected $_instanceViewer;
21
	/**
22
	 * @var boolean
23
	 */
24
	protected $_toolbar;
25
	/**
26
	 * @var PositionInTable
27
	 */
28
	protected $_toolbarPosition;
29
30
31
	public function __construct($identifier,$model,$modelInstance=NULL) {
32
		parent::__construct($identifier);
33
		$this->_template="%wrapContentBefore%%content%%wrapContentAfter%";
34
		$this->setModel($model);
35
		if(isset($modelInstance));
36
			$this->show($modelInstance);
37
	}
38
39
	public function show($modelInstance){
40
		$this->_modelInstance=$modelInstance;
41
	}
42
43
	public function getModel() {
44
		return $this->_model;
45
	}
46
47
	public function setModel($_model) {
48
		$this->_model=$_model;
49
		return $this;
50
	}
51
52
	public function getInstanceViewer() {
53
		return $this->_instanceViewer;
54
	}
55
56
	public function setInstanceViewer($_instanceViewer) {
57
		$this->_instanceViewer=$_instanceViewer;
58
		return $this;
59
	}
60
61
	public abstract function getHtmlComponent();
0 ignored issues
show
Coding Style introduced by
The abstract declaration must precede the visibility declaration
Loading history...
62
63
	public function setColor($color){
64
		return $this->getHtmlComponent()->setColor($color);
65
	}
66
67
	/**
68
	 * @return \Ajax\semantic\html\collections\menus\HtmlMenu
69
	 */
70
	public function getToolbar(){
71
		if(isset($this->_toolbar)===false){
72
			$this->_toolbar=new HtmlMenu("toolbar-".$this->identifier);
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Ajax\semantic\html\...-' . $this->identifier) of type object<Ajax\semantic\htm...ections\menus\HtmlMenu> is incompatible with the declared type boolean of property $_toolbar.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
73
			$this->_toolbar->setSecondary();
74
		}
75
		return $this->_toolbar;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->_toolbar; of type Ajax\semantic\html\colle...\menus\HtmlMenu|boolean adds the type boolean to the return on line 75 which is incompatible with the return type documented by Ajax\common\Widget::getToolbar of type Ajax\semantic\html\collections\menus\HtmlMenu.
Loading history...
76
	}
77
78
	/**
79
	 * Adds a new element in toolbar
80
	 * @param mixed $element
81
	 * @return \Ajax\common\html\HtmlDoubleElement
82
	 */
83
	public function addInToolbar($element){
84
		$tb=$this->getToolbar();
85
		return $tb->addItem($element);
86
	}
87
88
	public function addItemInToolbar($caption,$icon=NULL){
89
		$result=$this->addInToolbar($caption);
90
		$result->addIcon($icon);
91
		return $result;
92
	}
93
94
	public function addButtonInToolbar($caption){
95
		$bt=new HtmlButton("",$caption);
96
		return $this->addInToolbar($bt);
97
	}
98
99
	public function addLabelledIconButtonInToolbar($caption,$icon,$before=true,$labeled=false){
100
		$bt=new HtmlButton("",$caption);
101
		$bt->addIcon($icon,$before,$labeled);
102
		return $this->addInToolbar($bt);
103
	}
104
}