ADD query of whole database

This commit is contained in:
Thomas Kuschel 2023-10-15 16:17:17 +02:00
parent e39dcaf35c
commit 36cb70eea0
4 changed files with 121 additions and 11 deletions

View File

@ -24,4 +24,6 @@ COM_DEPOT_SELECT_YOUR_OPTION="Select your option"
COM_DEPOT_TAB_NEW_PART="New Component" COM_DEPOT_TAB_NEW_PART="New Component"
COM_DEPOT_TAB_EDIT_PART="Component Details" COM_DEPOT_TAB_EDIT_PART="Component Details"
COM_DEPOT_TAB_STATISTICS="Component Statistics" COM_DEPOT_TAB_STATISTICS="Component Statistics"
COM_DEPOT_TABLE_HEAD_ID="ID"
COM_DEPOT_TABLE_HEAD_NAME="Component Name"
COM_DEPOT_XML_DESCRIPTION="Depot, the component warehouse" COM_DEPOT_XML_DESCRIPTION="Depot, the component warehouse"

View File

@ -0,0 +1,82 @@
<?php
/**
* @package Depot.Administrator
* @subpackage com_depot
* @author Thomas Kuschel <thomas@kuschel.at>
* @copyright (C) 2023 KW4NZ, <https://www.kuschel.at>
* @license GNU General Public License version 2 or later; see LICENSE.md
* @since 0.9.1
*/
namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Table\Table;
\defined('_JEXEC') or die;
class PartsModel extends ListModel
{
/**
* Build an SQL query to load the list data.
*
* @return \Joomla\Database\DatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
{
$db = $this->getDatabase();
$query = $db->getQuery(true);
$query->select('*')
->from($db->quoteName('#__depot', 'd'));
// order by
$query->order('d.id ASC');
if (true) {
return $query;
}
// select the required fields from the table
$query->select(
$this->getState(
'list.select',
[
$db->quoteName('d.id'),
$db->quoteName('d.component_name'),
$db->quoteName('d.alias'),
$db->quoteName('d.description'),
$db->quoteName('d.quantity'),
$db->quoteName('d.quantity_exp'),
$db->quoteName('d.ordering'),
]
)
)
->select(
[
$db->quoteName('u.name', 'creator'),
$db->quoteName('m.short_name', 'manufacturer'),
$db->quoteName('m.long_name', 'manufacturer_long'),
$db->quoteName('s.name', 'stock_name'),
]
)
->from($db->quoteName('#__depot', 'd'))
->join('LEFT', $db->quoteName('#__depot_manufacturer', 'm'), $db->quoteName('m.id') . ' = ' . $db->quoteName('d.manufacturer_id'))
->join('LEFT', $db->quoteName('#__depot_stock', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('d.stock_id'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('d.checked_out'));
// Filter by published state
$published = (string) $this->getState('filter.published');
if (is_numeric($published)) {
$published = (int) $published;
$query->where($db->quoteName('d.state') . ' = :published')
->bind(':published', $published, ParameterType::INTEGER);
} elseif ($published === '') {
$query->where($db->quoteName('d.state') . ' IN (0, 1)');
}
return $query;
}
}

View File

@ -13,11 +13,18 @@ namespace KW4NZ\Component\Depot\Administrator\View\Parts;
defined('_JEXEC') or die; defined('_JEXEC') or die;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Factory;
class HtmlView extends BaseHtmlView class HtmlView extends BaseHtmlView
{ {
public function display($tpl = null) public function display($tpl = null)
{ {
// Get application
$app = Factory::getApplication();
$this->items = $this->get('Items');
parent::display($tpl); parent::display($tpl);
} }
} }

View File

@ -11,3 +11,22 @@
<h2>Welcome to my Depot Component!</h2> <h2>Welcome to my Depot Component!</h2>
<p>Link: <a href="index.php?option=com_depot&view=part&layout=edit&id=1">Part</a></p> <p>Link: <a href="index.php?option=com_depot&view=part&layout=edit&id=1">Part</a></p>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>COM_DEPOT_TABLE_HEAD_ID</th>
<th>COM_DEPOT_TABLE_HEAD_NAME</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr>
<td>
<?= $item->id ?>
<td>
<?= $item->component_name ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>