forked from Public/pics
		
	
		
			
				
	
	
		
			150 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			150 lines
		
	
	
		
			3.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/*****************************************************************************
 | 
						|
 * TabularData.php
 | 
						|
 * Contains the template that displays tabular data.
 | 
						|
 *
 | 
						|
 * Kabuki CMS (C) 2013-2025, Aaron van Geffen
 | 
						|
 *****************************************************************************/
 | 
						|
 | 
						|
class TabularData extends SubTemplate
 | 
						|
{
 | 
						|
	protected GenericTable $_t;
 | 
						|
 | 
						|
	public function __construct(GenericTable $table)
 | 
						|
	{
 | 
						|
		$this->_t = $table;
 | 
						|
	}
 | 
						|
 | 
						|
	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();
 | 
						|
		if (!empty($title))
 | 
						|
		{
 | 
						|
			$titleclass = $this->_t->getTitleClass();
 | 
						|
			echo '
 | 
						|
			<div class="generic-table', !empty($titleclass) ? ' ' . $titleclass : '', '">
 | 
						|
				<h1>', htmlspecialchars($title), '</h1>';
 | 
						|
		}
 | 
						|
	}
 | 
						|
 | 
						|
	protected function renderPaginationForm($pager, $form, $class='row')
 | 
						|
	{
 | 
						|
		echo '
 | 
						|
			<div class="', $class, ' clearfix justify-content-end">';
 | 
						|
 | 
						|
		// Page index?
 | 
						|
		if (!empty($pager))
 | 
						|
			PageIndexWidget::paginate($pager);
 | 
						|
 | 
						|
		// Form controls?
 | 
						|
		if (isset($form))
 | 
						|
			InlineFormView::renderInlineForm($form);
 | 
						|
 | 
						|
		echo '
 | 
						|
			</div>';
 | 
						|
	}
 | 
						|
 | 
						|
	protected function renderTableHead(array $headers)
 | 
						|
	{
 | 
						|
		echo '
 | 
						|
					<thead>
 | 
						|
						<tr>';
 | 
						|
 | 
						|
		foreach ($headers as $th)
 | 
						|
		{
 | 
						|
			echo '
 | 
						|
							<th', (!empty($th['width']) ? ' width="' . $th['width'] . '"' : ''), (!empty($th['class']) ? ' class="' . $th['class'] . '"' : ''), ($th['colspan'] > 1 ? ' colspan="' . $th['colspan'] . '"' : ''), ' scope="', $th['scope'], '">',
 | 
						|
							$th['href'] ? '<a href="' . $th['href'] . '">' . $th['label'] . '</a>' : $th['label'];
 | 
						|
 | 
						|
			if ($th['sort_mode'])
 | 
						|
				echo ' <i class="bi bi-caret-' . ($th['sort_mode'] === 'down' ? 'down' : 'up') . '-fill"></i>';
 | 
						|
 | 
						|
			echo '</th>';
 | 
						|
		}
 | 
						|
 | 
						|
		echo '
 | 
						|
						</tr>
 | 
						|
					</thead>';
 | 
						|
	}
 | 
						|
 | 
						|
	protected function renderTableBody($body)
 | 
						|
	{
 | 
						|
		echo '
 | 
						|
					<tbody>';
 | 
						|
 | 
						|
		if (is_array($body))
 | 
						|
		{
 | 
						|
			foreach ($body as $tr)
 | 
						|
			{
 | 
						|
				echo '
 | 
						|
						<tr', (!empty($tr['class']) ? ' class="' . $tr['class'] . '"' : ''), '>';
 | 
						|
 | 
						|
				foreach ($tr['cells'] as $td)
 | 
						|
				{
 | 
						|
					echo '
 | 
						|
							<td',
 | 
						|
								(!empty($td['class']) ? ' class="' . $td['class'] . '"' : ''),
 | 
						|
								(!empty($td['width']) ? ' width="' . $td['width'] . '"' : ''), '>',
 | 
						|
								$td['value'],
 | 
						|
							'</td>';
 | 
						|
				}
 | 
						|
 | 
						|
				echo '
 | 
						|
						</tr>';
 | 
						|
			}
 | 
						|
		}
 | 
						|
		else
 | 
						|
		{
 | 
						|
			$header = $this->_t->getHeader();
 | 
						|
			echo '
 | 
						|
						<tr>
 | 
						|
							<td colspan="', count($header), '" class="fullwidth">', $body, '</td>
 | 
						|
						</tr>';
 | 
						|
		}
 | 
						|
 | 
						|
		echo '
 | 
						|
					</tbody>';
 | 
						|
	}
 | 
						|
}
 |