Permalink
Browse files

Fix duplicate code

  • Loading branch information...
1 parent b78899a commit 35c725515b049d816497a3491c108792ffb2b22e @lem9 lem9 committed Apr 29, 2012
Showing with 53 additions and 64 deletions.
  1. +53 −64 libraries/export/odt.php
View
@@ -269,41 +269,11 @@ function PMA_getTableDefStandIn($db, $view, $crlf)
. '</table:table-cell>';
$GLOBALS['odt_buffer'] .= '</table:table-row>';
- $columns = PMA_DBI_get_columns($db, $table);
+ $columns = PMA_DBI_get_columns($db, $view);
foreach ($columns as $column) {
- $field_name = $column['Field'];
- $GLOBALS['odt_buffer'] .= '<table:table-row>';
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . htmlspecialchars($field_name) . '</text:p>'
- . '</table:table-cell>';
-
- $extracted_columnspec = PMA_extractColumnSpec($column['Type']);
- $type = htmlspecialchars($extracted_columnspec['print_type']);
- if (empty($type)) {
- $type = '&nbsp;';
- }
-
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . htmlspecialchars($type) . '</text:p>'
- . '</table:table-cell>';
- if (!isset($column['Default'])) {
- if ($column['Null'] != 'NO') {
- $column['Default'] = 'NULL';
- } else {
- $column['Default'] = '';
- }
- } else {
- $column['Default'] = $column['Default'];
- }
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . '</text:p>'
- . '</table:table-cell>';
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>'
- . '</table:table-cell>';
-
+ $GLOBALS['odt_buffer'] .= PMA_formatOneColumnDefinition($column);
$GLOBALS['odt_buffer'] .= '</table:table-row>';
- } // end while
+ } // end foreach
$GLOBALS['odt_buffer'] .= '</table:table>';
return true;
@@ -416,36 +386,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comme
$columns = PMA_DBI_get_columns($db, $table);
foreach ($columns as $column) {
- $field_name = $column['Field'];
- $GLOBALS['odt_buffer'] .= '<table:table-row>';
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . htmlspecialchars($field_name) . '</text:p>'
- . '</table:table-cell>';
-
- $extracted_columnspec = PMA_extractColumnSpec($column['Type']);
- $type = htmlspecialchars($extracted_columnspec['print_type']);
- if (empty($type)) {
- $type = '&nbsp;';
- }
-
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . htmlspecialchars($type) . '</text:p>'
- . '</table:table-cell>';
- if (!isset($column['Default'])) {
- if ($column['Null'] != 'NO') {
- $column['Default'] = 'NULL';
- } else {
- $column['Default'] = '';
- }
- } else {
- $column['Default'] = $column['Default'];
- }
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . (($column['Null'] == '' || $column['Null'] == 'NO') ? __('No') : __('Yes')) . '</text:p>'
- . '</table:table-cell>';
- $GLOBALS['odt_buffer'] .= '<table:table-cell office:value-type="string">'
- . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>'
- . '</table:table-cell>';
+ $GLOBALS['odt_buffer'] .= PMA_formatOneColumnDefinition($column);
if ($do_relation && $have_rel) {
if (isset($res_rel[$field_name])) {
@@ -477,7 +418,7 @@ function PMA_getTableDef($db, $table, $crlf, $error_url, $do_relation, $do_comme
}
}
$GLOBALS['odt_buffer'] .= '</table:table-row>';
- } // end while
+ } // end foreach
$GLOBALS['odt_buffer'] .= '</table:table>';
return true;
@@ -587,5 +528,53 @@ function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = fals
return PMA_exportOutputHandler($dump);
} // end of the 'PMA_exportStructure' function
+ /**
+ * Formats the definition for one column
+ *
+ * @param array $column info about this column
+ *
+ * @return string Formatted column definition
+ *
+ * @access public
+ */
+ function PMA_formatOneColumnDefinition(
+ $column
+ ) {
+ $field_name = $column['Field'];
+ $definition = '<table:table-row>';
+ $definition .= '<table:table-cell office:value-type="string">'
+ . '<text:p>' . htmlspecialchars($field_name) . '</text:p>'
+ . '</table:table-cell>';
+
+ $extracted_columnspec = PMA_extractColumnSpec($column['Type']);
+ $type = htmlspecialchars($extracted_columnspec['print_type']);
+ if (empty($type)) {
+ $type = '&nbsp;';
+ }
+
+ $definition .= '<table:table-cell office:value-type="string">'
+ . '<text:p>' . htmlspecialchars($type) . '</text:p>'
+ . '</table:table-cell>';
+ if (! isset($column['Default'])) {
+ if ($column['Null'] != 'NO') {
+ $column['Default'] = 'NULL';
+ } else {
+ $column['Default'] = '';
+ }
+ } else {
+ $column['Default'] = $column['Default'];
+ }
+ $definition .= '<table:table-cell office:value-type="string">'
+ . '<text:p>'
+ . (($column['Null'] == '' || $column['Null'] == 'NO')
+ ? __('No')
+ : __('Yes'))
+ . '</text:p>'
+ . '</table:table-cell>';
+ $definition .= '<table:table-cell office:value-type="string">'
+ . '<text:p>' . htmlspecialchars($column['Default']) . '</text:p>'
+ . '</table:table-cell>';
+ return $definition;
+ }
} // end else
?>

0 comments on commit 35c7255

Please sign in to comment.