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