00001 <?php
00002
00007 class XFormsSelectControl extends XFormsControl
00008 {
00016 public function generateDescriptionTK() {
00017 if ($this->getDescription() != '') {
00018 $descrip = new TKLabel($this->getDescription());
00019 $descrip->class = array('questionDescrip', 'questionDescripTop');
00020 return $descrip;
00021 } else {
00022 return null;
00023 }
00024 }
00025
00026
00036 public function generateTK($table = null, $isFirst = false) {
00037
00038 $id = $this->getControlId();
00039 $items = $this->getItems();
00040 $values = $this->getValues();
00041
00042 switch($this->getAppearance()) {
00043 case 'grid':
00044
00045 # CREATE COLUMN HEADERS
00046 # If we are displaying in grid layout and this is the first question,
00047 # then create the column headers and add them as a row
00048 if ($isFirst){
00049 $table->addText('');
00050 $itemCounter = 0;
00051 foreach ($items as $item) {
00052 $label = $item->getViewLabel();
00053 $table->addText($label, array('class' => array('gridHeaderCell')));
00054 }
00055 $table->addRow();
00056 }
00057
00058 $isOdd = (count($table->row_ids) - 1) % 2 == 0;
00059 # CREATE COLUMN DATA
00060 # for every control, add the normal table row of question + answers
00061 $table->addText($this->getLabel(), $isOdd ? array('class' => array('oddQuestionTd')) : array());
00062 $itemCounter = 0;
00063 foreach ($items as $item) {
00064
00065 $value = $item->getViewValue();
00066 $checked = in_array($value, $values);
00067 $cb = new TKCheckBox($id . '_' . $itemCounter, $value, $checked);
00068 $cb->class = array($id);
00069 $table->add($cb, array('class' => array('checkboxContainer', $isOdd ? 'oddQuestionTd' : '')));
00070 $itemCounter++;
00071 }
00072 return $table;
00073
00074 case 'minimal':
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 return (new TKLabel('Compact and minimal appearance not yet supported for select.'));
00091 break;
00092
00093 # Full Appearance
00094 # Create a set of radio buttons
00095 case 'compact':
00096 case 'full':
00097 default:
00098
00099 # make a vertical container to store the buttons
00100 if (count($items) > SConfig::getOption('xforms.maxBeforeWrap')) {
00101 $itemsContainer = new TKTable();
00102 $itemsContainer->class = array('questionOptionTable');
00103 $wrapping = true;
00104 } else {
00105 $itemsContainer = new TKVBox();
00106 $wrapping = false;
00107 }
00108
00109 $itemCounter = 0;
00110 foreach ($items as $item) {
00111
00112 # get the value, label, and checked status
00113 $value = $item->getViewValue();
00114 $label = $item->getViewLabel();
00115 $checked = in_array($value, $values);
00116
00117 # create a TK container for the row, add items
00118 $itemContainer = new TKNullBox();
00119 $questionOptionCB = new TKCheckBox($id . '_' . $itemCounter,
00120 $value, $checked);
00121 $questionOptionCB->class = array('questionOptionCB', $id);
00122 $itemContainer->add($questionOptionCB);
00123 $questionOptionText = new TKLabel("<label for='".$questionOptionCB->getId()."'>$label</label>");
00124 $questionOptionText->class = array('questionOptionText');
00125 $itemContainer->add($questionOptionText);
00126 $evenOdd = ($itemCounter % 2 == 0) ? 'evenQuestionTd' : 'oddQuestionTd';
00127 $itemContainer->class = array('questionOption', $evenOdd);
00128
00129 $itemsContainer->add($itemContainer);
00130
00131 $itemCounter++;
00132
00133 # if we are wrapping and we get to the # of columns,
00134 # we should add a new row.
00135 if ($wrapping
00136 && ($itemCounter % SConfig::getOption('xforms.numOptionColumns') == 0)) {
00137 $itemsContainer->addRow();
00138 }
00139
00140 }
00141
00142 # return the box containing all radio buttons
00143 return $itemsContainer;
00144 }
00145
00146 }
00147
00148 }
00149
00150 ?>