89 lines
2.3 KiB
PHP
89 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @package MokoSuiteBackup
|
||
|
|
* @subpackage com_mokosuitebackup
|
||
|
|
* @author Moko Consulting <hello@mokoconsulting.tech>
|
||
|
|
* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved.
|
||
|
|
* @license GNU General Public License version 3 or later; see LICENSE
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace Joomla\Component\MokoSuiteBackup\Administrator\Model;
|
||
|
|
|
||
|
|
defined('_JEXEC') or die;
|
||
|
|
|
||
|
|
use Joomla\CMS\MVC\Model\ListModel;
|
||
|
|
use Joomla\Database\QueryInterface;
|
||
|
|
|
||
|
|
class RemotesModel extends ListModel
|
||
|
|
{
|
||
|
|
public function __construct($config = [])
|
||
|
|
{
|
||
|
|
if (empty($config['filter_fields'])) {
|
||
|
|
$config['filter_fields'] = [
|
||
|
|
'id', 'a.id',
|
||
|
|
'profile_id', 'a.profile_id',
|
||
|
|
'title', 'a.title',
|
||
|
|
'type', 'a.type',
|
||
|
|
'enabled', 'a.enabled',
|
||
|
|
'ordering', 'a.ordering',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
parent::__construct($config);
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function getListQuery(): QueryInterface
|
||
|
|
{
|
||
|
|
$db = $this->getDatabase();
|
||
|
|
$query = $db->getQuery(true);
|
||
|
|
|
||
|
|
$query->select('a.*')
|
||
|
|
->from($db->quoteName('#__mokosuitebackup_remotes', 'a'));
|
||
|
|
|
||
|
|
// Join profile title
|
||
|
|
$query->select($db->quoteName('p.title', 'profile_title'))
|
||
|
|
->join('LEFT', $db->quoteName('#__mokosuitebackup_profiles', 'p') . ' ON p.id = a.profile_id');
|
||
|
|
|
||
|
|
// Filter by profile
|
||
|
|
$profileId = $this->getState('filter.profile_id');
|
||
|
|
|
||
|
|
if (is_numeric($profileId)) {
|
||
|
|
$query->where($db->quoteName('a.profile_id') . ' = ' . (int) $profileId);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Filter by type
|
||
|
|
$type = $this->getState('filter.type');
|
||
|
|
|
||
|
|
if (!empty($type)) {
|
||
|
|
$query->where($db->quoteName('a.type') . ' = ' . $db->quote($type));
|
||
|
|
}
|
||
|
|
|
||
|
|
// Filter by enabled
|
||
|
|
$enabled = $this->getState('filter.enabled');
|
||
|
|
|
||
|
|
if (is_numeric($enabled)) {
|
||
|
|
$query->where($db->quoteName('a.enabled') . ' = ' . (int) $enabled);
|
||
|
|
}
|
||
|
|
|
||
|
|
// Filter by search
|
||
|
|
$search = $this->getState('filter.search');
|
||
|
|
|
||
|
|
if (!empty($search)) {
|
||
|
|
$search = $db->quote('%' . $db->escape(trim($search), true) . '%');
|
||
|
|
$query->where('(' . $db->quoteName('a.title') . ' LIKE ' . $search . ')');
|
||
|
|
}
|
||
|
|
|
||
|
|
$orderCol = $this->state->get('list.ordering', 'a.ordering');
|
||
|
|
$orderDir = $this->state->get('list.direction', 'ASC');
|
||
|
|
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDir));
|
||
|
|
|
||
|
|
return $query;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected function populateState($ordering = 'a.ordering', $direction = 'ASC'): void
|
||
|
|
{
|
||
|
|
parent::populateState($ordering, $direction);
|
||
|
|
}
|
||
|
|
}
|