Completed
Push — master ( d551f2...460f9e )
by Jean-Christophe
03:07
created

FormInstanceViewer::addSeparatorAfter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
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 5
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\widgets\dataform;
4
5
use Ajax\semantic\widgets\base\InstanceViewer;
6
use Ajax\service\JString;
7
use Ajax\semantic\html\collections\form\HtmlFormInput;
8
9
class FormInstanceViewer extends InstanceViewer {
10
	protected $separators;
11
12
	public function __construct($identifier,$instance=NULL, $captions=NULL) {
13
		parent::__construct($identifier,$instance=NULL, $captions=NULL);
14
		$this->separators=[-1];
15
		$this->defaultValueFunction=function($name,$value,$index){
16
			$caption=$this->getCaption($index);
17
			$input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value);
18
			$input->setName($name);
19
			return $input;
20
		};
21
	}
22
23
	protected function _beforeAddProperty($index,&$field){
24
		if(JString::endswith($field, "\n")===true){
25
			$this->addSeparatorAfter($index);
26
		}
27
		if($index>1 && JString::startswith($field, "\n")===true){
28
			$this->addSeparatorAfter($index-1);
29
		}
30
		$field=\str_replace("\n", "", $field);
31
	}
32
33
34
35
	public function addSeparatorAfter($fieldNum){
36
		if(\array_search($fieldNum, $this->separators)===false)
37
			$this->separators[]=$fieldNum;
38
			return $this;
39
	}
40
41
	public function getSeparators() {
42
		return $this->separators;
43
	}
44
45
	public function setSeparators($separators) {
46
		$this->separators=\array_merge([-1], $separators);
47
		return $this;
48
	}
49
50
}