Example #1
0
 private function render(\DOMDocument $doc, Element $element, $parent = null)
 {
     if ($element instanceof \tarcisio\svg\SVG) {
         $svgs = $doc->getElementsByTagName('svg');
         $svg = $svgs->item(0);
         $svg->setAttribute('width', $element->width);
         $svg->setAttribute('height', $element->height);
         $svg->setAttribute('viewBox', "0 0 {$element->width} {$element->height}");
         $gs = $doc->getElementsByTagName('g');
         $g = $gs->item(0);
         foreach ($element->getChildren() as $ch) {
             $this->render($doc, $ch, $g);
         }
         return $doc;
     }
     if (!is_null($element->getTitle())) {
         $element->appendChild(new Title('', $element->getTitle()));
     }
     $e = $doc->createElement($element->getElementName());
     $parent->appendChild($e);
     foreach ($element->getAttributes() as $k => $v) {
         if (!is_null($v)) {
             $e->setAttribute($k, $v);
         }
     }
     if (!is_null($element->getValue())) {
         $e->nodeValue = $element->getValue();
     }
     foreach ($element->getChildren() as $ch) {
         $this->render($doc, $ch, $e);
     }
     return $doc;
 }
Example #2
0
 /**
  * @param mixed  $value
  * @param string $message
  * @return boolean
  */
 public function isValid($value, &$messages = array())
 {
     if ($value != $this->compare->getValue()) {
         $messages[] = $this->getErrorMessage(self::ERR_NOT_EQUAL);
         return false;
     }
     return true;
 }
Example #3
0
 /**
  * @covers Xoops\Form\Element::getValue
  */
 public function testGetValue()
 {
     $name = 'name';
     $this->object->setValue($name);
     $value = $this->object->getValue();
     $this->assertSame($name, $value);
     $names = array('name1', 'name2');
     $this->object->setValue($names);
     $value = $this->object->getValue();
     $tmp = $names;
     array_unshift($tmp, $name);
     $this->assertSame($tmp, $value);
 }
Example #4
0
 /**
  * @param Element $element
  * @param \DOMNode $node
  */
 protected function build(Element $element, \DOMNode $node)
 {
     $dom = $this->getEngine();
     if ($element->getValue() instanceof Collection) {
         $newElement = $dom->createElement($element->getName());
         foreach ($element->getValue()->getElements() as $child) {
             $this->build($child, $newElement);
         }
     } else {
         $newElement = $dom->createElement($element->getName(), $element->getValue()->getValue());
     }
     foreach ($element->getAttributes()->getValues() as $attr => $value) {
         $newElement->setAttribute($attr, $value);
     }
     $node->appendChild($newElement);
 }
Example #5
0
 public function getValue()
 {
     $value = parent::getValue();
     if ($value == $this->m_Hint) {
         $this->m_Value = null;
         return null;
     }
     return $value;
 }
Example #6
0
 /**
  * Generates HTML output for the given field object and its child elements
  *
  * @internal
  * @param Element $objField The Element class-based object to parse
  * @param boolean $hideEmpty Set to true to hide empty field values from the overview. Defaults to false.
  * @param integer $intDynamicCount The dynamic counter for the current Element being parsed
  * @return string Generated HTML
  */
 private function fieldAsHtml($objField, $hideEmpty = false, $intDynamicCount = 0)
 {
     $strReturn = "";
     $strFieldName = $objField->getName();
     $strLabel = $objField->getShortLabel();
     // Passing 'true' gets the short label if available.
     $varValue = $intDynamicCount > 0 ? $objField->getValue($intDynamicCount) : $objField->getValue();
     $strValue = is_array($varValue) ? implode(", ", $varValue) : $varValue;
     if (!empty($strValue) && $hideEmpty || !$hideEmpty && !is_null($strValue)) {
         if (get_class($objField) == "ValidFormBuilder\\Hidden" && $objField->isDynamicCounter()) {
             return $strReturn;
         } else {
             switch ($objField->getType()) {
                 case static::VFORM_BOOLEAN:
                     $strValue = $strValue == 1 ? "yes" : "no";
                     break;
             }
             if (empty($strLabel) && empty($strValue)) {
                 // *** Skip the field.
             } else {
                 $strValue = nl2br($strValue);
                 $strValue = htmlspecialchars($strValue, ENT_QUOTES);
                 $strReturn .= "<tr class=\"vf__field_value\">";
                 $strReturn .= "<td valign=\"top\" style=\"padding-right: 20px\" class=\"vf__field\">" . ($strReturn .= $strLabel . ($strReturn .= "</td>" . ($strReturn .= "<td valign=\"top\" class=\"vf__value\">" . ($strReturn .= "<strong>" . $strValue . "</strong>" . ($strReturn .= "</td>\n")))));
                 $strReturn .= "</tr>";
             }
         }
     }
     return $strReturn;
 }
