mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 01:33:11 +08:00
Fixed ordering in tags supporting more fields
This commit is contained in:
@@ -9,22 +9,26 @@ use function Shlinkio\Shlink\Core\camelCaseToSnakeCase;
|
||||
enum OrderableField: string
|
||||
{
|
||||
case TAG = 'tag';
|
||||
// case SHORT_URLS = 'shortUrls';
|
||||
// case VISITS = 'visits';
|
||||
// case NON_BOT_VISITS = 'nonBotVisits';
|
||||
|
||||
case SHORT_URLS_COUNT = 'shortUrlsCount';
|
||||
case VISITS = 'visits';
|
||||
case NON_BOT_VISITS = 'nonBotVisits';
|
||||
/** @deprecated Use VISITS instead */
|
||||
case VISITS_COUNT = 'visitsCount';
|
||||
/** @deprecated Use SHORT_URLS instead */
|
||||
case SHORT_URLS_COUNT = 'shortUrlsCount';
|
||||
|
||||
public static function isAggregateField(string $field): bool
|
||||
{
|
||||
return $field === self::SHORT_URLS_COUNT->value || $field === self::VISITS_COUNT->value;
|
||||
$parsed = self::tryFrom($field);
|
||||
return $parsed !== null && $parsed !== self::TAG;
|
||||
}
|
||||
|
||||
public static function toSnakeCaseValidField(?string $field): string
|
||||
{
|
||||
return camelCaseToSnakeCase($field === self::SHORT_URLS_COUNT->value ? $field : self::VISITS_COUNT->value);
|
||||
$parsed = self::tryFrom($field);
|
||||
$normalized = match ($parsed) {
|
||||
self::VISITS_COUNT, null => self::VISITS,
|
||||
default => $parsed,
|
||||
};
|
||||
|
||||
return camelCaseToSnakeCase($normalized->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,8 +25,8 @@ final class TagInfo implements JsonSerializable
|
||||
return new self(
|
||||
$data['tag'],
|
||||
(int) $data['shortUrlsCount'],
|
||||
(int) $data['visitsCount'],
|
||||
isset($data['nonBotVisitsCount']) ? (int) $data['nonBotVisitsCount'] : null,
|
||||
(int) $data['visits'],
|
||||
isset($data['nonBotVisits']) ? (int) $data['nonBotVisits'] : null,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,8 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
||||
't.id_0 AS id',
|
||||
't.name_1 AS name',
|
||||
'COUNT(DISTINCT s.id) AS short_urls_count',
|
||||
'COUNT(DISTINCT v.id) AS visits_count', // Native queries require snake_case for cross-db compatibility
|
||||
'COUNT(DISTINCT v2.id) AS non_bot_visits_count',
|
||||
'COUNT(DISTINCT v.id) AS visits', // Native queries require snake_case for cross-db compatibility
|
||||
'COUNT(DISTINCT v2.id) AS non_bot_visits',
|
||||
)
|
||||
->from('(' . $subQb->getQuery()->getSQL() . ')', 't') // @phpstan-ignore-line
|
||||
->leftJoin('t', 'short_urls_in_tags', 'st', $nativeQb->expr()->eq('t.id_0', 'st.tag_id'))
|
||||
@@ -108,8 +108,8 @@ class TagRepository extends EntitySpecificationRepository implements TagReposito
|
||||
$rsm = new ResultSetMappingBuilder($this->getEntityManager());
|
||||
$rsm->addScalarResult('name', 'tag');
|
||||
$rsm->addScalarResult('short_urls_count', 'shortUrlsCount');
|
||||
$rsm->addScalarResult('visits_count', 'visitsCount');
|
||||
$rsm->addScalarResult('non_bot_visits_count', 'nonBotVisitsCount');
|
||||
$rsm->addScalarResult('visits', 'visits');
|
||||
$rsm->addScalarResult('non_bot_visits', 'nonBotVisits');
|
||||
|
||||
return map(
|
||||
$this->getEntityManager()->createNativeQuery($nativeQb->getSQL(), $rsm)->getResult(),
|
||||
|
||||
Reference in New Issue
Block a user