/** \{ * \name Rendering methods */ function build_widget() { $name = $this->get('name'); $id = $this->get('id'); $multiple = $this->_get('multiple'); $threshold = $this->_get('threshold'); $num_options = count($this->_options); /* Decide how to render. The values 0 and -1 are special, and if there * are no options, always render a single element (perhaps JavaScript is * used to populate the control). */ if ($num_options === 0) { $render_many_elements = false; } elseif ($threshold === -1) { $render_many_elements = true; } elseif ($threshold === 0) { $render_many_elements = false; } elseif ($num_options <= $threshold) { $render_many_elements = true; } else { $render_many_elements = false; } if ($render_many_elements) { /* Render listing of checkboxes or radio buttons */ $out = new AnewtXHTMLFragment(); foreach ($this->_options as $option) { if ($multiple) { $child = $option->_build_checkbox(); } else { $child = $option->_build_radiobutton(); } $out->append_child($child); } /* Set the id property on the first child (this is the radio button * or checkbox) of the first option. */ if ($this->_options) { $out->child_nodes[0]->child_nodes[0]->set_attribute('id', $id); } } else { /* Render single select element */ if ($multiple) { $out = new AnewtXHTMLSelect(null, array('name' => sprintf('%s[]', $name), 'multiple' => 'multiple')); } else { $out = new AnewtXHTMLSelect(null, array('name' => $name)); } /* Set the id property. */ $out->set_attribute('id', $id); /* Set the height if provided. If the 'multiple' property is not * set, this forces a drop down select box to be displayed as * a multiline selection list. */ $size = $this->_get('size'); if (!is_null($size)) { assert('is_int($size);'); $out->set_attribute('size', (string) $size); } if ($this->_get('disabled')) { $out->set_attribute('disabled', 'disabled'); } foreach ($this->_options as $option_or_option_group) { $out->append_child($option_or_option_group->_build_option()); } } return $out; }
$fragment->append_child(new AnewtXHTMLHeader2('Tables')); $table = new AnewtXHTMLTable(); $table_head = new AnewtXHTMLTableHead(new AnewtXHTMLTableRow(ax_fragment(new AnewtXHTMLTableHeaderCell('Column 1'), new AnewtXHTMLTableHeaderCell('Column 2')))); $table->append_child($table_head); $table_body = new AnewtXHTMLTableBody(ax_fragment(new AnewtXHTMLTableRow(ax_fragment(new AnewtXHTMLTableCell('r1c1'), new AnewtXHTMLTableCell('r1c2')), new AnewtXHTMLTableRow(ax_fragment(new AnewtXHTMLTableCell('r2c1'), new AnewtXHTMLTableCell('r2c2')))))); $table->append_child($table_body); $fragment->append_child($table); /* Forms */ $fragment->append_child(new AnewtXHTMLHeader2('Forms')); $form = new AnewtXHTMLForm(null, array('method' => 'GET')); $input_fragment = new AnewtXHTMLFragment(); $input_fragment->append_child(new AnewtXHTMLLabel('Label: ', array('for' => 'test'))); $input_fragment->append_child(new AnewtXHTMLInput(null, array('name' => 'test', 'id' => 'test', 'type' => 'text'))); $form->append_child(new AnewtXHTMLParagraph($input_fragment)); $select = new AnewtXHTMLSelect(null, array('name' => 'select')); $select->append_child(new AnewtXHTMLOption('First', array('value' => 'first'))); $select->append_child(new AnewtXHTMLOption('Second', array('value' => 'second'))); $select->append_child(new AnewtXHTMLOption('Third', array('value' => 'third'))); $form->append_child(new AnewtXHTMLParagraph($select)); $fragment->append_child($form); $form->append_child(new AnewtXHTMLParagraph(new AnewtXHTMLInput(null, array('type' => 'submit')))); /* Convenience API */ $r = array(); $r[] = ax_h2('Convenience API'); $r[] = ax_p('Test with some <& special characters.', array('style' => 'color: #ccc;')); $r[] = ax_p_class(ax_raw('This is <strong>strong</strong>'), 'someclass'); $r[] = ax_p(ax_abbr('ICE', 'InterCity Express')); $r[] = ax_p(array('Test', ax_br(), 'after the break')); $p = ax_p(array('testje', array('1', '2'), ax_strong('blablabla'))); $p->set_attribute('id', 'paragraph-id'); $p->set_class('foo bar baz');