Example #7
0
 /**
  * Get checkbox value
  *
  * See {@link \ValidFormBuilder\Element::getValue()}
  *
  * @internal
  * @see \ValidFormBuilder\Element::getValue()
  */
 public function getValue($intDynamicPosition = 0)
 {
     $varValue = parent::getValue($intDynamicPosition);
     return strlen($varValue) > 0 && $varValue !== 0 ? true : false;
 }
Example #8
0
 /**
  * Radio element type
  * @param Element $element
  * @param $fieldHtml
  * @throws \Exception
  */
 protected static function radio(Element &$element, &$fieldHtml)
 {
     $name = $element->getName();
     $id = $element->getId();
     $value = $element->getValue();
     if ($element->getType() == self::TYPE_MULTICHECKBOX && !is_array($value)) {
         $value = array();
     }
     $options = $element->getProperties('options');
     if (!is_array($options)) {
         throw new \Exception("Options for field type '{$element->getType()}' must be given as array.");
     }
     //classes
     $class = $element->getProperties('class');
     if (!is_array($class)) {
         $class = array();
     }
     $attributes = $element->getProperties('attributes');
     $extraAttributes = '';
     if (is_array($attributes)) {
         foreach ($attributes as $attr => $val) {
             if (is_string($attr)) {
                 $extraAttributes .= sprintf('%s="%s" ', $attr, $val);
             } else {
                 $extraAttributes .= sprintf('%s ', $val);
             }
         }
     }
     foreach ($options as $option => $lbl) {
         $optionAttributes = $extraAttributes;
         //does this option have its own settings?
         if (is_array($lbl)) {
             $optionSettings = $lbl;
             if (!isset($optionSettings['label'])) {
                 throw new \Exception("A label has not been set for one of the arrayed options for field - " . $element->getName(true));
             }
             $lbl = $optionSettings['label'];
             if (isset($optionSettings['attributes']) && is_array($optionSettings['attributes'])) {
                 foreach ($optionSettings['attributes'] as $attr => $val) {
                     if (is_string($attr)) {
                         $optionAttributes .= sprintf('%s="%s" ', $attr, $val);
                     } else {
                         $optionAttributes .= sprintf('%s ', $val);
                     }
                 }
             }
         }
         $labelHtml = self::$templates['label'];
         $labelHtml = str_replace('{{id}}', "{$id}_{$option}", $labelHtml);
         $labelHtml = str_replace('{{text}}', $lbl, $labelHtml);
         if ($element->getType() == self::TYPE_RADIO) {
             $field = self::$templates[self::TYPE_RADIO];
             $field = str_replace('{{name}}', $name, $field);
             $field = str_replace('{{value}}', 'value="' . $option . '" ' . ($option == $value ? ' checked="checked"' : ''), $field);
         } else {
             if ($element->getType() == self::TYPE_MULTICHECKBOX) {
                 $field = self::$templates[self::TYPE_CHECKBOX];
                 $field = str_replace('{{name}}', "{$name}[]", $field);
                 $field = str_replace('{{value}}', 'value="' . $option . '" ' . (in_array($option, $value) ? ' checked="checked"' : ''), $field);
             }
         }
         $field = str_replace('{{id}}', "{$id}_{$option}", $field);
         $field = str_replace('{{class}}', implode(' ', $class), $field);
         $field = str_replace('{{attributes}}', $optionAttributes, $field);
         $field .= ' ' . $labelHtml;
         $options[$option] = "<div>{$field}</div>";
     }
     $fieldHtml = '<div>' . implode('', $options) . '</div>';
 }
Example #9
0
 /**
  * Render an element
  *
  * @param Element  $element  Form element
  *
  * @return string
  */
 public static function element(Element $element)
 {
     $meta = $element->getMeta();
     $html = $element instanceof Select ? self::options($element->getOptions(), array_flip((array) $element->getValue())) : $meta['html'];
     return $meta['before'] . self::tag($element->getTag(), $element->getAttributes(), $html) . $meta['after'];
 }