cvs: pear /HTML_OOH_Form/layoutmanager form_flowlayout.php form_gridlayout.php form_grouplayout.php form_layoutmanager.php form_themed_flowlayout.php
form_themed_gridlayout.php

From: Date: Sun, 14 Oct 2001 18:19:19 +0000
Subject: cvs: pear /HTML_OOH_Form/layoutmanager form_flowlayout.php form_gridlayout.php form_grouplayout.php form_layoutmanager.php form_themed_flowlayout.php
form_themed_gridlayout.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-1016@lists.php.net to get a copy of this message
uw Sun Oct 14 14:19:19 2001 EDT Added files: /pear/HTML_OOH_Form/layoutmanager form_flowlayout.php form_gridlayout.php form_grouplayout.php form_layoutmanager.php form_themed_flowlayout.php form_themed_gridlayout.php Log: Here you go with the layoutmanager.

Index: pear/HTML_OOH_Form/layoutmanager/form_flowlayout.php +++ pear/HTML_OOH_Form/layoutmanager/form_flowlayout.php <?php include_once(FORM_INCLUDE_DIR . 'layoutmanager/form_layoutmanager.php'); /** * Flowlayout manager * * This class uses a slightly modifiedflow layout manager rule to * layout items. The usual rule is "put as many as you can in a row [and * give each of the items of a row the same space]". * * Of course you can't implement such a rule for html as you don't know * the size of an item nor the size of a row at least not the size a client * can display. So, I decided to use this rule: "put all items in one table * as long as I don't tell you to insert a row." * * Use insertBreak() for a row. * * @version $Id: form_flowlayout.php,v 1.1 2001/10/14 18:19:18 uw Exp $ * @author Ulf Wendel <ulf.wendel@phpdoc.de> * @package Form * @access public */ class flowlayout extends layoutmanager { /** * Current row * * @var int */ var $row = 0; /** * Current col * * @var int */ var $col = 0; function get() { $ret = '<table border="0" cellspacing="0" cellpadding="0">'; reset($this->items); while (list($row, $cols) = each($this->items)) { $ret .= '<tr><td><table width="100%" cellspacing="0" cellpadding="0"><tr>'; // well, it's ok for me $size = round(100 / count($cols)); reset($cols); while (list($col, $data) = each($cols)) { if (is_array($data)) $data = $this->callMethod($data['method'], &$data['obj'], $data['params']); #$ret .= sprintf('<td align="left" valign="top" width="%d%%">%s</td>', $size, $data); $ret .= sprintf('<td align="left" valign="top">%s</td>', $data); } $ret .= '</td></tr></table></tr>'; } $ret .= '</table>'; return $ret; } // end func get function addItem(&$obj, $display_method = 'get', $method_params = '') { $this->items[$this->row][$this->col++] = array( 'obj' => &$obj, 'method' => $display_method, 'params' => $method_params ); } // end func addItem function addContent($content) { $this->items[$this->row][$this->col++] = $content; } // end func addContent /** * Adds a break * * A break starts a new table under the first one. * All tables are tied together in an outer table which ensures that * we get a homogenous with of all rows. */ function insertBreak() { $this->row++; } // end func insertBreak } // end class flowlayout ?> Index: pear/HTML_OOH_Form/layoutmanager/form_gridlayout.php +++ pear/HTML_OOH_Form/layoutmanager/form_gridlayout.php <?php include_once(FORM_INCLUDE_DIR . 'layoutmanager/form_layoutmanager.php'); /** * Very simple grid layout manager * * A grid layout manager is one of the most basic layout managers at all. * All you do is define a grid and assign items to each cell. * * @access public * @version $Id: form_gridlayout.php,v 1.1 2001/10/14 18:19:18 uw Exp $ * @author Ulf Wendel <ulf.wendel@phpdoc.de> * @package Form */ class gridlayout extends layoutmanager { /** * Size of the grid * * @var array s */ var $grid_size = NULL; /** * Coordinates (row/col) of the next cell. * * @var array */ var $next_cell = NULL; /** * Creates a grid * * @param int rows * @param int cols */ function gridlayout($rows = 1, $cols = 1) { $this->grid_size['rows'] = $rows; $this->grid_size['cols'] = $cols; $this->next_cell = array('row' => 0, 'col' => 0); if (method_exists($this, 'layoutmanager*')) $this->layoutmanager(); } // end constructor function get() { $ret = '<table border="0" cellspacing="0" cellpadding="0">'; reset($this->items); while (list($row, $cols) = each($this->items)) { $ret .= '<tr>'; $size = round(100 / count($cols)); reset($cols); while (list($col, $data) = each($cols)) { if (is_array($data)) $data = $this->callMethod($data['method'], &$data['obj'], $data['params']); #$ret .= sprintf('<td align="left" valign="top" width="%d%%">%s</td>', $size, $data); $ret .= sprintf('<td align="left" valign="top">%s</td>', $data); } $ret .= '</tr>'; } $ret .= '</table>'; return $ret; } // end func get /** * Fills a cell / adds an item. * * @param object mixed item * @param string name of the display method * @param array list of display method parameters * @param int cell-ID. Cellnumbering starts with 1. * In case of a 2/2 grip 1 is the upper left * and 4 the lower right */ function addItem(&$obj, $display_method = 'get', $method_params = '', $cell = -1) { list($row, $col) = $this->getCell($cell); $this->items[$row][$col] = array( 'obj' => &$obj, 'method' => $display_method, 'params' => $method_params ); } // end func addItem /** * ... * * @param string * @param int cell-ID */ function addContent($content, $cell = -1) { list($row, $col) = $this->getCell($cell); $this->items[$row][$col] = $content; } // end func addContent /** * Returns the coordinates of the requested cell and updates next_cell * * @param int cell-ID * @see $next_cell, addContent(), addItem() */ function getCell($cell) { if (-1 == $cell) { $row = $this->next_cell['row']; $col = $this->next_cell['col']; } else { $row = floor($cell / $this->grid_size['cols']); $col = $cell % $this->grid_size['cols']; } if ($row > $this->grid_size['rows'] || $col > $this->grid_size['cols']) return false; if ($col == $this->grid_size['cols'] - 1) { $this->next_cell['row']++; $this->next_cell['col'] = 0; } else { $this->next_cell['col']++; } return array($row, $col); } // end func getRowCol } // end class gridlayout ?> Index: pear/HTML_OOH_Form/layoutmanager/form_grouplayout.php +++ pear/HTML_OOH_Form/layoutmanager/form_grouplayout.php <?php include_once(FORM_INCLUDE_DIR . 'layoutmanager/form_layoutmanager.php'); /** * Groups elements together in a nice box * * This is not really a layout manager. It's used to group * elements and draw a box around them which looks like * HTML 4 .... Sadly not all major browser support this tag. * * @access public * @author Ulf Wendel <ulf.wendel@phpdoc.de> * @version $Id: form_grouplayout.php,v 1.1 2001/10/14 18:19:18 uw Exp $ * @package Form */ class grouplayout extends layoutmanager { /** * Box label * * @var string */ var $label = ''; /** * Creates the template object * * @param string box label * @param string template file * @param string path to the template file */ function grouplayout($label, $tpl = 'grouplayout.html', $tpl_root = 'html/') { $this->themed(); $this->label = $label; $this->setTemplate($tpl, FORM_INCLUDE_DIR . $tpl_root); if (method_exists($this, 'layoutmanager')) $this->layoutmanager(); } // end constructor function addItem(&$obj, $display_method = 'get', $method_params = '') { $this->tpl->setVariable('CONTENT', $this->callMethod($display_method, &$obj, $method_params)); } // end func addItem function addContent($content) { $this->tpl->setVariable('CONTENT', $content); } // end func addContent function get() { $this->tpl->setVariable('LABEL', preg_replace('@\s@', '&nbsp;', $this->label)); return $this->tpl->get(); } // end func get } // end class grouplayout ?> Index: pear/HTML_OOH_Form/layoutmanager/form_layoutmanager.php +++ pear/HTML_OOH_Form/layoutmanager/form_layoutmanager.php <?php include_once(FORM_INCLUDE_DIR . 'IT.php'); /** * Abstract baseclass of all layoutmanager. * * Needs PHP 4.0.5+ * * @access public * @author Ulf Wendel <ulf.wendel@phpdoc.de> * @version $Id: form_layoutmanager.php,v 1.1 2001/10/14 18:19:18 uw Exp $ * @package Form */ class layoutmanager { /** * List of items to be arranged * * @var items */ var $items; /** * IT[X] template object * * @var object IT[X] template object */ var $tpl = ''; /** * Returns the generated HTML * * @abstract * @access public */ function get() { return NULL; } // end func get /** * Returns and prints the generated HTML * * @brother get() */ function show() { $ret = $this->get(); print $ret; return $ret; } // end func show /** * Add an item to the layout manager (drawing surface). * * @param object Object to add * @param string method of the object that returns it's html presentation * @param array optional parameters of the display method * Form needs this and it's handy anyway: $form->showElement(name) * object: $form * method: showElement * parameters: array(name) * @access public * @see addContent() */ function addItem(&$obj, $display_method = 'get', $method_params = '') { $this->addContent($this->callMethod($display_method, &$obj, $method_params)); } // end func addItem /** * Adds content to the layout manager. * * You can add objects using addItem() or content to the layout manager. * In case of addItem() you'll pass an object by reference to the layout manager * which generated the HTML the layout manager has to layout. In case of * addContent() you're providing the HTML content directly. * * @param string content to layout * @access public * @abstract * @see addItem() */ function addContent($content) { return NULL; } // end func addContent /** * Wrapper for call_user_method() and call_user_method_array * * @param string method * @param object mixed * @param mixed method parameters */ function callMethod($method, &$obj, $params) { if ('' != $params && !is_array($params)) $params = array($params); if (is_array($params)) return call_user_method_array($method, $obj, $params); else return call_user_method($method, $obj); } // end func callMethod /** * Creates the template object. * */ function themed() { $this->tpl = new IntegratedTemplate(); } // end constructor /** * Sets the template. * * @param string template file * @param string path of the template file */ function setTemplate($tpl, $tpl_root = '') { if ('' != $tpl_root) $this->tpl->setRoot($tpl_root); $this->tpl->loadTemplatefile($tpl, true, true); } // end setTemplate } // end class form_layoutmanager ?> Index: pear/HTML_OOH_Form/layoutmanager/form_themed_flowlayout.php +++ pear/HTML_OOH_Form/layoutmanager/form_themed_flowlayout.php <?php include_once(FORM_INCLUDE_DIR . 'layoutmanager/form_flowlayout.php'); /** * Themed flowlayout (using templates). * * @version $Id: form_themed_flowlayout.php,v 1.1 2001/10/14 18:19:18 uw Exp $ * @package Form * @access public * @author Ulf Wendel <ulf.wendel@phpdoc.de> */ class themed_flowlayout extends flowlayout { /** * Creates the required template object * * @param string template file * @param string path to the template file */ function themed_flowlayout($tpl = 'flowlayout.html', $tpl_root = 'html') { $this->themed(); $this->setTemplate($tpl, FORM_INCLUDE_DIR . $tpl_root); } // end func themed_flowlayout function get() { reset($this->items); while (list($row, $cols) = each($this->items)) { if (0 == count($cols)) { // break $this->tpl->setCurrentBlock('col'); $this->tpl->setVariable('ITEM', '<br>'); $this->tpl->setVariable('WIDTH'); $this->tpl->parseCurrentBlock(); $this->tpl->parse('row'); continue; } // well, it's ok for me $size = round(100 / count($cols)); $this->tpl->setCurrentBlock('col'); reset($cols); while (list($col, $data) = each($cols)) { if (is_array($data)) $this->tpl->setVariable('ITEM', $this->callMethod($data['method'], &$data['obj'], $data['params'])); else $this->tpl->setVariable('ITEM', $data); $this->tpl->setVariable('WIDTH', $size); $this->tpl->parseCurrentBlock(); } $this->tpl->parse('row'); } return $this->tpl->get(); } } // end class themed_flowlayout ?> Index: pear/HTML_OOH_Form/layoutmanager/form_themed_gridlayout.php +++ pear/HTML_OOH_Form/layoutmanager/form_themed_gridlayout.php <?php include_once(FORM_INCLUDE_DIR . 'layoutmanager/form_gridlayout.php'); /** * Gridlayout using templates. * * @version $Id: form_themed_gridlayout.php,v 1.1 2001/10/14 18:19:18 uw Exp $ * @package Form * @author Ulf Wendel <ulf.wendel@phpdoc.de> */ class themed_gridlayout extends gridlayout { /** * Creates grid and template. * * @param int grid height / number of rows * @param int grid width / number of columns * @param string template file * @param string path to the template file */ function themed_gridlayout($rows = 1, $cols = 1, $tpl = 'gridlayout.html', $tpl_root = 'html/') { $this->themed(); $this->setTemplate($tpl, FORM_INCLUDE_DIR . $tpl_root); $this->gridlayout($rows, $cols); } // end constructor function get() { reset($this->items); while (list($row, $cols) = each($this->items)) { $this->tpl->setCurrentBlock('col'); $size = round(100 / count($cols)); reset($cols); while (list($col, $data) = each($cols)) { if (is_array($data)) $this->tpl->setVariable('ITEM', $this->callMethod($data['method'], &$data['obj'], $data['params'])); else $this->tpl->setVariable('ITEM', $data); $this->tpl->setVariable('WIDTH', $size); $this->tpl->parseCurrentBlock(); } $this->tpl->parse('row'); } return $this->tpl->get(); } // end func get } // end class themed_gridlayout ?>
« previous php.pear.cvs (#1016) next »