30 lines
1.3 KiB
PHP
30 lines
1.3 KiB
PHP
<?php
|
|
namespace Moko\Component\MokoSuiteField\Administrator\Model;
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
|
|
|
class EquipmentModel extends BaseDatabaseModel
|
|
{
|
|
public function getItems(string $type = '', string $status = '', int $locationId = 0, string $search = '', int $limit = 50): array
|
|
{
|
|
$db = $this->getDatabase();
|
|
$query = $db->getQuery(true)
|
|
->select('eq.*, loc.name AS location_name, loc.address, cd.name AS customer_name')
|
|
->from($db->quoteName('#__mokosuitefield_equipment', 'eq'))
|
|
->join('LEFT', $db->quoteName('#__mokosuitefield_locations', 'loc') . ' ON loc.id = eq.location_id')
|
|
->join('LEFT', $db->quoteName('#__contact_details', 'cd') . ' ON cd.id = eq.contact_id')
|
|
->order('eq.name ASC');
|
|
|
|
if ($type) $query->where($db->quoteName('eq.type') . ' = ' . $db->quote($type));
|
|
if ($status) $query->where($db->quoteName('eq.status') . ' = ' . $db->quote($status));
|
|
if ($locationId) $query->where('eq.location_id = ' . $locationId);
|
|
if ($search) $query->where('(' . $db->quoteName('eq.name') . ' LIKE ' . $db->quote('%' . $search . '%')
|
|
. ' OR ' . $db->quoteName('eq.serial_number') . ' LIKE ' . $db->quote('%' . $search . '%') . ')');
|
|
|
|
$db->setQuery($query, 0, $limit);
|
|
return $db->loadObjectList() ?: [];
|
|
}
|
|
}
|