00001 <?php
00008 class XFormsControlGroup extends XFormsGroup {
00009
00010 protected $displayMode = 'vertical';
00011
00020 public function setDisplayMode($d) {
00021 $this->displayMode = $d;
00022 }
00023
00031 public function getDisplayMode() {
00032 return $this->displayMode;
00033 }
00034
00042 public function generateTK() {
00043 switch($this->getDisplayMode()) {
00044 case 'grid':
00045
00046 $b = new TKVBox();
00047 $table = new TKTable();
00048 $table->class = array('XFormsGroupTable');
00049 $b->add($table);
00050 $b->class = array('XFormsQuestion', 'XFormsGroup');
00051
00052 $cs = $this->getControls();
00053 $isFirst = true;
00054 $questionCount = 0;
00055 $questionRefs = array();
00056 foreach ($cs as $c) {
00057 $questionRefs []= $c->getRef();
00058 $c->setAppearance('grid');
00059 $c->generateTK($table, $isFirst, ($questionCount %2 == 0));
00060
00061 # if it is required, add a star in the extra column
00062 if ($this->isRequired()) {
00063 $req = new TKLabel('*');
00064 } else {
00065 $req = new TKLabel(' ');
00066 }
00067 $req->class = array('formReq');
00068 $table->add($req);
00069
00070 # add the row that contains the question
00071 $table->addRow();
00072
00073 # if there is an error on the question,
00074 # add an extra row for the error.
00075 $xfe = $c->getXFormsError();
00076 if ($xfe != '') {
00077
00078 # compute the number of columns you need to span
00079 $span = count($c->getItems()) + 2;
00080
00081 # make the error label
00082 $errLabel = new TKLabel('↑ ' . $xfe);
00083 $errLabel->class = array('errorMsg');
00084
00085 # add the label
00086 $table->add($errLabel, array('colspan' => $span));
00087
00088 # add the error row
00089 $table->addRow();
00090 }
00091 $questionCount++;
00092 $isFirst = false;
00093 }
00094 $b->add($this->buildSelectHelper($questionRefs));
00095 return $b;
00096 break;
00097
00098 case 'vertical':
00099 default:
00100
00101 # vertical box to hold the question group
00102 $b = new TKNullBox();
00103
00104 if ($this->isRequired()) {
00105 $req = new TKLabel('*');
00106 $req->class = array('formReq');
00107 $b->add($req);
00108 }
00109
00110 # label of the question title
00111 $label = new TKLabel($this->getLabel());
00112 $label->class = array('questionTitle');
00113 $b->add($label);
00114
00115 # loop through and render out all the form controls in this group
00116 $cs = $this->getControls();
00117 foreach ($cs as $c) {
00118
00119 # get the description; add it to the page if there is any content
00120 $tkD = $c->generateDescriptionTK();
00121 if ($tkD != null) $b->add($tkD);
00122
00123 # generate the TK code for the control
00124 if ($c != null) {
00125
00126 $b->add($c->generateTK());
00127 }
00128
00129 # add the XForms error for this element
00130 $xfe = $c->getXFormsError();
00131 if ($xfe != '') {
00132 $errLabel = new TKLabel('↑ ' . $xfe);
00133 $errLabel->class = array('errorMsg');
00134 $b->add($errLabel);
00135 }
00136 $b->add($this->buildSelectHelper($c));
00137 }
00138 $b->class = array('XFormsQuestion', 'XFormsGroup');
00139 return $b;
00140 break;
00141 }
00142 }
00143
00149 private function buildSelectHelper($c) {
00150
00151 $selHelpBox = new TKNullBox();
00152 $selHelpBox->class = array('selectHelper');
00153
00154
00155
00156 if (($c instanceOf XFormsSelectControl)
00157 && $c->getAppearance() == 'full') {
00158 $selHelpBox->addLabel('<a href="javascript:selectItems(true,\''
00159 . $c->getRef() . '\');">Select All</a>');
00160 }
00161 // If this control is required and it's a select1 (radio button), return now before
00162 // we add the "select none" option
00163 if ($this->isRequired() && ($c instanceOf XFormsSelect1Control)) {
00164 return $selHelpBox;
00165 }
00166 // Add "Select None"
00167 // If this is either type of select with an appearance 'full', add "select none"
00168 if ((($c instanceOf XFormsSelectControl) ||
00169 ($c instanceOf XFormsSelect1Control))
00170 && $c->getAppearance() == 'full') {
00171 // If this is a select control, add the spacer that comes after "select all"
00172 if ($c instanceOf XFormsSelectControl)
00173 $selHelpBox->addLabel(' - ');
00174 $selHelpBox->addLabel('<a href="javascript:selectItems(false,\''
00175 . $c->getRef() . '\');">Select None</a>');
00176 }
00177 // FOR GRID LAYOUT
00178 // If an array is passed in, it means we want to display a de-selector for multiple refs
00179 // separated by commas (i.e., it's a grid display)
00180 if (is_array($c)) {
00181 $selHelpBox->addLabel('<a href="javascript:selectItems(false,\''
00182 . implode(',', $c) . '\');">Select None</a>');
00183 }
00184 return $selHelpBox;
00185 }
00186 }
00187
00188 ?>