* @copyright Copyright (C) 2026 Moko Consulting. All rights reserved. * @license GNU General Public License version 3 or later; see LICENSE * SPDX-License-Identifier: GPL-3.0-or-later */ namespace Joomla\Component\MokoSuiteCross\Administrator\Model; defined('_JEXEC') or die; use Joomla\CMS\MVC\Model\ListModel; class PostsModel extends ListModel { /** * Constructor. * * @param array $config Configuration array */ public function __construct($config = []) { if (empty($config['filter_fields'])) { $config['filter_fields'] = [ 'id', 'a.id', 'article_id', 'a.article_id', 'service_id', 'a.service_id', 'status', 'a.status', 'created', 'a.created', 'posted_at', 'a.posted_at', ]; } parent::__construct($config); } /** * Build an SQL query to load the list data. * * @return \Joomla\Database\QueryInterface */ protected function getListQuery() { $db = $this->getDatabase(); $query = $db->getQuery(true); $query->select('a.*') ->select($db->quoteName('c.title', 'article_title')) ->select($db->quoteName('s.title', 'service_title')) ->select($db->quoteName('s.service_type')) ->from($db->quoteName('#__mokosuitecross_posts', 'a')) ->join('LEFT', $db->quoteName('#__content', 'c') . ' ON ' . $db->quoteName('c.id') . ' = ' . $db->quoteName('a.article_id')) ->join('LEFT', $db->quoteName('#__mokosuitecross_services', 's') . ' ON ' . $db->quoteName('s.id') . ' = ' . $db->quoteName('a.service_id')); // Filter by status $status = $this->getState('filter.status'); if (!empty($status)) { $query->where($db->quoteName('a.status') . ' = ' . $db->quote($status)); } // Filter by service $serviceId = $this->getState('filter.service_id'); if (!empty($serviceId)) { $query->where($db->quoteName('a.service_id') . ' = ' . (int) $serviceId); } // Filter by search (article title or message content) $search = $this->getState('filter.search'); if (!empty($search)) { $search = '%' . $db->escape(trim($search), true) . '%'; $query->where('(' . $db->quoteName('c.title') . ' LIKE ' . $db->quote($search) . ' OR ' . $db->quoteName('a.message') . ' LIKE ' . $db->quote($search) . ')'); } // Ordering $orderCol = $this->state->get('list.ordering', 'a.created'); $orderDirn = $this->state->get('list.direction', 'DESC'); $query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn)); return $query; } }