Commit 7cb181f0 authored by Tino Goratsch's avatar Tino Goratsch

Added the possibility to quickly enable/disable downloads

parent f57f3dc2
......@@ -85,6 +85,7 @@ class Create extends AbstractFormAction
];
return [
'active' => $this->formsHelper->yesNoCheckboxGenerator('active', 1),
'options' => $this->getOptions(['comments' => '0']),
'units' => $this->formsHelper->choicesGenerator('units', $this->getUnits(), ''),
'categories' => $this->categoriesHelpers->categoriesList(Files\Installer\Schema::MODULE_NAME, '', true),
......
......@@ -88,6 +88,7 @@ class Edit extends AbstractFormAction
];
return [
'active' => $this->formsHelper->yesNoCheckboxGenerator('active', $file['active']),
'options' => $this->getOptions($file),
'units' => $this->formsHelper->choicesGenerator('units', $this->getUnits(),
trim(strrchr($file['size'], ' '))),
......
......@@ -64,6 +64,15 @@ class Index extends Core\Controller\AbstractAdminAction
protected function addDataGridColumns(Core\Helpers\DataGrid $dataGrid)
{
$dataGrid
->addColumn([
'label' => $this->translator->t('files', 'active'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\ReplaceValueColumnRenderer::class,
'fields' => ['active'],
'custom' => [
'search' => [0, 1],
'replace' => [$this->translator->t('system', 'no'), $this->translator->t('system', 'yes')]
]
], 60)
->addColumn([
'label' => $this->translator->t('system', 'publication_period'),
'type' => Core\Helpers\DataGrid\ColumnRenderer\DateColumnRenderer::class,
......
......@@ -65,6 +65,11 @@ class Migration extends Modules\Installer\AbstractMigration
],
43 => [
"INSERT INTO `{pre}acl_resources` (`id`, `module_id`, `area`, `controller`, `page`, `params`, `privilege_id`) VALUES('', '{moduleId}', 'admin', 'index', 'duplicate', '', 4);",
],
44 => [
"ALTER TABLE `{pre}files` ADD COLUMN `active` TINYINT(1) UNSIGNED NOT NULL AFTER `id`;",
"ALTER TABLE `{pre}files` ADD INDEX (`active`)",
"UPDATE `{pre}files` SET `active` = 1;"
]
];
}
......
......@@ -58,7 +58,7 @@ class Schema implements Modules\Installer\SchemaInterface
*/
public function getSchemaVersion()
{
return 43;
return 44;
}
/**
......@@ -69,6 +69,7 @@ class Schema implements Modules\Installer\SchemaInterface
return [
"CREATE TABLE `{pre}files` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`active` TINYINT(1) UNSIGNED NOT NULL,
`start` DATETIME NOT NULL,
`end` DATETIME NOT NULL,
`updated_at` DATETIME NOT NULL,
......
......@@ -35,11 +35,12 @@ class FilesModel extends AbstractModel
}
/**
* @return array
* @inheritdoc
*/
protected function getAllowedColumns()
{
return [
'active' => DataProcessor\ColumnTypes::COLUMN_TYPE_BOOLEAN,
'start' => DataProcessor\ColumnTypes::COLUMN_TYPE_DATETIME,
'end' => DataProcessor\ColumnTypes::COLUMN_TYPE_DATETIME,
'updated_at' => DataProcessor\ColumnTypes::COLUMN_TYPE_DATETIME,
......@@ -59,6 +60,7 @@ class FilesModel extends AbstractModel
protected function getDefaultDataForDuplication()
{
return [
'active' => 0,
'start' => 'now',
'end' => 'now'
];
......
......@@ -26,10 +26,10 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
*/
public function resultExists($fileId, $time = '')
{
$period = empty($time) === false ? ' AND ' . $this->getPublicationPeriod() : '';
$period = empty($time) === false ? ' AND ' . $this->getPublicationPeriod() . ' AND `active` = :active' : '';
return ((int)$this->db->fetchColumn(
'SELECT COUNT(*) FROM ' . $this->getTableName() . ' WHERE id = :id' . $period,
['id' => $fileId, 'time' => $time]
"SELECT COUNT(*) FROM {$this->getTableName()} WHERE `id` = :id" . $period,
['id' => $fileId, 'time' => $time, 'active' => 1]
) > 0);
}
......@@ -53,7 +53,7 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
*/
public function getFileById($fileId)
{
return $this->db->fetchColumn('SELECT `file` FROM ' . $this->getTableName() . ' WHERE id = ?', [$fileId]);
return $this->db->fetchColumn("SELECT `file` FROM {$this->getTableName()} WHERE `id` = ?", [$fileId]);
}
/**
......@@ -83,11 +83,11 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
*/
public function getAllByCategoryId($categoryId, $time = '', $limitStart = '', $resultsPerPage = '')
{
$where = empty($time) === false ? ' AND ' . $this->getPublicationPeriod() : '';
$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,
['time' => $time, 'categoryId' => $categoryId]
['time' => $time, 'active' => 1, 'categoryId' => $categoryId]
);
}
......@@ -100,11 +100,11 @@ class FilesRepository extends Core\Model\Repository\AbstractRepository
*/
public function getAll($time = '', $limitStart = '', $resultsPerPage = '')
{
$where = empty($time) === false ? ' WHERE ' . $this->getPublicationPeriod() : '';
$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,
['time' => $time]
['time' => $time, 'active' => 1]
);
}
}
jQuery(document).ready(function ($) {
$('input[name="active"]').on('click change', function () {
$('#publication-period-wrapper').toggle(this.value === '1');
}).filter(':checked').click();
$(':checkbox[name="external"]')
.on('click', function () {
$('#file-external-toggle').toggle($(this).is(':checked'));
......
......@@ -10,7 +10,10 @@
</ul>
<div class="tab-content">
<div id="tab-1" class="tab-pane fade in active">
{datepicker name=['start', 'end'] value=[$form.start, $form.end]}
{include file="asset:System/Partials/form_group.button_group.tpl" options=$active name="active" required=true label={lang t="files|active"}}
<div id="publication-period-wrapper">
{datepicker name=['start', 'end'] value=[$form.start, $form.end]}
</div>
</div>
<div id="tab-2" class="tab-pane fade">
{include file="asset:System/Partials/form_group.input_text.tpl" name="title" value=$form.title required=true maxlength=120 data_attributes=['seo-slug-base' => 'true'] label={lang t="files|title"}}
......
<?xml version="1.0" encoding="UTF-8"?>
<language>
<keys>
<item key="active">Aktiv</item>
<item key="admin_index_create">Neuen Download erstellen</item>
<item key="admin_index_delete">Downloads löschen</item>
<item key="admin_index_edit">Download bearbeiten</item>
......@@ -19,6 +20,7 @@
<item key="latest_files">Aktuelle Downloads</item>
<item key="mod_description">Mit diesem Modul können die Downloads verwaltet werden.</item>
<item key="new_file">Neue Datei angeben</item>
<item key="select_active">Bitte wählen Sie aus, ob der Download veröffentlicht werden soll oder nicht.</item>
<item key="select_allow_comments">Bitte wählen Sie aus, ob Kommentare unter Downloads zugelassen werden sollen oder nicht.</item>
<item key="select_category">Bitte wählen Sie die Kategorie aus, in der sich der Download befinden soll.</item>
<item key="select_internal_resource">Bitte geben Sie den Pfad zur hochzuladenden Datei an.</item>
......
<?xml version="1.0" encoding="UTF-8"?>
<language>
<keys>
<item key="active">Active</item>
<item key="admin_index_create">Create new download</item>
<item key="admin_index_delete">Delete downloads</item>
<item key="admin_index_edit">Edit download</item>
......@@ -19,6 +20,7 @@
<item key="latest_files">Latest downloads</item>
<item key="mod_description">With this module you are able to administer the downloads.</item>
<item key="new_file">Replace current file</item>
<item key="select_active">Please select, whether this file should be active or not.</item>
<item key="select_allow_comments">Please select whether you want to allow comments under downloads or not.</item>
<item key="select_category">Please select a category where do you want to find the download.</item>
<item key="select_internal_resource">Please select the path to the file you want to upload.</item>
......
......@@ -49,6 +49,16 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
{
$this->validator
->addConstraint(Core\Validation\ValidationRules\FormTokenValidationRule::class)
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
'data' => $formData,
'field' => 'active',
'message' => $this->translator->t('files', 'select_active'),
'extra' => [
'haystack' => [0, 1]
]
])
->addConstraint(
Core\Validation\ValidationRules\DateValidationRule::class,
[
......
......@@ -2,7 +2,7 @@
<language>
<keys>
<item key="activate_readmore">Activate &quot;read more...&quot;</item>
<item key="active">Aktiv</item>
<item key="active">Active</item>
<item key="admin_index_create">Create new news</item>
<item key="admin_index_delete">Delete news</item>
<item key="admin_index_edit">Edit news</item>
......@@ -20,7 +20,7 @@
<item key="readmore_chars"><![CDATA[Characters required, to enable the &quot;read more...&quot;-function]]></item>
<item key="select_activate_readmore">
<![CDATA[Please select whether you want to enable or disable the &quot;read more...&quot;-function.]]></item>
<item key="select_active">Please select, whether the news should be active or not.</item>
<item key="select_active">Please select, whether this news should be active or not.</item>
<item key="select_allow_comments">Please select whether you want to allow comments under news or not.</item>
<item key="select_category">Please select the category where do you want to find the news.</item>
<item key="select_display_category_in_breadcrumb">Please select whether you want to display the category name of a
......
......@@ -31,6 +31,7 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
public function validate(array $formData)
{
$this->validator
->addConstraint(Core\Validation\ValidationRules\FormTokenValidationRule::class)
->addConstraint(
Core\Validation\ValidationRules\InArrayValidationRule::class,
[
......@@ -41,7 +42,6 @@ class AdminFormValidation extends Core\Validation\AbstractFormValidation
'haystack' => [0, 1]
]
])
->addConstraint(Core\Validation\ValidationRules\FormTokenValidationRule::class)
->addConstraint(
Core\Validation\ValidationRules\DateValidationRule::class,
[
......
......@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased] - 2017-xx-xx
### Added
- Added the possibility to duplicate downloads via the admin data grid
- Added the possibility to quickly enable/disable downloads
### 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