WEB: Allow listing of screenshots for "other" company id

The "other" company id is an aggregation of all games whose company has
edited one game.
This commit is contained in:
Le Philousophe
2024-11-09 19:00:18 +01:00
parent 2be6b63ab2
commit 8540d5da28
2 changed files with 29 additions and 4 deletions
+2 -4
View File
@@ -46,11 +46,9 @@ class ScreenshotsModel extends BasicModel
$data = $this->getFromCache($companyId);
if (!$data) {
$screenshots = ScreenshotQuery::create()
->useGameQuery()
->filterByCompanyId($companyId)
->endUse()
->withColumn(self::SUBCATEGORY_COLUMN, 'subcategory')
->find();
->withColumn(self::SUBCATEGORY_COLUMN, 'subcategory')
->find();
if ($screenshots->count() === 0) {
throw new \ErrorException(self::INVALID_CATEGORY);
+27
View File
@@ -7,6 +7,7 @@ use Propel\Runtime\Connection\ConnectionInterface;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
use ScummVM\OrmObjects\Screenshot as ChildScreenshot;
use ScummVM\OrmObjects\Map\GameTableMap;
use ScummVM\OrmObjects\Map\ScreenshotTableMap;
/**
@@ -96,4 +97,30 @@ class ScreenshotQuery extends BaseScreenshotQuery
return $obj;
}
public function filterByCompanyId($companyId, ConnectionInterface $con = null)
{
if ($companyId !== 'other') {
return $this->useGameQuery()
->filterByCompanyId($companyId)
->endUse();
}
// other company id means all companies with at most 1 game
$subquery = ScreenshotQuery::create()->useGameQuery()
->groupByCompanyId()
->endUse()
->withColumn('COUNT(DISTINCT((CASE
WHEN ' . GameTableMap::COL_SERIES_ID . ' IS NULL
THEN ' . ScreenshotTableMap::COL_ID . '
ELSE ' . GameTableMap::COL_SERIES_ID . '
END)))', 'cnt')
->having('cnt <= 1')
->withColumn(GameTableMap::COL_COMPANY_ID, 'company_id')
->removeSelfSelectColumns();
return $this->joinGame()
->addSelectQuery($subquery, 'c', false)
->where(GameTableMap::COL_COMPANY_ID . ' = c.company_id');
}
}