Index: lib/tablelib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/tablelib.php,v retrieving revision 1.24.2.3 diff -u -r1.24.2.3 tablelib.php --- lib/tablelib.php 13 Mar 2008 14:02:34 -0000 1.24.2.3 +++ lib/tablelib.php 10 May 2008 04:36:06 -0000 @@ -774,6 +774,27 @@ } $this->data[] = NULL; } + + /** + * Add a row of data to the table. This function takes an array with + * column names as keys. + * It ignores any elements with keys that are not defined as columns. It + * puts in empty strings into the row when there is no element in the passed + * array corresponding to a column in the table. It puts the row elements in + * the proper order. + * @param $rowwithkeys array + * + */ + function add_data_keyed($rowwithkeys){ + foreach (array_keys($this->columns) as $column){ + if (isset($rowwithkeys[$column])){ + $row [] = $rowwithkeys[$column]; + } else { + $row[] =''; + } + } + $this->add_data($row); + } }