示例#1
0
/**
 * return html for Space Usage And Row Statistic
 *
 * @param array  $showtable       showing table information
 * @param string $db              database
 * @param string $table           table
 * @param int    $cell_align_left cell align left
 *
 * @return string
 */
function PMA_getHtmlForSpaceUsageAndRowStatistics($showtable, $db, $table, $cell_align_left)
{
    $html = '';
    $nonisam = false;
    if (isset($showtable['Type']) && !preg_match('@ISAM|HEAP@i', $showtable['Type'])) {
        $nonisam = true;
    }
    if ($nonisam == false) {
        // Gets some sizes
        $mergetable = PMA_Table::isMerge($db, $table);
        list($data_size, $data_unit) = PMA_Util::formatByteDown($showtable['Data_length']);
        if ($mergetable == false) {
            list($index_size, $index_unit) = PMA_Util::formatByteDown($showtable['Index_length']);
        }
        if (isset($showtable['Data_free']) && $showtable['Data_free'] > 0) {
            list($free_size, $free_unit) = PMA_Util::formatByteDown($showtable['Data_free']);
            list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length'] - $showtable['Data_free']);
        } else {
            unset($free_size);
            unset($free_unit);
            list($effect_size, $effect_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
        }
        list($tot_size, $tot_unit) = PMA_Util::formatByteDown($showtable['Data_length'] + $showtable['Index_length']);
        $num_rows = isset($showtable['Rows']) ? $showtable['Rows'] : 0;
        if ($num_rows > 0) {
            list($avg_size, $avg_unit) = PMA_Util::formatByteDown(($showtable['Data_length'] + $showtable['Index_length']) / $showtable['Rows'], 6, 1);
        }
        // Displays them
        $html .= '<br /><br />';
        $html .= PMA_getHtmlForSpaceUsage($data_size, $data_unit, isset($index_size) ? $index_size : null, isset($index_unit) ? $index_unit : null, isset($free_size) ? $free_size : null, isset($free_unit) ? $free_unit : null, isset($effect_size) ? $effect_size : null, isset($effect_unit) ? $effect_unit : null, isset($tot_size) ? $tot_size : null, isset($tot_unit) ? $tot_unit : null, $mergetable);
        $html .= '</td>';
        $html .= PMA_getHtmlForRowStatistics($showtable, $cell_align_left, isset($avg_size) ? $avg_size : 0, isset($avg_unit) ? $avg_unit : 0, $mergetable);
        $html .= "\n";
        $html .= '</table>';
        $html .= '</td>';
        $html .= '</tr>';
        $html .= '</table>';
    }
    // end if ($nonisam == false)
    return $html;
}
 /**
  * Tests for PMA_getHtmlForSpaceUsage() method.
  *
  * @return void
  * @test
  */
 public function testPMAGetHtmlForSpaceUsage()
 {
     $data_size = '10';
     $data_unit = '11';
     $index_size = '12';
     $index_unit = '13';
     $free_size = '14';
     $free_unit = '15';
     $effect_size = '16';
     $effect_unit = '17';
     $tot_size = '18';
     $tot_unit = '19';
     $mergetable = false;
     $html = PMA_getHtmlForSpaceUsage($data_size, $data_unit, $index_size, $index_unit, $free_size, $free_unit, $effect_size, $effect_unit, $tot_size, $tot_unit, $mergetable);
     //validation 1 : title
     $this->assertContains(__('Space usage:'), $html);
     //validation 2 : $data_size & $data_unit
     $this->assertContains($data_size, $html);
     $this->assertContains($data_unit, $html);
     //validation 3 : $index_size & $index_unit
     $this->assertContains($index_size, $html);
     $this->assertContains($index_unit, $html);
     //validation 4 : Overhead
     $this->assertContains(__('Overhead'), $html);
     $this->assertContains($free_size, $html);
     $this->assertContains($free_unit, $html);
     //validation 5 : Effective
     $this->assertContains(__('Effective'), $html);
     $this->assertContains($effect_size, $html);
     $this->assertContains($effect_unit, $html);
     //validation 6 : $tot_size & $tot_unit
     $this->assertContains($tot_size, $html);
     $this->assertContains($tot_unit, $html);
 }