$fm = array('RLTB' => 'Right to left, top to bottom', 'RLBT' => 'Right to left, bottom to top', 'LRTB' => 'Left to right, top to bottom', 'LRBT' => 'Left to right, bottom to top', 'TBLR' => 'Top to bottom, left to right', 'TBRL' => 'Top to bottom, right to left', 'BTLR' => 'Bottom to top, left to right', 'BTRL' => 'Bottom to top, right to left', 'InC' => 'Inwards, clockwise', 'InCC' => 'Inwards, counter-clockwise', 'OutC' => 'Outwards, clockwise', 'OutCC' => 'Outwards, counter-clockwise'); $def['number'] = 5; $def['cols'] = 5; $form = new HTML_QuickForm('formMatrixExample'); if ($_POST) { $form->setDefaults($_POST); } else { $form->setDefaults($def); } $form->addElement('header', '', "HTML_Table_Matrix Example"); $form->addElement('select', 'number', "Number of items", $nSel); $form->addElement('select', 'cols', "Columns", $sel); $form->addElement('select', 'rows', "Rows", $sel); $form->addElement('select', 'startcol', "X Offset", $sel); $form->addElement('select', 'startrow', "Y Offset", $sel); $form->addElement('select', 'fillmode', "Fill", $fm); $form->addElement('submit', "Submit"); $form->display(); if ($_POST) { echo "<br><hr>"; $nw = new Numbers_Words(); for ($i = 1; $i <= $_POST['number']; $i++) { $data[] = $nw->toWords($i); } $m->setData($data); $m->setTableSize($_POST['rows'], $_POST['cols']); $m->setFillStart($_POST['startrow'], $_POST['startcol']); $f = HTML_Table_Matrix_Filler::factory($_POST['fillmode'], $m); $m->accept($f); print $m->toHtml(); }
/** * Fills table with provided data. RL & BT modes are not implemented yet. * * This function does the actual laying out of the data into the table. * It isn't necessary to call this unless you want to add or change something * in the table, as toHtml() calls this automatically if the table has not * yet been filled with data. * * @return mixed boolean true on success, PEAR_Error otherwise * @see setData() */ function fillTable() { if (!HTML_Table_Matrix_Filler::isValid($this->_filler)) { return PEAR::raiseError("No Filler has been set."); } $this->_calculateSize(); reset($this->_data); $size = $this->_getTableSize(); $this->_data = array_slice($this->_data, 0, $size); if (isset($this->_filler->callback)) { if (!is_callable($this->_filler->callback) || !is_array($cr = call_user_func($this->_filler->callback, $this->_data))) { return PEAR::raiseError("Invalid filler callback."); } $this->_data = $cr; } for ($i = $index = 0; $i < $size; $i++, $index++) { list($row, $col) = $this->_filler->next($index); $this->_fillCell($row, $col); } $this->_isFilled = TRUE; return true; }