Browse Source

add total for year counter

master
filesite 1 month ago
parent
commit
9f8fe59c60
  1. 17
      themes/beauty/controller/CommandController.php
  2. 6
      themes/beauty/controller/ListController.php
  3. 22
      themes/beauty/views/list/bydate.php
  4. 12
      themes/beauty/views/site/index.php

17
themes/beauty/controller/CommandController.php

@ -133,7 +133,6 @@ eof; @@ -133,7 +133,6 @@ eof;
//缓存所有目录的文件数量
$this->saveDirCounter();
//TODO: 保存所有目录下文件数量统计
//按年、月保存文件数据,以便按年、月显示
//while (true) {
@ -150,6 +149,8 @@ eof; @@ -150,6 +149,8 @@ eof;
Common::setCache($this->dateIndexCacheKey, array());
Common::setCache($this->noOriginalCtimeFilesCacheKey, array());
Common::setCache($this->allFilesCacheKey, array());
Common::setCache($this->dirCounterCacheKey, array());
Common::setCache($this->allDirTreeCacheKey, array());
}
protected function getParentDir($dirpath) {
@ -217,7 +218,15 @@ eof; @@ -217,7 +218,15 @@ eof;
foreach ($scanResults as $id => $item) {
$hadScanedDirs = Common::getCache($cacheKey);
if (!empty($item['filename'])) {
//忽略.txt描述文件
if (
!empty($item['filename']) && !empty($item['extension'])
&& (
in_array($item['extension'], $supportedImageExts)
|| in_array($item['extension'], $supportedVideoExts)
|| in_array($item['extension'], $supportedAudioExts)
)
) {
//保存所有文件到索引
$this->updateAllFilesCache($item);
//更新年份、月份时间索引
@ -367,6 +376,10 @@ eof; @@ -367,6 +376,10 @@ eof;
$indexKeys = [];
foreach ($cacheData as $year => $item) {
$indexKeys[$year] = array_keys($item);
$indexKeys[$year]['total'] = 0;
foreach($item as $month => $ids) {
$indexKeys[$year]['total'] += count($ids);
}
}
Common::saveCacheToFile("{$cacheKey}_keys", $indexKeys, $cacheDir);

6
themes/beauty/controller/ListController.php

@ -501,7 +501,7 @@ Class ListController extends Controller { @@ -501,7 +501,7 @@ Class ListController extends Controller {
//只显示有数据的月份
$monthsByType = [];
foreach($cacheData as $month => $arr) {
if (!empty($arr)) {
if ($month != 'total' && !empty($arr)) {
array_push($monthsByType, $month);
}
}
@ -521,7 +521,9 @@ Class ListController extends Controller { @@ -521,7 +521,9 @@ Class ListController extends Controller {
//把所有文件拼接到一个数组里
$allFiles = [];
foreach($cacheData as $month => $files) {
$allFiles = array_merge($allFiles, $files);
if (is_array($files)) {
$allFiles = array_merge($allFiles, $files);
}
}

22
themes/beauty/views/list/bydate.php

@ -23,6 +23,7 @@ if (!empty($viewData['para_month'])) { @@ -23,6 +23,7 @@ if (!empty($viewData['para_month'])) {
$selectedId = $viewData['para_month'];
}
$cacheData = !empty($viewData['cacheData']) ? $viewData['cacheData'] : [];
?><!-- 顶部导航栏模块 -->
<nav class="navbar navbar-default navbar-fixed-top navbarJS">
<div class="container-fluid">
@ -69,8 +70,18 @@ if (!empty($viewData['para_month'])) { @@ -69,8 +70,18 @@ if (!empty($viewData['para_month'])) {
foreach($arrYears as $year) {
$intYear = str_replace('y', '', $year);
$selected = $year == $viewData['para_year'] ? 'active' : '';
$htmlFileTotal = '';
if (!empty($viewData['cacheData_keys'][$year]['total'])) {
$htmlFileTotal = <<<eof
<small class="badge">{$viewData['cacheData_keys'][$year]['total']}</small>
eof;
}
echo <<<eof
<li class="{$selected}"><a href="/list/bydate?year={$year}"><img src="/img/beauty/calendar.svg?gray" alt="calendar" width="14" class="menu-icon"> {$intYear}年</a></li>
<li class="{$selected}"><a href="/list/bydate?year={$year}">
<img src="/img/beauty/calendar.svg?gray" alt="calendar" width="14" class="menu-icon">
{$intYear}年
{$htmlFileTotal}
</a></li>
eof;
}
}else {
@ -86,16 +97,19 @@ eof; @@ -86,16 +97,19 @@ eof;
<?php
if (!empty($viewData['menus'])) { //只显示第一级目录
foreach ($viewData['menus'] as $index => $item) {
$fileTotal = 0;
$htmlFileTotal = '';
if ( !empty($viewData['dirCounters']) && !empty($viewData['dirCounters'][$item['id']]) ) {
$dirTotal = $viewData['dirCounters'][$item['id']];
$fileTotal = $dirTotal['image_total'] + $dirTotal['video_total'] + $dirTotal['audio_total'];
$htmlFileTotal = <<<eof
<small class="badge">{$fileTotal}</small>
eof;
}
echo <<<eof
<li><a href="{$item['path']}">
<img src="/img/beauty/folder.svg" alt="directories" width="17" class="menu-icon">
{$item['directory']}
<small class="badge">{$fileTotal}</small>
{$htmlFileTotal}
</a></li>
eof;
}
@ -110,7 +124,6 @@ eof; @@ -110,7 +124,6 @@ eof;
<!-- 内容主题 -->
<div class="img_main <?=$main_view_cls?>">
<?php
$cacheData = !empty($viewData['cacheData']) ? $viewData['cacheData'] : [];
$btnSetSnap = '';
$total = 0;
@ -208,6 +221,7 @@ eof; @@ -208,6 +221,7 @@ eof;
}
foreach ($months as $month) {
if (strpos($month, 'm') === false) {continue;}
$intMonth = str_replace('m', '', $month);
$activedClass = $month == $viewData['para_month'] ? 'active' : '';
$monthLink = Html::getLinkByParams(FSC::$app['requestUrl'], array(

12
themes/beauty/views/site/index.php

@ -78,8 +78,18 @@ $main_view_cls = $menu_ext_status == 'opened' ? '' : 'full'; @@ -78,8 +78,18 @@ $main_view_cls = $menu_ext_status == 'opened' ? '' : 'full';
arsort($arrYears);
foreach($arrYears as $year) {
$intYear = str_replace('y', '', $year);
$htmlFileTotal = '';
if (!empty($viewData['cacheDataByDate'][$year]['total'])) {
$htmlFileTotal = <<<eof
<small class="badge">{$viewData['cacheDataByDate'][$year]['total']}</small>
eof;
}
echo <<<eof
<li><a href="/list/bydate?year={$year}"><img src="/img/beauty/calendar.svg?gray" alt="calendar" width="14" class="menu-icon"> {$intYear}年</a></li>
<li><a href="/list/bydate?year={$year}">
<img src="/img/beauty/calendar.svg?gray" alt="calendar" width="14" class="menu-icon">
{$intYear}年
{$htmlFileTotal}
</a></li>
eof;
}
}else {

Loading…
Cancel
Save