Skip to content

Commit 2066f6c

Browse files
committed
New parameter "showUnpublished" for fmFiles snippet
1 parent a43ea3b commit 2066f6c

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

_build/elements/snippets.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
'type' => 'numberfield',
6262
'value' => 0,
6363
),
64+
'showUnpublished' => array(
65+
'type' => 'combo-boolean',
66+
'value' => false,
67+
),
6468
'showGroups' => array(
6569
'type' => 'combo-boolean',
6670
'value' => true,

core/components/fileman/elements/snippets/files.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
$tplRow = $modx->getOption('tplRow', $scriptProperties, 'tpl.FileMan.Row');
1919
$wrapIfEmpty = $modx->getOption('wrapIfEmpty', $scriptProperties, false);
2020

21-
$usePdoTools = $fileMan->pdoToolsAvailable()
22-
? $modx->getOption('fileman_pdotools', $scriptProperties, true)
23-
: false;
21+
$usePdoTools = $fileMan->pdoToolsAvailable() && $modx->getOption('fileman_pdotools', $scriptProperties, true);
2422

25-
$sortby = $modx->getOption('sortBy', $scriptProperties, 'sort_order');
26-
$sortdir = $modx->getOption('sortDir', $scriptProperties, 'ASC');
23+
$sortBy = $modx->getOption('sortBy', $scriptProperties, 'sort_order');
24+
$sortDir = $modx->getOption('sortDir', $scriptProperties, 'ASC');
2725
$limit = $modx->getOption('limit', $scriptProperties, 0);
2826
$offset = $modx->getOption('offset', $scriptProperties, 0);
2927
$totalVar = $modx->getOption('totalVar', $scriptProperties, 'total');
@@ -32,6 +30,7 @@
3230

3331
$ids = $modx->getOption('ids', $scriptProperties, '');
3432
$resource = $modx->getOption('resource', $scriptProperties, 0);
33+
$showUnpublished = $modx->getOption('showUnpublished', $scriptProperties, false);
3534
$showGroups = $modx->getOption('showGroups', $scriptProperties, true);
3635
$makeUrl = $modx->getOption('makeUrl', $scriptProperties, true);
3736
$private = $modx->getOption('private', $scriptProperties, false);
@@ -50,6 +49,11 @@
5049
// Build query
5150
$c = $modx->newQuery(File::class);
5251

52+
if (!$showUnpublished) {
53+
$c->where([
54+
'published' => true
55+
]);
56+
}
5357
// resource
5458
$c->where([
5559
'resource_id' => ($resource > 0) ? $resource : $modx->resource->get('id')
@@ -71,7 +75,7 @@
7175
}
7276

7377
// sort
74-
$c->sortby($modx->escape($sortby), $sortdir);
78+
$c->sortby($modx->escape($sortBy), $sortDir);
7579

7680
$items = $modx->getIterator(File::class, $c);
7781

@@ -83,7 +87,7 @@
8387

8488
/** @var File $item */
8589
foreach ($items as $item) {
86-
$item->source = $mediaSource;
90+
$item->setMediaSource($mediaSource);
8791
$itemArr = $item->toArray();
8892

8993
if ($makeUrl) {

core/components/fileman/lexicon/en/properties.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
$_lang['fileman_prop_ids'] = 'List of specific id files for output';
1515
$_lang['fileman_prop_resource'] = 'Show files for this resource, by default - the current resource.';
1616
$_lang['fileman_prop_showGroups'] = 'Use grouping (if the group field is filled in)';
17+
$_lang['fileman_prop_showUnpublished'] = 'Show unpublished files';
1718
$_lang['fileman_prop_makeUrl'] = 'Generate a link to download a file';
1819
$_lang['fileman_prop_includeTimeStamp'] = 'Include file modification date';
1920

core/components/fileman/lexicon/ru/properties.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
$_lang['fileman_prop_private'] = 'Закрытый режим дает скачать файл через идентификатор файла';
1414
$_lang['fileman_prop_ids'] = 'Список конкретных id файлов для вывода';
1515
$_lang['fileman_prop_resource'] = 'Показать файлы для этого ресурса, по-умолчанию используется текущий';
16+
$_lang['fileman_prop_showUnpublished'] = 'Показывать неопубликованные файлы';
1617
$_lang['fileman_prop_showGroups'] = 'Использовать группировку (если заполнено поле)';
1718
$_lang['fileman_prop_makeUrl'] = 'Создавать ссылку для скачивания файла';
1819
$_lang['fileman_prop_includeTimeStamp'] = 'Получать дату модификации файла';

0 commit comments

Comments
 (0)