2026-06-02 13:47:36 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2026-06-11 12:24:27 -05:00
|
|
|
* @package MokoSuiteBackup
|
|
|
|
|
* @subpackage com_mokosuitebackup
|
2026-06-02 13:47:36 -05:00
|
|
|
* @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
|
|
|
|
|
*/
|
|
|
|
|
|
2026-06-11 12:24:27 -05:00
|
|
|
namespace Joomla\Component\MokoSuiteBackup\Administrator\Model;
|
2026-06-02 13:47:36 -05:00
|
|
|
|
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
|
|
|
|
|
|
use Joomla\CMS\MVC\Model\ListModel;
|
|
|
|
|
use Joomla\Database\QueryInterface;
|
|
|
|
|
|
|
|
|
|
class ProfilesModel extends ListModel
|
|
|
|
|
{
|
|
|
|
|
public function __construct($config = [])
|
|
|
|
|
{
|
|
|
|
|
if (empty($config['filter_fields'])) {
|
|
|
|
|
$config['filter_fields'] = [
|
|
|
|
|
'id', 'a.id',
|
|
|
|
|
'title', 'a.title',
|
|
|
|
|
'backup_type', 'a.backup_type',
|
|
|
|
|
'published', 'a.published',
|
|
|
|
|
'ordering', 'a.ordering',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::__construct($config);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getListQuery(): QueryInterface
|
|
|
|
|
{
|
|
|
|
|
$db = $this->getDatabase();
|
|
|
|
|
$query = $db->getQuery(true);
|
|
|
|
|
|
|
|
|
|
$query->select('a.*')
|
2026-06-11 12:24:27 -05:00
|
|
|
->from($db->quoteName('#__mokosuitebackup_profiles', 'a'));
|
2026-06-02 13:47:36 -05:00
|
|
|
|
2026-06-23 11:03:13 -05:00
|
|
|
// Subquery: count of backup records per profile
|
|
|
|
|
$subQuery = $db->getQuery(true)
|
|
|
|
|
->select('COUNT(*)')
|
|
|
|
|
->from($db->quoteName('#__mokosuitebackup_records', 'r'))
|
|
|
|
|
->where($db->quoteName('r.profile_id') . ' = ' . $db->quoteName('a.id'));
|
|
|
|
|
$query->select('(' . $subQuery . ') AS ' . $db->quoteName('backup_count'));
|
|
|
|
|
|
2026-06-02 13:47:36 -05:00
|
|
|
$published = $this->getState('filter.published');
|
|
|
|
|
|
|
|
|
|
if (is_numeric($published)) {
|
|
|
|
|
$query->where($db->quoteName('a.published') . ' = ' . (int) $published);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
}
|