Files
pmgr/site/views/elements/table.ctp
abijah a1bab966ed Added descriptive text to the customer entry page, as well as work to associate labels with the inputs and set their class dynamically, to flag missing required fields.
git-svn-id: file:///svn-source/pmgr/branches/pre_0.1_work_20090819@753 97e9348a-65ac-dc4b-aefc-98561f571b83
2009-08-23 23:12:04 +00:00

90 lines
2.8 KiB
PHP

<?php /* -*- mode:PHP -*- */
/* table.ctp */
/*
*
* @filesource
* @copyright Copyright 2009, Abijah Perkins
* @package pmgr
*/
// The caller may not have given us a row_class, or may have given
// it as a non-array. Ultimately, we want it to be an array with
// an entry for each row, where each entry is an array of classes.
if (!isset($row_class) || !is_array($row_class))
$row_class = array();
// Same for the column_class, except columns instead of rows.
if (!isset($column_class) || !is_array($column_class))
$column_class = array();
// Give a default if not caller supplied.
if (!isset($suppress_alternate_rows))
$suppress_alternate_rows = false;
// If we have rows, then we have a table... go to work
if (isset($rows) && is_array($rows) && count($rows)) {
// Prework to get each element of row_class as an
// array of classes, lowercased and whitespace free.
foreach ($row_class AS &$rca) {
if (!is_array($rca))
$rca = array($rca);
foreach ($rca AS &$rc)
$rc = preg_replace("/ /", "-", preg_replace('/\./', '', strtolower($rc)));
}
// Same prework for column_class
foreach ($column_class AS &$cca) {
if (!is_array($cca))
$cca = array($cca);
foreach ($cca AS &$cc)
$cc = preg_replace("/ /", "-", preg_replace('/\./', '', strtolower($cc)));
}
// Associate each cell with the appropriate class(es).
// NOTE: Very kludgy solution on the row class(es).
// I want the row_class to affix to the <tr> tag.
// tableCells, however, does not have such ability :-/
// Therefore, the row class(es) get replicated to each
// cell within the row.
foreach ($rows AS $r => &$row) {
foreach ($row AS $c => $col) {
$cell_class = implode(" ", array_merge(empty( $row_class[$r]) ? array() : $row_class[$r],
empty($column_class[$c]) ? array() : $column_class[$c]));
if ($cell_class)
$row[$c] = array($col, array('class' => $cell_class));
}
}
// Allow user to specify a list of classes
if (isset($class) && is_array($class))
$class = implode(' ', $class);
// OK, output the table HTML
echo('<TABLE' .
(empty($id) ? '' : ' ID="'.$id.'"') .
(empty($class) ? '' : ' CLASS="'.$class.'"') .
'>' . "\n");
if (!empty($caption))
echo(' <CAPTION>' . $caption . '</CAPTION>' . "\n");
if (isset($headers) && is_array($headers)) {
echo(' <THEAD>' . "\n");
echo $html->tableHeaders($headers) . "\n";
echo(' </THEAD>' . "\n");
}
echo(' <TBODY>' . "\n");
echo $html->tableCells($rows,
$suppress_alternate_rows ? null : array('class' => "oddrow"),
$suppress_alternate_rows ? null : array('class' => "evnrow"),
false, false) . "\n";
echo(' </TBODY>' . "\n");
echo('</TABLE>' . "\n");
}