00001 <?php
00002
00009 class XFormsControl extends SObject
00010 {
00011
00012 protected $ref; # what node it binds to
00013 protected $appearance = 'full'; # how it displays
00014 protected $description; # descrip to right of ?
00015 protected $items = array(); # question options
00016 protected $values = array();# set values
00017 protected $parent; # parent XFormsRenderModule
00018 protected $group; # group containing this object
00019 protected $label; # label specific to one control
00020
00021
00022
00023 protected $required;
00024 protected $type;
00025
00026
00027
00028
00036 public function getRef() {
00037 return $this->ref;
00038 }
00039
00047 public function getAppearance() {
00048 return $this->appearance;
00049 }
00050
00058 public function getDescription() {
00059 return $this->description;
00060 }
00061
00069 public function getParent() {
00070 return $this->parent;
00071 }
00072
00080 public function getGroup() {
00081 return $this->group;
00082 }
00083
00091 public function getValues() {
00092 return $this->values;
00093 }
00094
00102 public function getFirstValue() {
00103 if (count($this->values) < 1) {
00104 return null;
00105 } else {
00106 return XFormsFunctions::contentToScreen($this->values[0]);
00107 }
00108 }
00109
00117 public function getItems() {
00118 return $this->items;
00119 }
00120
00128 public function getRequired() {
00129 return $this->required;
00130 }
00131
00139 public function isRequired() {
00140 return $this->getRequired();
00141 }
00142
00150 public function getLabel() {
00151 return $this->label;
00152 }
00153
00154
00155
00156
00165 public function setRef($r) {
00166 $this->ref = $r;
00167 }
00168
00177 public function setAppearance($a) {
00178 $this->appearance = $a;
00179 }
00180
00189 public function setDescription($d) {
00190 $this->description = $d;
00191 }
00192
00201 public function setParent($p) {
00202 $this->parent = $p;
00203 }
00204
00213 public function setGroup($g) {
00214 $this->group = $g;
00215 }
00216
00225 public function setValues($v) {
00226 $this->values = $v;
00227 }
00228
00237 public function addValue($v) {
00238 if (!in_array($v, $this->values)){
00239 array_push($this->values, $v);
00240 }
00241 }
00242
00243
00252 public function setItems($i) {
00253 $this->items = $i;
00254 }
00255
00264 public function addItem($i) {
00265 array_push($this->items, $i);
00266 }
00267
00276 public function setRequired($r) {
00277 $this->required = $r;
00278 }
00279
00288 public function setLabel($l) {
00289 $this->label = $l;
00290 }
00291
00292
00293
00294
00302 public function searchForInputValues() {
00303 if ($this->getRef() == '') return;
00304
00305 if (count($this->getItems()) == 0) {
00306 # SINGLE INPUT
00307 # simply look for the first item in the list
00308 $values = $this->getParent()->getValueForInstanceNode(
00309 $this->getRef(), $this->getParent()->getXFormCache(), 0);
00310 $this->setValues($values);
00311 } else {
00312 # MULTIPLE INPUT
00313 # loop through all of our items, looking for matches in the input
00314 $items = $this->getItems();
00315 $counter = 0;
00316 foreach ($items as $item) {
00317 # attempt to get a submitted value for this particular option (i.e., option_2)
00318 $value = $this->getParent()->getValueForInstanceNode(
00319 $this->getRef(), $this->getParent()->getXFormCache(), $counter);
00320 # if it exists, add it to our values
00321 foreach($value as $v) {
00322 $this->addValue($v);
00323 }
00324 $counter++;
00325 }
00326 }
00327
00328 }
00329
00338 public function addItemsFromXMLTree($xml) {
00339 foreach ($xml as $tag => $value) {
00340 if ($tag == 'item') {
00341 $i = new XFormsControlItem();
00342 if (isset($value->label))
00343 $i->setLabel(XFormsFunctions::XMLToContent((string)$value->label));
00344 if (isset($value->value))
00345 $i->setValue(XFormsFunctions::XMLToContent((string)$value->value));
00346 $this->addItem($i);
00347 }
00348 }
00349 }
00350
00351
00352
00360 public function getControlId() {
00361 return $this->getParent()->getIdPrefix() . $this->getRef();
00362 }
00363
00371 public function getXFormsError() {
00372 $ib = $this->getParent();
00373 return $ib->getValidator()->getErrorCode(
00374 $ib->getParent()->getErrorCode($this->getRef()));
00375 }
00376
00384 public function getItemValues() {
00385 return array_map(create_function('$item', 'return $item->getViewLabel();'), $this->getItems());
00386 }
00387
00388
00389
00390
00398 public function generateDescriptionTK() {
00399 if ($this->getDescription() != '') {
00400 $descrip = new TKLabel($this->getDescription());
00401 $descrip->class = array('questionDescrip', 'questionDescripRight');
00402 return $descrip;
00403 } else {
00404 return null;
00405 }
00406 }
00407
00415 public function generateTK() {
00416 return null;
00417 }
00418
00426 public function render() {
00427 $tk = $this->generateTK();
00428 if ($tk != null) return $tk->render();
00429 }
00430
00431 }
00432
00433
00434 ?>