Skip to content

Commit 0b95fc0

Browse files
committed
Simplify shared cell code
1 parent cd353b4 commit 0b95fc0

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

PFBC/Element.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ abstract class Element extends Base {
77
protected $label;
88
protected $shortDesc;
99
protected $longDesc;
10+
protected $shared = false;
1011
protected $validation = array();
1112

1213
public function __construct($label, $name, array $properties = null) {
@@ -49,6 +50,10 @@ public function getLongDesc() {
4950
return $this->longDesc;
5051
}
5152

53+
public function getShared() {
54+
return $this->shared;
55+
}
56+
5257
/*This method provides a shortcut for checking if an element is required.*/
5358
public function isRequired() {
5459
if(!empty($this->validation)) {

PFBC/View/SideBySide.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ class View_SideBySide extends FormView {
44
private $sharedCount = 0;
55

66
public function renderElement ($element) {
7+
$colSize = 'col-xs-12 col-md-8';
8+
79
if ($element instanceof Element_Hidden || $element instanceof Element_HTML || $element instanceof Element_Button) {
810
$element->render();
911
return;
@@ -17,21 +19,19 @@ public function renderElement ($element) {
1719
$element->setLabel("");
1820
}
1921

20-
if (!$element->getAttribute("shared") || $this->sharedCount == 0)
22+
if ($this->sharedCount == 0)
2123
echo '<div class="form-group elem-'.$element->getAttribute("id").'"> ', $this->renderLabel($element);
2224

23-
$colSize = 'col-xs-12 col-md-8';
24-
if ($element->getAttribute ("shared")) {
25-
$sharedSize = $element->getAttribute("shared");
26-
$this->sharedCount += $sharedSize[strlen($sharedSize) - 1];
27-
$colSize = $element->getAttribute ("shared");
25+
if ($element->getShared ()) {
26+
$colSize = $element->getShared ();
27+
$this->sharedCount += $colSize[strlen ($colSize) - 1];
2828
}
2929

3030
echo " <div class='$colSize'> ";
3131
echo $element->render(), $this->renderDescriptions($element);
3232
echo " </div> ";
3333

34-
if (!$element->getAttribute("shared") || $this->sharedCount == 8) {
34+
if ($this->sharedCount == 0 || $this->sharedCount == 8) {
3535
$this->sharedCount = 0;
3636
echo " </div> ";
3737
}

PFBC/View/SideBySide4.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ class View_SideBySide4 extends FormView {
33
private $sharedCount = 0;
44

55
public function renderElement ($element) {
6+
$colSize = 'col-xs-12 col-md-8';
67
$element->bootstrapVersion = 4;
8+
79
if ($element instanceof Element_Hidden || $element instanceof Element_HTML || $element instanceof Element_Button) {
810
$element->render();
911
return;
@@ -17,21 +19,19 @@ public function renderElement ($element) {
1719
$element->setLabel("");
1820
}
1921

20-
if (!$element->getAttribute("shared") || $this->sharedCount == 0)
22+
if ($this->sharedCount == 0)
2123
echo '<div class="row form-group elem-'.$element->getAttribute("id").'"> ', $this->renderLabel($element);
2224

23-
$colSize = 'col-xs-12 col-md-8';
24-
if ($element->getAttribute ("shared")) {
25-
$sharedSize = $element->getAttribute("shared");
26-
$this->sharedCount += $sharedSize[strlen($sharedSize) - 1];
27-
$colSize = $element->getAttribute ("shared");
25+
if ($element->getShared ()) {
26+
$colSize = $element->getShared ();
27+
$this->sharedCount += $colSize[strlen ($colSize) - 1];
2828
}
2929

3030
echo " <div class='$colSize'> ";
3131
echo $element->render(), $this->renderDescriptions($element);
3232
echo " </div> ";
3333

34-
if (!$element->getAttribute("shared") || $this->sharedCount == 8) {
34+
if ($this->sharedCount == 0 || $this->sharedCount == 8) {
3535
$this->sharedCount = 0;
3636
echo " </div> ";
3737
}

PFBC/View/Vertical.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
class View_Vertical extends FormView {
33
private $sharedCount = 0;
4+
45
public function renderElement ($element) {
56
if ($element instanceof Element_Hidden || $element instanceof Element_HTML || $element instanceof Element_Button) {
67
$element->render();
@@ -9,24 +10,23 @@ public function renderElement ($element) {
910
if (!$element instanceof Element_Radio && !$element instanceof Element_Checkbox && !$element instanceof Element_File)
1011
$element->appendAttribute("class", "form-control");
1112

12-
if (!$element->getAttribute("shared") || $this->sharedCount == 0) {
13-
$rowClass = $element->getAttribute ("shared") ? 'row' : '';
14-
echo '<div class="'.$rowClass.' form-group elem-'.$element->getAttribute("id").'"> ', $this->renderLabel($element);
13+
if ($this->sharedCount == 0) {
14+
$rowClass = $element->getShared() ? 'row' : '';
15+
echo '<div class="'.$rowClass.' form-group elem-'.$element->getAttribute ("id").'"> ', $this->renderLabel($element);
1516
}
1617

17-
if ($element->getAttribute ("shared")) {
18-
$sharedSize = $element->getAttribute("shared");
19-
$this->sharedCount += $sharedSize[strlen($sharedSize) - 1];
20-
$colSize = $element->getAttribute ("shared");
18+
if ($element->getShared()) {
19+
$colSize = $element->getShared();
20+
$this->sharedCount += $colSize[strlen ($colSize) - 1];
2121
echo " <div class='$colSize'> ";
2222
}
2323

2424
$element->setAttribute('placeholder', $element->getLabel());
2525
echo $element->render(), $this->renderDescriptions($element);
26-
if ($element->getAttribute ("shared"))
26+
if ($element->getShared())
2727
echo " </div> ";
2828

29-
if (!$element->getAttribute("shared") || $this->sharedCount == 12) {
29+
if ($this->sharedCount == 0 || $this->sharedCount == 12) {
3030
$this->sharedCount = 0;
3131
echo " </div> ";
3232
}

0 commit comments

Comments
 (0)