This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/application/classes/lnapp/table.php

64 lines
1.4 KiB
PHP
Raw Normal View History

2011-08-16 02:27:19 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class is for rendering a table of data.
*
* @package lnApp
* @subpackage Page
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
* @uses Style
*/
class lnApp_Table {
public static function limit($data,$rows,array $cols,$other) {
if (! (array)$data)
return '';
$output = '';
$other = $i = 0;
$output = '<table border="0">';
$output .= '<tr><th>'.implode('</th><th>',array_keys($cols)).'</th></tr>';
foreach ($data as $do) {
if ($i++ < $rows) {
$output .= '<tr>';
foreach (array_values($cols) as $col) {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
$output .= sprintf('<td>%s</td>',$x);
}
$output .= '</tr>';
} else {
if (is_array($do) AND isset($do[$col]))
$x = $do[$col];
// If the col is a method, we need to eval it
elseif (preg_match('/\(/',$col))
eval("\$x = \$do->$col;");
else
$x = $do->{$col};
$other += $x;
}
}
if ($other)
$output .= sprintf('<tr><td>Other</td><td colspan="%s">(%s) %s</td></tr>',count($cols)-1,$i-$rows,$other);
$output .= '</table>';
return $output;
}
}
?>