Completed
Push — master ( c8eebb...4924e4 )
by Jean-Christophe
02:55
created

HtmlTab::forwardPanel()   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 6
1
<?php
2
namespace Ajax\semantic\html\modules;
3
4
use Ajax\semantic\html\base\HtmlSemCollection;
5
use Ajax\semantic\html\elements\HtmlSegment;
6
use Ajax\semantic\html\collections\menus\HtmlMenu;
7
use Ajax\semantic\html\base\constants\Side;
8
use Ajax\JsUtils;
9
10
class HtmlTab extends HtmlSemCollection{
11
	protected $params=array("debug"=>true);
12
13
	public function __construct( $identifier, $tabs=array()){
14
		parent::__construct( $identifier, "div", "");
15
		$menu=new HtmlMenu("menu".$this->identifier);
16
		$menu->asTab(false)->setAttachment(NULL,Side::TOP);
0 ignored issues
show
Documentation introduced by
NULL is of type null, but the function expects a object<Ajax\semantic\htm...e\HtmlSemDoubleElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
		$this->content["menu"]=$menu;
18
		$this->addItems($tabs);
19
	}
20
21
	protected function createItem($value){
22
		$count=$this->count();
23
		$title=$value;
24
		$content=NULL;
25
		if(\is_array($value)){
26
			$title=@$value[0];$content=@$value[1];
27
		}
28
		$menuItem=$this->content["menu"]->addItem($title);
29
		$menuItem->addToProperty("data-tab", $menuItem->getIdentifier());
30
		$menuItem->removeProperty("href");
31
		$segment=new HtmlSegment("item-".$this->identifier."-".$count, $content);
32
		$segment->setAttachment(NULL,Side::BOTTOM)->addToProperty("class", "tab")->addToProperty("data-tab",$menuItem->getIdentifier());
0 ignored issues
show
Documentation introduced by
NULL is of type null, but the function expects a object<Ajax\semantic\htm...e\HtmlSemDoubleElement>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
		return $segment;
34
	}
35
36
	public function activate($index){
37
		$this->content["menu"]->getItem($index)->setActive(true);
38
		$this->content[$index]->setActive(true);
39
		return $this;
40
	}
41
42
	public function addPanel($title,$content){
43
		return $this->addItem([$title,$content]);
0 ignored issues
show
Documentation introduced by
array($title, $content) is of type array<integer,?,{"0":"?","1":"?"}>, but the function expects a object<Ajax\common\html\HtmlDoubleElement>|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
44
	}
45
46
	/**
47
	 * render the content of $controller::$action and set the response to a new panel
48
	 * @param JsUtils $js
49
	 * @param string $title The panel title
50
	 * @param Controller $initialController
51
	 * @param string $controller a Phalcon controller
52
	 * @param string $action a Phalcon action
53
	 * @param array $params
54
	 */
55
	public function forwardPanel(JsUtils $js,$title,$initialController,$controller,$action,$params=array()){
56
		return $this->addPanel($title, $js->forward($initialController, $controller, $action,$params));
57
	}
58
59
	/**
60
	 * render the content of an existing view : $controller/$action and set the response to a new panel
61
	 * @param JsUtils $js
62
	 * @param string $title The panel title
63
	 * @param Controller $initialController
64
	 * @param string $viewName
65
	 * @param $params The parameters to pass to the view
66
	 */
67
	public function renderViewPanel(JsUtils $js,$title,$initialController, $viewName, $params=array()) {
68
		return $this->addPanel($title, $js->renderContent($initialController, $viewName,$params));
69
	}
70
71
	/*
72
	 * (non-PHPdoc)
73
	 * @see BaseHtml::run()
74
	 */
75
	public function run(JsUtils $js) {
76 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...
77
			$this->_bsComponent=$js->semantic()->tab("#".$this->identifier." .item",$this->params);
78
			$this->addEventsOnRun($js);
79
			return $this->_bsComponent;
80
	}
81
	public function compile(JsUtils $js=NULL, &$view=NULL) {
82
		if($this->content["menu"]->count()>0)
83
			$this->activate(0);
84
		return parent::compile($js,$view);
85
	}
86
}