Commit 77fabc0f authored by Tino Goratsch's avatar Tino Goratsch

finished the previous work

parent 9acdb2aa
......@@ -7,6 +7,8 @@
namespace ACP3\Modules\ACP3\Files\Model\Repository;
use ACP3\Core;
use ACP3\Core\Database\Connection;
use ACP3\Modules\ACP3\Files\Installer\Schema;
/**
* Class FilesRepository
......@@ -17,6 +19,22 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
use Core\Model\Repository\PublicationPeriodAwareTrait;
const TABLE_NAME = 'files';
/**
* @var Core\Settings\SettingsInterface
*/
private $settings;
/**
* FilesRepository constructor.
* @param Connection $db
* @param Core\Settings\SettingsInterface $settings
*/
public function __construct(Connection $db, Core\Settings\SettingsInterface $settings)
{
parent::__construct($db);
$this->settings = $settings;
}
/**
* @param int $fileId
......@@ -86,7 +104,7 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
$where = empty($time) === false ? ' AND ' . $this->getPublicationPeriod() . ' AND `active` = :active' : '';
$limitStmt = $this->buildLimitStmt($limitStart, $resultsPerPage);
return $this->db->fetchAll(
'SELECT * FROM ' . $this->getTableName() . ' WHERE category_id = :categoryId' . $where . ' ORDER BY `start` DESC, `end` DESC, `id` DESC' . $limitStmt,
"SELECT * FROM {$this->getTableName()} WHERE `category_id` = :categoryId {$where} ORDER BY {$this->getOrderBy()}{$limitStmt}",
['time' => $time, 'active' => 1, 'categoryId' => $categoryId]
);
}
......@@ -103,7 +121,7 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
$where = empty($time) === false ? ' WHERE ' . $this->getPublicationPeriod() . ' AND `active` = :active' : '';
$limitStmt = $this->buildLimitStmt($limitStart, $resultsPerPage);
return $this->db->fetchAll(
'SELECT * FROM ' . $this->getTableName() . $where . ' ORDER BY `start` DESC, `end` DESC, `id` DESC' . $limitStmt,
"SELECT * FROM {$this->getTableName()}{$where} ORDER BY {$this->getOrderBy()}{$limitStmt}",
['time' => $time, 'active' => 1]
);
}
......@@ -115,4 +133,23 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
{
return (int)$this->db->fetchColumn("SELECT MAX(`sort`) FROM {$this->getTableName()};");
}
/**
* @return string
*/
private function getOrderBy()
{
$settings = $this->settings->getSettings(Schema::MODULE_NAME);
$orderByMap = [
'date' => '`start` DESC, `end` DESC, `id` DESC',
'custom' => '`sort` ASC'
];
if (isset($settings['order_by']) && isset($orderByMap[$settings['order_by']])) {
return $orderByMap[$settings['order_by']];
}
return $orderByMap['date'];
}
}
......@@ -8,6 +8,7 @@ services:
class: ACP3\Modules\ACP3\Files\Model\Repository\FilesRepository
arguments:
- '@core.db'
- '@core.config'
files.model.search_results_aware_repository:
class: ACP3\Modules\ACP3\Files\Model\Repository\SearchResultsAwareRepository
......
......@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Added the possibility to duplicate downloads via the admin data grid
- Added the possibility to quickly enable/disable downloads
- Added the possibility to order download by date and with an custom order
### Changed
- Updated `giggsey/locale` library to version 1.3 to take advantage of the new functionality for the localized country list
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment