Login

Drupal7 Generate Report

We are using the Drupal7 implementation of theme_table to render our report. As of version alpha 6, theme_table() requires you to include at least 2 data rows (note! may be a bug).

In the example below, we check to see if we have any records to report.

If we don't have any records to report, we notify the user there is no records, create a default display.

If we do have records to display, we add the array elements to our $vars array structure.

Note! Drupal7's theme_table() also requires all of the elements such as "caption" included in the example below. In Drupal6, most of these elements were optional.

function _get_color_vote() {
 
    $header = array("Color Name","Vote Count");
    $vars = array();
    $vars['attributes'] = array('style'=>'width:25%;border: solid black 2px;','cellpadding'=>3,'cellspacing' =>3);
    $vars['caption'] = 'Color Election';
    $vars['header']=$header;
    $vars['colgroups'] = NULL;
    $vars['sticky'] = NULL;
    $vars['empty'] = NULL;
 
    $rows['data'] = array();
    $db = new dbMy_color();
    try
    {
        $data_rows = $db->getCountByColor();
        $table_rows = array_merge($rows, $data_rows);
        $vars['rows']=$table_rows;
 
    } catch(Exception $e) {
        $data = array('No Data','No Data');
        $data[0] = array('red','0');
        $data[1] = array('white','0');
        $data[2] = array('blue','0');
 
        $table_rows = array_merge($rows,$data);
        $vars['rows']=$table_rows;
    }
    return $vars;