|null $params * @return array */ public static function getEntrySearchConditions(?array $params = null): array { $conditions = [ 'e.id LIKE %s', 'e.formId LIKE %s', 'f.name LIKE %s', ]; // Only include fieldValue if searchFieldValue is true (default true for BC) if (!isset($params['searchFieldValue']) || $params['searchFieldValue']) { $conditions[] = 'eft.fieldValue LIKE %s'; } return $conditions; } /** * Get entry fields SQL and params for the given entries. * * @param array> $entries * @return array{sql: string, params: array} * @throws InvalidArgumentException */ public static function getEntryFieldsQuery(array $entries): array { if (empty($entries)) { return ['sql' => '', 'params' => []]; } $entryIds = array_column($entries, 'id'); $placeholders = implode(',', array_fill(0, count($entryIds), '%d')); $entryFieldsTable = EntryFieldsTable::getTableName(); $sql = "SELECT * FROM {$entryFieldsTable} WHERE entryId IN ($placeholders)"; return ['sql' => $sql, 'params' => $entryIds]; } /** * Get the count of entries for a specific form (SQL and params). * * @param string $table * @param int $formId * @return array{sql: string, params: array} */ public static function getCountByFormIdQuery(string $table, int $formId): array { $sql = "SELECT COUNT(*) FROM {$table} WHERE formId = %d"; return ['sql' => $sql, 'params' => [$formId]]; } /** * Get the count of entries for the filter dropdown (SQL and params). * * @param string $table * @param array|null $params * @return array{sql: string, params: array} */ public static function getFilterCountQuery(string $table, ?array $params = null): array { $where = ''; $queryParams = []; if (!empty($params['filters']['formId'])) { $where = 'WHERE formId = %d'; $queryParams[] = (int)$params['filters']['formId']; } $sql = "SELECT SUM(status = 'read') as readTrueCount, SUM(status = 'unread') as readFalseCount, SUM(starred = 1) as starredTrueCount, SUM(starred = 0) as starredFalseCount FROM {$table} $where"; return ['sql' => $sql, 'params' => $queryParams]; } /** * Get the count of entries for multiple form IDs (SQL and params). * * @param int[] $formIds * @return array{sql: string, params: array, formIds: array} * @throws InvalidArgumentException */ public static function getEntryCountByFormIdsQuery(array $formIds): array { if (empty($formIds)) { return ['sql' => '', 'params' => [], 'formIds' => []]; } $formIds = array_map('intval', $formIds); $placeholders = implode(',', array_fill(0, count($formIds), '%d')); $tableName = EntriesTable::getTableName(); $sql = "SELECT formId, COUNT(*) as count FROM {$tableName} WHERE formId IN ($placeholders) GROUP BY formId"; return ['sql' => $sql, 'params' => $formIds, 'formIds' => $formIds]; } }