Completed
Push — master ( 667888...aa0ebb )
by Jean-Christophe
03:27
created

DataForm::_setToolbarPosition()   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 2
1
<?php
2
3
namespace Ajax\semantic\widgets\dataform;
4
5
use Ajax\common\Widget;
6
use Ajax\semantic\html\collections\form\HtmlForm;
7
use Ajax\semantic\widgets\datatable\PositionInTable;
8
use Ajax\service\JArray;
9
use Ajax\JsUtils;
10
11
/**
12
 * DataForm widget for editing model objects
13
 * @version 1.0
14
 * @author jc
15
 * @since 2.2
16
 */
17
class DataForm extends Widget {
18
	use FormFieldAsTrait;
19
20 View Code Duplication
	public function __construct($identifier, $modelInstance=NULL) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
21
		parent::__construct($identifier, null,$modelInstance);
22
		$this->_instanceViewer=new FormInstanceViewer();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Ajax\semantic\widge...rm\FormInstanceViewer() of type object<Ajax\semantic\wid...orm\FormInstanceViewer> is incompatible with the declared type object<Ajax\common\InstanceViewer> of property $_instanceViewer.

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...
23
		$this->content=["form"=>new HtmlForm($identifier)];
24
		$this->_toolbarPosition=PositionInTable::BEFORETABLE;
25
	}
26
27 View Code Duplication
	public function compile(JsUtils $js=NULL,&$view=NULL){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
28
		$this->_instanceViewer->setInstance($this->_modelInstance);
29
30
		$form=$this->content["form"];
31
		$this->_generateContent($form);
32
33
		if(isset($this->_toolbar)){
34
			$this->_setToolbarPosition($form);
35
		}
36
		$this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"form",PositionInTable::AFTERTABLE]);
37
		return parent::compile($js,$view);
38
	}
39
40
	/**
41
	 * @param HtmlForm $form
42
	 */
43
	protected function _generateContent($form){
44
		$values= $this->_instanceViewer->getValues();
45
		$count=$this->_instanceViewer->count();
46
		$separators=$this->_instanceViewer->getSeparators();
47
		$separators[]=$count;
48
		for($i=0;$i<\sizeof($separators)-1;$i++){
49
			$fields=\array_slice($values, $separators[$i]+1,$separators[$i+1]-$separators[$i]);
50
			if(\sizeof($fields)===1){
51
				$form->addField($fields[0]);
52
			}else
53
				$form->addFields($fields);
54
		}
55
	}
56
57
	public function addSeparatorAfter($fieldNum){
58
		$this->_instanceViewer->addSeparatorAfter($fieldNum);
59
		return $this;
60
	}
61
62
	public function getSeparators() {
63
		return $this->_instanceViewer->getSeparators();
64
	}
65
66
	public function setSeparators($separators) {
67
		$this->_instanceViewer->setSeparators($separators);
68
		return $this;
69
	}
70
71
	/**
72
	 * {@inheritDoc}
73
	 * @see \Ajax\common\Widget::getHtmlComponent()
74
	 * @return HtmlForm
75
	 */
76
	public function getHtmlComponent() {
77
		return $this->content["form"];
78
	}
79
	/**
80
	 * {@inheritdoc}
81
	 * @see \Ajax\common\Widget::_setToolbarPosition()
82
	 */
83
	protected function _setToolbarPosition($table, $captions=NULL) {
84
		$this->content[$this->_toolbarPosition]=$this->_toolbar;
85
	}
86
87
	public function setValidationParams(array $_validationParams){
88
		return $this->getHtmlComponent()->setValidationParams($_validationParams);
89
	}
90
91
	public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL){
92
		return $this->getHtmlComponent()->addSubmit($identifier, $value,$cssStyle,$url,$responseElement);
93
	}
94
}