forked from Public/pics
TabularData: split up into logical methods
This commit is contained in:
parent
d6f39a3410
commit
01954d4a7d
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
class TabularData extends SubTemplate
|
class TabularData extends SubTemplate
|
||||||
{
|
{
|
||||||
private GenericTable $_t;
|
protected GenericTable $_t;
|
||||||
|
|
||||||
public function __construct(GenericTable $table)
|
public function __construct(GenericTable $table)
|
||||||
{
|
{
|
||||||
@ -16,6 +16,47 @@ class TabularData extends SubTemplate
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function html_content()
|
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 '
|
||||||
|
<div class="', $tableClass, '">';
|
||||||
|
|
||||||
|
// Build the table!
|
||||||
|
echo '
|
||||||
|
<table class="table table-striped table-condensed">';
|
||||||
|
|
||||||
|
$this->renderTableHead($this->_t->getHeader());
|
||||||
|
$this->renderTableBody($this->_t->getBody());
|
||||||
|
|
||||||
|
echo '
|
||||||
|
</table>';
|
||||||
|
|
||||||
|
if ($tableClass)
|
||||||
|
echo '
|
||||||
|
</div>';
|
||||||
|
|
||||||
|
// 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 '
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderTitle()
|
||||||
{
|
{
|
||||||
$title = $this->_t->getTitle();
|
$title = $this->_t->getTitle();
|
||||||
if (!empty($title))
|
if (!empty($title))
|
||||||
@ -25,43 +66,32 @@ class TabularData extends SubTemplate
|
|||||||
<div class="generic-table', !empty($titleclass) ? ' ' . $titleclass : '', '">
|
<div class="generic-table', !empty($titleclass) ? ' ' . $titleclass : '', '">
|
||||||
<h1>', htmlspecialchars($title), '</h1>';
|
<h1>', htmlspecialchars($title), '</h1>';
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($this->_subtemplates as $template)
|
protected function renderPaginationForm($pager, $form, $class='row')
|
||||||
$template->html_main();
|
|
||||||
|
|
||||||
// Showing an inline form?
|
|
||||||
$pager = $this->_t->getPageIndex();
|
|
||||||
if (!empty($pager) || isset($this->_t->form_above))
|
|
||||||
{
|
{
|
||||||
echo '
|
echo '
|
||||||
<div class="row clearfix justify-content-end">';
|
<div class="', $class, ' clearfix justify-content-end">';
|
||||||
|
|
||||||
// Page index?
|
// Page index?
|
||||||
if (!empty($pager))
|
if (!empty($pager))
|
||||||
PageIndexWidget::paginate($pager);
|
PageIndexWidget::paginate($pager);
|
||||||
|
|
||||||
// Form controls?
|
// Form controls?
|
||||||
if (isset($this->_t->form_above))
|
if (isset($form))
|
||||||
$this->showForm($this->_t->form_above);
|
$this->renderInlineForm($form);
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
</div>';
|
</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
$tableClass = $this->_t->getTableClass();
|
protected function renderTableHead(array $headers)
|
||||||
if ($tableClass)
|
{
|
||||||
echo '
|
echo '
|
||||||
<div class="', $tableClass, '">';
|
|
||||||
|
|
||||||
// Build the table!
|
|
||||||
echo '
|
|
||||||
<table class="table table-striped table-condensed">
|
|
||||||
<thead>
|
<thead>
|
||||||
<tr>';
|
<tr>';
|
||||||
|
|
||||||
// Show all headers in their full glory!
|
foreach ($headers as $th)
|
||||||
$header = $this->_t->getHeader();
|
|
||||||
foreach ($header as $th)
|
|
||||||
{
|
{
|
||||||
echo '
|
echo '
|
||||||
<th', (!empty($th['width']) ? ' width="' . $th['width'] . '"' : ''), (!empty($th['class']) ? ' class="' . $th['class'] . '"' : ''), ($th['colspan'] > 1 ? ' colspan="' . $th['colspan'] . '"' : ''), ' scope="', $th['scope'], '">',
|
<th', (!empty($th['width']) ? ' width="' . $th['width'] . '"' : ''), (!empty($th['class']) ? ' class="' . $th['class'] . '"' : ''), ($th['colspan'] > 1 ? ' colspan="' . $th['colspan'] . '"' : ''), ' scope="', $th['scope'], '">',
|
||||||
@ -75,11 +105,14 @@ class TabularData extends SubTemplate
|
|||||||
|
|
||||||
echo '
|
echo '
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderTableBody($body)
|
||||||
|
{
|
||||||
|
echo '
|
||||||
<tbody>';
|
<tbody>';
|
||||||
|
|
||||||
// The body is what we came to see!
|
|
||||||
$body = $this->_t->getBody();
|
|
||||||
if (is_array($body))
|
if (is_array($body))
|
||||||
{
|
{
|
||||||
foreach ($body as $tr)
|
foreach ($body as $tr)
|
||||||
@ -90,59 +123,31 @@ class TabularData extends SubTemplate
|
|||||||
foreach ($tr['cells'] as $td)
|
foreach ($tr['cells'] as $td)
|
||||||
{
|
{
|
||||||
echo '
|
echo '
|
||||||
<td', (!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>';
|
<td',
|
||||||
|
(!empty($td['class']) ? ' class="' . $td['class'] . '"' : ''),
|
||||||
if (!empty($td['class']))
|
(!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>',
|
||||||
echo '<span class="', $td['class'], '">', $td['value'], '</span>';
|
$td['value'],
|
||||||
else
|
'</td>';
|
||||||
echo $td['value'];
|
|
||||||
|
|
||||||
echo '</td>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
</tr>';
|
</tr>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// !!! Sum colspan!
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
$header = $this->_t->getHeader();
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="', count($header), '" class="fullwidth">', $body, '</td>
|
<td colspan="', count($header), '" class="fullwidth">', $body, '</td>
|
||||||
</tr>';
|
</tr>';
|
||||||
|
|
||||||
echo '
|
|
||||||
</tbody>
|
|
||||||
</table>';
|
|
||||||
|
|
||||||
if ($tableClass)
|
|
||||||
echo '
|
|
||||||
</div>';
|
|
||||||
|
|
||||||
// Showing an inline form?
|
|
||||||
if (!empty($pager) || isset($this->_t->form_below))
|
|
||||||
{
|
|
||||||
echo '
|
|
||||||
<div class="row clearfix justify-content-end">';
|
|
||||||
|
|
||||||
// Page index?
|
|
||||||
if (!empty($pager))
|
|
||||||
PageIndexWidget::paginate($pager);
|
|
||||||
|
|
||||||
// Form controls?
|
|
||||||
if (isset($this->_t->form_below))
|
|
||||||
$this->showForm($this->_t->form_below);
|
|
||||||
|
|
||||||
echo '
|
|
||||||
</div>';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($title))
|
|
||||||
echo '
|
echo '
|
||||||
</div>';
|
</tbody>';
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function showForm($form)
|
protected function renderInlineForm($form)
|
||||||
{
|
{
|
||||||
if (!isset($form['is_embed']))
|
if (!isset($form['is_embed']))
|
||||||
echo '
|
echo '
|
||||||
|
Loading…
Reference in New Issue
Block a user