<?php
 class FormItemVO implements MotoDomObjectInterface { public $id = 0; public $label = ""; public $required = false; public $x = 0; public $y = 0; public $width = 0; public $height = 0; public $type = ""; public $mailOrder = 0; public $tabOrder = 0; public $defaultValue = ""; public $textToShow = ""; public function __construct(DOMNode $parent = null) { if (!empty($parent)) { $this->loadDomElement($parent); } } public function loadDomElement(DOMNode $parent) { $this->id = (int) $parent->getAttribute('id'); $this->required = (boolean) MotoUtil::toBoolean($parent->getAttribute('required')); $this->type = (string) MotoUtil::getValue($parent->getAttribute('type'), "text"); $this->x = (int) $parent->getAttribute('x'); $this->y = (int) $parent->getAttribute('y'); $this->width = (int) $parent->getAttribute('width'); $this->height = (int) $parent->getAttribute('height'); $this->mailOrder = (int) $parent->getAttribute('mailOrder'); $this->tabOrder = (int) $parent->getAttribute('tabOrder'); $nodeValue = $parent->getElementsByTagName('label')->item(0); if (!is_null($nodeValue)) { $label = (string) $nodeValue->nodeValue; $label = preg_replace('/^([0-9]*:)/i', '', $label); $this->label = $label; } $nodeValue = $parent->getElementsByTagName('defaultValue')->item(0); if (!is_null($nodeValue)) $this->defaultValue = (string) $nodeValue->nodeValue; $nodeValue = $parent->getElementsByTagName('textToShow')->item(0); if (!is_null($nodeValue)) $this->textToShow = (string) $nodeValue->nodeValue; return $this; } public function saveDomElement(DOMNode $parent) { $parent->setAttribute('id', (string) $this->id); if ($this->required == true) $parent->setAttribute('required', (string) MotoUtil::boolToString($this->required)); $parent->setAttribute('type', (string) $this->type); $parent->setAttribute('x', (string) $this->x); $parent->setAttribute('y', (string) $this->y); $parent->setAttribute('width', (string) $this->width); $parent->setAttribute('height', (string) $this->height); if ($this->mailOrder != 0) $parent->setAttribute('mailOrder', (string) $this->mailOrder); if ($this->tabOrder != 0) $parent->setAttribute('tabOrder', (string) $this->tabOrder); $order = substr("0" . $this->mailOrder, -2); $label = $order . ':' . $this->label; $parent->appendChild(new DOMElement('label')) ->appendChild($parent->ownerDocument->createCDATASection($label)); if ($this->defaultValue != "") { $parent->appendChild(new DOMElement('defaultValue')) ->appendChild($parent->ownerDocument->createCDATASection($this->defaultValue)); } if ($this->textToShow != "") { $parent->appendChild(new DOMElement('textToShow')) ->appendChild($parent->ownerDocument->createCDATASection($this->textToShow)); } return $parent; } public static function findAll(DOMNode $context) { return MotoXML::findByXPath(".//item", $context, get_class()); } } ?>