Created
August 17, 2009 02:56
-
-
Save Me1000/168865 to your computer and use it in GitHub Desktop.
An implementation of NSTableView delegate style table building in PHP
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 | |
class PHPTableView //extends PHPObject LULZ | |
{ | |
var $delegate; //actually doesn't do anything... but you know. | |
var $dataSource; | |
var $columns; //theoretically a column should be an object but for simplicty sake it's just an array of the column header text... This also needs to be initialized. $tableview->coumns = array(); should work... or in an init method for this class itself. | |
var $rows; //int | |
var $dataArray; // | |
function setDeleagte($aDelegate) | |
{ | |
$this->delegate = $aDelegate; | |
} | |
function setDataSource($aSource) | |
{ | |
$this->dataSource = $aSource; | |
$this->reloadData(); | |
} | |
function reloadData() //this is used because the data is part of the tableview until it has to pull the data again (from the datasource) | |
{ | |
$this->rows = $this->dataSource->numberOfRowsInTableView($this); | |
$this->dataArray = array(); //clear out the array | |
for($r = 0; $r < $this->rows; $r++) | |
{ | |
for($c = 0; $c < count($this->columns); $c++) | |
{ | |
$this->dataArray[$r] = array(); | |
$this->dataArray[$r][$c] = $this->dataSource->tableViewObjectValueForTableColumnRow($this, $c, $r); | |
} | |
} | |
} | |
function addColumn($aColumn) | |
{ | |
arrayPush($this->columns, $aColumn); | |
} | |
function displayTable() | |
{ | |
$render = "<table>"; | |
//header loop | |
$render .= "<th>"; | |
for($c = 0; $c < count($this->columns); $c++) | |
{ | |
$render .= "<td>" . $this->columns[$c] . "</td>"; | |
} | |
$render .= "</th>"; | |
//content loop | |
for($r = 0; $r < $this->rows; $r++) | |
{ | |
$render .= "<tr>"; | |
for($c = 0; $c < count($this->columns); $c++) | |
{ | |
$render .= "<td>" . $this->dataArray[$r][$c] . "</td>"; | |
} | |
$render .= "</tr>"; | |
} | |
$render .= "</table>"; | |
return $render; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment