children = $childs; } } /** * Makes a new instance of the object in a static fashion * * @return object */ public static function make() { $obj = new ReflectionClass(__CLASS__); $args = func_get_args(); return $obj->newInstanceArgs($args); } // ################################################################### /** * Prints a simple row of text and text * * @param string Label (left side) * @param string Value (right side) * * @return BSPrinterTableElement Table row element */ public static function row_label($label, $value) { $tr = new BSPrinterTableElement(); $tr->addChild(new BSPrinterLabelElement($label)); $tr->addChild(new BSPrinterLabelElement($value)); return $tr; } // ################################################################### /** * Creates an input[text/password] field row * * @param string Label * @param string Field name * @param mixed Default value * @param bool A password field? * * @return BPrinterTableElement Table row element */ public static function row_text($label, $name, $value = null, $password = false) { $tr = new BSPrinterTableElement(); $tr->addChild(new BSPrinterLabelElement($label)); $tr->addChild(new BSPrinterBaseElement(($password ? 'password' : 'text'), $name, $value)); return $tr; } // ################################################################### /** * Creates a submit row * * @param array Child elements to add before the buttons * @param string Save button text * @param string Reset button text * * @return BSPrinterTableElement Table row element */ public static function row_submit(Array $children = null, $save = ':submit:', $reset = ':reset:') { $build = ''; if (sizeof($children) > 0) { foreach ($children as $child) { $build .= "\n\t\t\t" . $child->paint(); } } $save = ($save == ':submit:' ? _('Submit') : $save); $reset = ($reset == ':reset:' ? _('Reset') : $reset); if (!is_null($save)) { $elm = new BSPrinterBaseElement('submit', '__submit__', " $save "); $elm->setAccessKey('s'); $build .= "\n\t\t\t" . $elm->paint(); } if (!is_null($reset)) { $elm = new BSPrinterBaseElement('reset', '__reset__', " $reset "); $elm->setAccessKey('r'); $build .= "\n\t\t\t" . $elm->paint() . "\n\t\t"; } $tr = new BSPrinterTableElement(); $tr->addChild(new BSPrinterLabelElement($build)); $tr->setCssClass('tfoot'); return $tr; } // ################################################################### /** * Constructs a * * @return BSPrinterTableElement Upload form */ public static function row_upload($label, $name) { $tr = new BSPrinterTableElement(); $tr->addChild(new BSPrinterLabelElement($label)); $tr->addChild(new BSPrinterBaseElement('upload', $name)); return $tr; } // ################################################################### /** * Creates a row with a radio select option for yes/no * * @param string Row label * @param string Name of the radio buttons * @param bool Yes is selected? (if false, No is selected) * * @return BSPrinterTableElement Yes-No row */ public static function row_yes_no($label, $name, $yes) { $elm = new BSPrinterBaseElement('radio', $name, 1); $elm->setActive($yes); $build = $elm->paint() . ' ' . _('Yes') . ' '; $elm = new BSPrinterBaseElement('radio', $name, 0); $elm->setActive(!$yes); $build .= $elm->paint() . ' ' . _('No'); $tr = new BSPrinterTableElement(); $tr->addChild(new BSPrinterLabelElement($label)); $tr->addChild(new BSPrinterLabelElement($build)); return $tr; } // ################################################################### /** * Prints a row with a textarea * * @param string Label * @param string Textarea name * @param string Value to fill with * * @return BSPrinterTableElement Table row */ public static function row_textarea($label, $name, $value = null) { $tr = new BSPrinterTableElement(); $tr->addChild(new BSPrinterLabelElement($label)); $tr->addChild(new BSPrinterBaseElement('textarea', $name, $value)); return $tr; } // ################################################################### /** * Returns the number of columns in this element * * @return integer Column count */ public function numberOfColumns() { return sizeof($this->children); } // ################################################################### /** * Adds a child node to the element * * @param BSPrinterElement A child element * * @return fluent interface */ public function addChild(BSPrinterElement $child) { $this->children[] = $child; return $this; } // ################################################################### /** * Sets the number of columns this row should have and pads the * elements accordingly * * @param integer Column count * * @return fluent interface */ public function setColumnNumber($cols) { if ($cols < $this->numberOfColumns()) { throw new Exception('You need to have at least ' . $this->numberOfColumns() . ' columns'); } $this->colspan = $cols; return $this; } // ################################################################### /** * Returns the HTML for all printed children elements * * @return string Printed HTML */ protected function _paintChildren() { $builder = ''; $numCols = $this->numberOfColumns(); $even = true; if ($this->colspan % $numCols == 0) { $cols = $this->colspan / $numCols; $even = true; } else { $cols = intval($this->colspan / $numCols); $even = false; } $i = 0; foreach ($this->children as $child) { $i++; $colspan = (($i == $numCols && !$even) ? $cols + 1 : $cols); $builder .= "\n\t\t 1 ? ' colspan="' . $colspan . '"' : '') . ">" . $child->paint() . ""; } return $builder; } // ################################################################### /** * Paints the entire table row * * @return string Table row HTML */ public function paint() { return "\t_prepareStyle() . ">" . $this->_paintChildren() . "\n\t"; } } ?>