Last active
December 16, 2015 08:08
-
-
Save toddjcrane/5403373 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Copyright 2013 Todd Crane. All Rights Reserved. GPL-type license TBD */ | |
class web_table { | |
protected $tableName = 'UnnamedTable'; | |
protected $numCols = 0; | |
protected $numRows = 0; | |
protected $rows = array(); | |
/* TODO: devise method for merged cells (colspan= and rowspan=)*/ | |
public function __construct ($name = "UnnamedTable") { | |
$this -> tableName = $name; | |
return 0; | |
} | |
public function insertColumn() { | |
// Argument 1: name | |
// Argument 2: index | |
$args = func_get_args(); | |
if (!isset($args[0])) $args[0] = "UnnamedColumn"; | |
if (!isset($args[1])) $args[1] = $this->numCols; | |
$this->numCols++; | |
$rowi = 0; | |
while ($rowi < $this -> numRows) { | |
$this->rows[$rowi]['value'][$args[1]] = array('name'=>'unnamedCell','value'=> NULL); | |
$rowi++; | |
} | |
return 0; | |
} | |
public function insertRow() { | |
// Argument 1: name | |
// Argument 2: index | |
$args = func_get_args(); | |
if (!isset($args[0])) $args[0] = "UnnamedRow"; | |
if (!isset($args[1])) $args[1] = $this->numRows; | |
$this->numRows++; | |
if (isset($this->rows[$args[1]])) $this->pushRows($args[1]); | |
$this->rows[$args[1]] = array ('name' => $args[0], 'value' => array()); | |
$coli = 0; | |
while ($coli < $this -> numCols) { | |
$this->rows[$args[1]]['value'][$coli] = array('name'=>'unnamedCell','value'=> NULL); | |
$coli++; | |
} | |
return 0; | |
} | |
public function defineCell($row,$col,$value) { | |
$this->rows[$row]['value'][$col]['value'] = $value; | |
/* TODO: FINISH FUNCTION defineCell()*/ | |
return 0; | |
} | |
public function addHeader() { | |
$this->insertRow("Header",0); | |
return 0; | |
} | |
public function addFooter () { | |
/* TODO: CREATE FUNCTION AddFooter()*/ | |
return 0; | |
} | |
public function printTable ($echo = TRUE) { | |
$iRow = 0; | |
$return = "<table id=\"{$this->tableName}\" name=\"{$this->tableName}\">"; | |
while ($iRow < $this->numRows) { | |
if ($iRow%2) $rowclass = "rowOdd"; | |
else $rowclass = "rowEven"; | |
$return .= "<tr id=\"{$this->rows[$iRow]['name']}\" name=\"{$this->rows[$iRow]['name']}\" class=\"{$this->rows[$iRow]['name']} {$rowclass}\">"; | |
$iCol = 0; | |
while ($iCol < $this->numCols) { | |
if ($iCol%2) $colclass = "colOdd"; | |
else $colclass = "colEven"; | |
$return .= "<td id=\"{$this->rows[$iRow]['value'][$iCol]['name']}\" name=\"{$this->rows[$iRow]['value'][$iCol]['name']}\" class=\"{$this->rows[$iRow]['value'][$iCol]['name']} {$rowclass} {$colclass}\">{$this->rows[$iRow]['value'][$iCol]['value']}</td>"; | |
$iCol++; | |
} | |
$return .= "</tr>"; | |
$iRow ++; | |
} | |
$return .= "</table>"; | |
if ($echo) echo $return; | |
return $return; | |
} | |
protected function pushRows ($index) { | |
$i = $this->numRows; | |
while ($i > $index) { | |
$i--; | |
$this->rows[$i+1] = $this->rows[$i]; | |
} | |
return 0; | |
} | |
} | |
// SDG | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment