Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Copyright (c) 2022 Carlosjuero
- * http://localhost/
- */
- /**
- * Description of tableBuilder
- *
- * @author prepf
- */
- class tableBuilder {
- // Table Building class
- public $tableData = array();
- public $tableStartTag = array();
- public $tableRows = array();
- public $tableCells = array();
- private $rowCount = array();
- private $cellCount = array();
- private $tmpTableRows = array();
- function __construct($tableID, $tableClass) {
- if ($tableClass != null) {
- $this->tableStartTag[$tableID] = '<table class="' . $tableClass . '">';
- } else {
- $this->tableStartTag[$tableID] = "<table>";
- }
- }
- function addTableRow($tableID, $rowClass) {
- // Build Table Rows
- $this->rowCount[$tableID] += 1;
- $tmpData = '<tr class="' . $rowClass . '">';
- $this->tmpTableRows[$tableID][$this->rowCount[$tableID]] = $tmpData;
- }
- function buildTableRows($tableID) {
- $curRow = 1;
- foreach ($this->tmpTableRows[$tableID] as $trow) {
- $tmpData .= $trow[$tableID][$curRow];
- $curCell = 1;
- foreach ($this->tableCells[$tableID][$curRow] as $tcell) {
- $tmpData .= $this->tableCells[$tableID][$curRow][$curCell];
- $curCell +=1;
- }
- $tmpData .= '</tr>';
- $this->tableRows[$tableID][$curRow] = $tmpData . PHP_EOL;
- $curRow += 1;
- }
- }
- function addTableCells($tableID, $colspan, $cellData) {
- // Build Table Cells
- $rowID = $this->rowCount[$tableID];
- $this->cellCount[$tableID][$rowID] += 1;
- if ($colspan > 0) {
- $colspanAdd = ' colspan="' . $colspan . '" ';
- } else {
- $colspanAdd = '';
- }
- $tmpData = '<td' . $colspanAdd . '>' . $cellData . '</td>' . PHP_EOL;
- $this->tableCells[$tableID][$rowID][$this->cellCount[$tableID][$rowID]] = $tmpData;
- }
- function startTable($tableID) {
- return PHP_EOL . $this->tableStartTag[$tableID] . PHP_EOL;
- }
- function endTable() {
- return PHP_EOL . '</table>' . PHP_EOL . '<!-- End Table Builder Output -->' . PHP_EOL;
- }
- function buildTable($tableID) {
- $this->buildTableRows($tableID);
- $tmpData = startTable($tableID);
- foreach ($this->rowCount[$tableID] as $tRow) {
- $tmpData .= $this->tableRows[$tableID][$tRow];
- }
- }
- }
Advertisement
Comments
-
- I noticed an extra close bracket but it isn't throwing an error
Add Comment
Please, Sign In to add comment
Advertisement