phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
FormInstanceViewer.php
Go to the documentation of this file.
1 <?php
2 
4 
8 
10  protected $separators;
11  protected $headers;
12  protected $wrappers;
13 
14  public function __construct($identifier,$instance=NULL, $captions=NULL) {
15  parent::__construct($identifier,$instance, $captions);
16  $this->separators=[-1];
17  $this->headers=[];
18  $this->wrappers=[];
19  $this->defaultValueFunction=function($name,$value,$index){
20  $caption=$this->getCaption($index);
21  $input=new HtmlFormInput($this->widgetIdentifier."-".$name,$caption,"text",$value);
22  $input->setName($name);
23  return $input;
24  };
25  }
26 
27  protected function _beforeAddProperty($index,&$field){
28  if(JString::endswith($field, "\n")===true){
29  $this->addSeparatorAfter($index);
30  }
31  if($index>1 && JString::startswith($field, "\n")===true){
32  $this->addSeparatorAfter($index-1);
33  }
34  $field=\str_replace("\n", "", $field);
35  if(($header=$this->hasHeader($field))!==false){
36  $this->addHeaderDividerBefore($index, $header);
37  }
38  }
39 
40  protected function hasHeader(&$field){
41  $matches=[];$result=false;
42  if(\preg_match('/\{(.*?)\}/s', $field, $matches)===1){
43  $result=$matches[1];
44  $field=\str_replace("{".$result."}","", $field);
45  }
46  return $result;
47  }
48 
49 
50 
51  public function addSeparatorAfter($fieldNum){
52  if(\array_search($fieldNum, $this->separators)===false)
53  $this->separators[]=$fieldNum;
54  return $this;
55  }
56 
57  public function addHeaderDividerBefore($fieldNum,$header){
58  $this->headers[$fieldNum]=$header;
59  if($fieldNum>0)
60  $this->addSeparatorAfter($fieldNum-1);
61  return $this;
62  }
63 
64  public function addWrapper($fieldNum,$contentBefore,$contentAfter=null){
65  $this->wrappers[$fieldNum]=[$contentBefore,$contentAfter];
66  return $this;
67  }
68 
69  public function getSeparators() {
70  return $this->separators;
71  }
72 
73  public function removeSeparator($index){
74  \array_splice($this->separators,$index,1);
75  }
76 
77  public function removeField($index){
78  parent::removeField($index);
79  $pos=\array_search($index, $this->separators);
80  if($pos!==false){
81  $sepCount=\sizeof($this->separators);
82  for($i=$pos+1;$i<$sepCount;$i++){
83  $this->separators[$i]--;
84  }
85  \array_splice($this->separators, $pos, 1);
86  }
87  return $this;
88  }
89 
90  public function setSeparators($separators) {
91  $this->separators=\array_merge([-1], $separators);
92  return $this;
93  }
94 
95  public function getHeaders() {
96  return $this->headers;
97  }
98 
99  public function getWrappers() {
100  return $this->wrappers;
101  }
102 
103  public function setWrappers($wrappers) {
104  $this->wrappers=$wrappers;
105  return $this;
106  }
107 
108 
109 
110 }
static startswith($hay, $needle)
Definition: JString.php:10
static endswith($hay, $needle)
Definition: JString.php:14
addWrapper($fieldNum, $contentBefore, $contentAfter=null)
__construct($identifier, $instance=NULL, $captions=NULL)