From 925c2e0863cbe8161aaa9a6a38683ca166f5984c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 8 Dec 2017 15:36:30 -0200 Subject: [PATCH] Use template for getHtmlForColumns method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- libraries/classes/Tracking.php | 30 +--------- .../tracking/structure_snapshot_columns.twig | 56 +++++++++++++++++++ .../tracking/structure_snapshot_field.twig | 35 ------------ 3 files changed, 59 insertions(+), 62 deletions(-) create mode 100644 templates/table/tracking/structure_snapshot_columns.twig delete mode 100644 templates/table/tracking/structure_snapshot_field.twig diff --git a/libraries/classes/Tracking.php b/libraries/classes/Tracking.php index c40e9e0e31..dd73cc80f4 100644 --- a/libraries/classes/Tracking.php +++ b/libraries/classes/Tracking.php @@ -863,33 +863,9 @@ class Tracking */ public static function getHtmlForColumns(array $columns) { - $html = '

' . __('Structure') . '

'; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - $index = 1; - foreach ($columns as $field) { - $html .= Template::get('table/tracking/structure_snapshot_field')->render([ - 'index' => $index++, - 'field' => $field, - ]);; - } - - $html .= ''; - $html .= '
' . __('#') . '' . __('Column') . '' . __('Type') . '' . __('Collation') . '' . __('Null') . '' . __('Default') . '' . __('Extra') . '' . __('Comment') . '
'; - - return $html; + return Template::get('table/tracking/structure_snapshot_columns')->render([ + 'columns' => $columns, + ]); } /** diff --git a/templates/table/tracking/structure_snapshot_columns.twig b/templates/table/tracking/structure_snapshot_columns.twig new file mode 100644 index 0000000000..c98dfbe341 --- /dev/null +++ b/templates/table/tracking/structure_snapshot_columns.twig @@ -0,0 +1,56 @@ +

{% trans 'Structure' %}

+ + + + + + + + + + + + + + + {% set index = 1 %} + {% for field in columns %} + + + {% set index = index + 1 %} + + + + + + + + + {% endfor %} + +
{% trans %}#{% context %}Number{% endtrans %}{% trans 'Column' %}{% trans 'Type' %}{% trans 'Collation' %}{% trans 'Null' %}{% trans 'Default' %}{% trans 'Extra' %}{% trans 'Comment' %}
{{ index }} + + {{ field['Field'] }} + {% if field['Key'] == 'PRI' %} + {{ Util_getImage('b_primary', 'Primary'|trans) }} + {% elseif field['Key'] is not empty %} + {{ Util_getImage('bd_primary', 'Index'|trans) }} + {% endif %} + + {{ field['Type'] }}{{ field['Collation'] }}{{ field['Null'] == 'YES' ? 'Yes'|trans : 'No'|trans }} + {% if field['Default'] is defined %} + {% set extracted_columnspec = Util_extractColumnSpec(field['Type']) %} + {% if extracted_columnspec['type'] == 'bit' %} + {# here, $field['Default'] contains something like b'010' #} + {{ Util_convertBitDefaultValue(field['Default']) }} + {% else %} + {{ field['Default'] }} + {% endif %} + {% else %} + {% if field['Null'] == 'YES' %} + NULL + {% else %} + {% trans %}None{% context %}None for default{% endtrans %} + {% endif %} + {% endif %} + {{ field['Extra'] }}{{ field['Comment'] }}
diff --git a/templates/table/tracking/structure_snapshot_field.twig b/templates/table/tracking/structure_snapshot_field.twig deleted file mode 100644 index 1e00edbbac..0000000000 --- a/templates/table/tracking/structure_snapshot_field.twig +++ /dev/null @@ -1,35 +0,0 @@ - - {{ index }} - - - {{ field['Field'] }} - {% if field['Key'] == 'PRI' %} - {{ Util_getImage('b_primary', 'Primary'|trans) }} - {% elseif field['Key'] is not empty %} - {{ Util_getImage('bd_primary', 'Index'|trans) }} - {% endif %} - - - {{ field['Type'] }} - {{ field['Collation'] }} - {{ field['Null'] == 'YES' ? 'Yes'|trans : 'No'|trans }} - - {% if field['Default'] is defined %} - {% set extracted_columnspec = Util_extractColumnSpec(field['Type']) %} - {% if extracted_columnspec['type'] == 'bit' %} - {# here, $field['Default'] contains something like b'010' #} - {{ Util_convertBitDefaultValue(field['Default']) }} - {% else %} - {{ field['Default'] }} - {% endif %} - {% else %} - {% if field['Null'] == 'YES' %} - NULL - {% else %} - {% trans %}None{% context %}None for default{% endtrans %} - {% endif %} - {% endif %} - - {{ field['Extra'] }} - {{ field['Comment'] }} -