From 01954d4a7d1630ad2ee00765f1d3f3bc96af1d90 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Tue, 27 Aug 2024 11:55:22 +0200 Subject: [PATCH] TabularData: split up into logical methods --- templates/TabularData.php | 153 ++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 74 deletions(-) diff --git a/templates/TabularData.php b/templates/TabularData.php index e1f5f6c0..b6df151a 100644 --- a/templates/TabularData.php +++ b/templates/TabularData.php @@ -8,7 +8,7 @@ class TabularData extends SubTemplate { - private GenericTable $_t; + protected GenericTable $_t; public function __construct(GenericTable $table) { @@ -16,6 +16,47 @@ class TabularData extends SubTemplate } protected function html_content() + { + $this->renderTitle(); + + foreach ($this->_subtemplates as $template) + $template->html_main(); + + // Showing an inline form? + $pager = $this->_t->getPageIndex(); + if (!empty($pager) || isset($this->_t->form_above)) + $this->renderPaginationForm($pager, $this->_t->form_above); + + $tableClass = $this->_t->getTableClass(); + if ($tableClass) + echo ' +
'; + + // Build the table! + echo ' + '; + + $this->renderTableHead($this->_t->getHeader()); + $this->renderTableBody($this->_t->getBody()); + + echo ' +
'; + + if ($tableClass) + echo ' +
'; + + // Showing an inline form? + if (!empty($pager) || isset($this->_t->form_below)) + $this->renderPaginationForm($pager, $this->_t->form_below); + + $title = $this->_t->getTitle(); + if (!empty($title)) + echo ' + '; + } + + protected function renderTitle() { $title = $this->_t->getTitle(); if (!empty($title)) @@ -25,43 +66,32 @@ class TabularData extends SubTemplate

', htmlspecialchars($title), '

'; } + } - foreach ($this->_subtemplates as $template) - $template->html_main(); - - // Showing an inline form? - $pager = $this->_t->getPageIndex(); - if (!empty($pager) || isset($this->_t->form_above)) - { - echo ' -
'; - - // Page index? - if (!empty($pager)) - PageIndexWidget::paginate($pager); - - // Form controls? - if (isset($this->_t->form_above)) - $this->showForm($this->_t->form_above); - - echo ' -
'; - } - - $tableClass = $this->_t->getTableClass(); - if ($tableClass) - echo ' -
'; - - // Build the table! + protected function renderPaginationForm($pager, $form, $class='row') + { + echo ' +
'; + + // Page index? + if (!empty($pager)) + PageIndexWidget::paginate($pager); + + // Form controls? + if (isset($form)) + $this->renderInlineForm($form); + + echo ' +
'; + } + + protected function renderTableHead(array $headers) + { echo ' - '; - // Show all headers in their full glory! - $header = $this->_t->getHeader(); - foreach ($header as $th) + foreach ($headers as $th) { echo ' 1 ? ' colspan="' . $th['colspan'] . '"' : ''), ' scope="', $th['scope'], '">', @@ -75,11 +105,14 @@ class TabularData extends SubTemplate echo ' - + '; + } + + protected function renderTableBody($body) + { + echo ' '; - // The body is what we came to see! - $body = $this->_t->getBody(); if (is_array($body)) { foreach ($body as $tr) @@ -90,59 +123,31 @@ class TabularData extends SubTemplate foreach ($tr['cells'] as $td) { echo ' - '; - - if (!empty($td['class'])) - echo '', $td['value'], ''; - else - echo $td['value']; - - echo ''; + ', + $td['value'], + ''; } echo ' '; } } - // !!! Sum colspan! else + { + $header = $this->_t->getHeader(); echo ' '; - - echo ' - -
', $body, '
'; - - if ($tableClass) - echo ' -
'; - - // Showing an inline form? - if (!empty($pager) || isset($this->_t->form_below)) - { - echo ' -
'; - - // Page index? - if (!empty($pager)) - PageIndexWidget::paginate($pager); - - // Form controls? - if (isset($this->_t->form_below)) - $this->showForm($this->_t->form_below); - - echo ' -
'; } - if (!empty($title)) - echo ' -
'; + echo ' + '; } - protected function showForm($form) + protected function renderInlineForm($form) { if (!isset($form['is_embed'])) echo '