* @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 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.*') ->from($db->quoteName('#__mokosuitebackup_profiles', 'a')); // 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')); $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); } }