Advertisement
carlosjuero

testing php classes

Sep 26th, 2022 (edited)
870
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  * Copyright (c) 2022 Carlosjuero
  5.  * http://localhost/
  6.  */
  7.  
  8. /**
  9.  * Description of tableBuilder
  10.  *
  11.  * @author prepf
  12.  */
  13.  
  14. class tableBuilder {
  15.     // Table Building class
  16.     public $tableData = array();
  17.     public $tableStartTag = array();
  18.     public $tableRows = array();
  19.     public $tableCells = array();
  20.     private $rowCount = array();
  21.     private $cellCount = array();
  22.     private $tmpTableRows = array();
  23.    
  24.    
  25.     function __construct($tableID, $tableClass) {
  26.         if ($tableClass != null) {
  27.             $this->tableStartTag[$tableID] = '<table class="' . $tableClass . '">';
  28.         } else {
  29.             $this->tableStartTag[$tableID] = "<table>";
  30.         }
  31.     }
  32.    
  33.     function addTableRow($tableID, $rowClass) {
  34.         // Build Table Rows
  35.         $this->rowCount[$tableID] += 1;
  36.         $tmpData = '<tr class="' . $rowClass . '">';
  37.         $this->tmpTableRows[$tableID][$this->rowCount[$tableID]] = $tmpData;
  38.     }
  39.    
  40.     function buildTableRows($tableID) {
  41.         $curRow = 1;
  42.         foreach ($this->tmpTableRows[$tableID] as $trow) {
  43.             $tmpData .= $trow[$tableID][$curRow];
  44.             $curCell = 1;
  45.             foreach ($this->tableCells[$tableID][$curRow] as $tcell) {
  46.                 $tmpData .= $this->tableCells[$tableID][$curRow][$curCell];
  47.                 $curCell +=1;
  48.             }
  49.             $tmpData .= '</tr>';
  50.             $this->tableRows[$tableID][$curRow] = $tmpData . PHP_EOL;
  51.             $curRow += 1;
  52.         }
  53.     }
  54.    
  55.     function addTableCells($tableID, $colspan, $cellData) {
  56.         // Build Table Cells
  57.         $rowID = $this->rowCount[$tableID];
  58.         $this->cellCount[$tableID][$rowID] += 1;
  59.         if ($colspan > 0) {
  60.             $colspanAdd = ' colspan="' . $colspan . '" ';
  61.         } else {
  62.             $colspanAdd = '';
  63.         }
  64.         $tmpData = '<td' . $colspanAdd . '>' . $cellData . '</td>' . PHP_EOL;
  65.         $this->tableCells[$tableID][$rowID][$this->cellCount[$tableID][$rowID]] = $tmpData;
  66.        
  67.     }
  68.    
  69.     function startTable($tableID) {
  70.         return PHP_EOL . $this->tableStartTag[$tableID] . PHP_EOL;
  71.        
  72.     }
  73.    
  74.     function endTable() {
  75.         return PHP_EOL . '</table>' . PHP_EOL . '<!-- End Table Builder Output -->' . PHP_EOL;
  76.        
  77.     }
  78.    
  79.     function buildTable($tableID) {
  80.         $this->buildTableRows($tableID);
  81.         $tmpData = startTable($tableID);
  82.         foreach ($this->rowCount[$tableID] as $tRow) {
  83.             $tmpData .= $this->tableRows[$tableID][$tRow];
  84.         }
  85.     }
  86. }
  87.  
Tags: php
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement