From c7ecf78e5f4645d54b41ee9e8e83ccfc8c25b8e3 Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 25 Feb 2009 08:07:19 +0000 Subject: [PATCH] tablelib: MDL-18372 Let people specify a CSS class name to add to the element. --- lib/tablelib.php | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index cf81a639ae..99d72a0d41 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -587,10 +587,10 @@ class flexible_table { * array corresponding to a column in the table. It puts the row elements in * the proper order. * @param $rowwithkeys array - * + * @param string $classname CSS class name to add to this row's tr tag. */ - function add_data_keyed($rowwithkeys){ - $this->add_data($this->get_row_from_keyed($rowwithkeys)); + function add_data_keyed($rowwithkeys, $classname = ''){ + $this->add_data($this->get_row_from_keyed($rowwithkeys), $classname); } /** @@ -611,9 +611,10 @@ class flexible_table { * Can be used as before. print_html now calls finish_html to close table. * * @param array $row a numerically keyed row of data to add to the table. + * @param string $classname CSS class name to add to this row's tr tag. * @return boolean success. */ - function add_data($row) { + function add_data($row, $classname = '') { if(!$this->setup) { return false; } @@ -627,7 +628,7 @@ class flexible_table { $this->exportclass->add_data($row); } } else { - $this->print_row($row); + $this->print_row($row, $classname); } return true; } @@ -910,39 +911,44 @@ class flexible_table { /** * This function is not part of the public api. */ - function print_row($row){ + function print_row($row, $classname = '') { static $suppress_lastrow = NULL; static $oddeven = 1; - $colcount = count($this->columns); - $colbyindex = array_flip($this->columns); - echo ''; + $rowclasses = array('r' . $oddeven); + $oddeven = $oddeven ? 0 : 1; + + if ($classname) { + $rowclasses[] = $classname; + } + + echo ''; // If we have a separator, print it - if($row === NULL && $colcount) { + if ($row === NULL && $colcount) { + $colcount = count($this->columns); echo '
'; - } - else { - foreach($row as $index => $data) { + } else { + $colbyindex = array_flip($this->columns); + foreach ($row as $index => $data) { $column = $colbyindex[$index]; echo 'make_styles_string($this->column_style[$column]).'>'; - if(empty($this->sess->collapse[$column])) { - if($this->column_suppress[$column] && $suppress_lastrow !== NULL && $suppress_lastrow[$index] === $data) { + if (empty($this->sess->collapse[$column])) { + if ($this->column_suppress[$column] && $suppress_lastrow !== NULL && $suppress_lastrow[$index] === $data) { echo ' '; - } - else { + } else { echo $data; } - } - else { + } else { echo ' '; } echo ''; } } + echo ''; - $oddeven = $oddeven ? 0 : 1; + $suppress_enabled = array_sum($this->column_suppress); - if($suppress_enabled) { + if ($suppress_enabled) { $suppress_lastrow = $row; } } -- 2.39.5