get(DatabaseInterface::class); $query = $db->getQuery(true) ->select([ $db->quoteName('c.id'), $db->quoteName('c.alias'), $db->quoteName('c.name'), $db->quoteName('c.description'), $db->quoteName('c.category'), $db->quoteName('c.color'), $db->quoteName('c.match_all'), $db->quoteName('c.published'), ]) ->from($db->quoteName('#__mokosuiteclient_conditions', 'c')); if (!empty($filters['search'])) { $search = $db->quote('%' . $db->escape($filters['search'], true) . '%'); $query->where('(' . $db->quoteName('c.name') . ' LIKE ' . $search . ' OR ' . $db->quoteName('c.alias') . ' LIKE ' . $search . ')'); } if ($filters['published'] !== '' && $filters['published'] !== null) { $query->where($db->quoteName('c.published') . ' = ' . (int) $filters['published']); } $query->order($db->quoteName('c.name') . ' ASC'); $db->setQuery($query, $offset, $limit); return $db->loadObjectList() ?: []; } public function getTotal(array $filters = []): int { $db = Factory::getContainer()->get(DatabaseInterface::class); $query = $db->getQuery(true) ->select('COUNT(*)') ->from($db->quoteName('#__mokosuiteclient_conditions', 'c')); if (!empty($filters['search'])) { $search = $db->quote('%' . $db->escape($filters['search'], true) . '%'); $query->where('(' . $db->quoteName('c.name') . ' LIKE ' . $search . ' OR ' . $db->quoteName('c.alias') . ' LIKE ' . $search . ')'); } if ($filters['published'] !== '' && $filters['published'] !== null) { $query->where($db->quoteName('c.published') . ' = ' . (int) $filters['published']); } $db->setQuery($query); return (int) $db->loadResult(); } public function getGroupCount(int $conditionId): int { $db = Factory::getContainer()->get(DatabaseInterface::class); $db->setQuery( $db->getQuery(true) ->select('COUNT(*)') ->from($db->quoteName('#__mokosuiteclient_conditions_groups')) ->where($db->quoteName('condition_id') . ' = ' . $conditionId) ); return (int) $db->loadResult(); } public function getRuleCount(int $conditionId): int { $db = Factory::getContainer()->get(DatabaseInterface::class); $db->setQuery( $db->getQuery(true) ->select('COUNT(*)') ->from($db->quoteName('#__mokosuiteclient_conditions_rules', 'r')) ->join('INNER', $db->quoteName('#__mokosuiteclient_conditions_groups', 'g') . ' ON ' . $db->quoteName('g.id') . ' = ' . $db->quoteName('r.group_id')) ->where($db->quoteName('g.condition_id') . ' = ' . $conditionId) ); return (int) $db->loadResult(); } }