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;
//缓存所有目录的文件数量 //缓存所有目录的文件数量
$this->saveDirCounter(); $this->saveDirCounter();
//TODO: 保存所有目录下文件数量统计
//按年、月保存文件数据,以便按年、月显示 //按年、月保存文件数据,以便按年、月显示
//while (true) { //while (true) {
@ -150,6 +149,8 @@ eof;
Common::setCache($this->dateIndexCacheKey, array()); Common::setCache($this->dateIndexCacheKey, array());
Common::setCache($this->noOriginalCtimeFilesCacheKey, array()); Common::setCache($this->noOriginalCtimeFilesCacheKey, array());
Common::setCache($this->allFilesCacheKey, array()); Common::setCache($this->allFilesCacheKey, array());
Common::setCache($this->dirCounterCacheKey, array());
Common::setCache($this->allDirTreeCacheKey, array());
} }
protected function getParentDir($dirpath) { protected function getParentDir($dirpath) {
@ -217,7 +218,15 @@ eof;
foreach ($scanResults as $id => $item) { foreach ($scanResults as $id => $item) {
$hadScanedDirs = Common::getCache($cacheKey); $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); $this->updateAllFilesCache($item);
//更新年份、月份时间索引 //更新年份、月份时间索引
@ -367,6 +376,10 @@ eof;
$indexKeys = []; $indexKeys = [];
foreach ($cacheData as $year => $item) { foreach ($cacheData as $year => $item) {
$indexKeys[$year] = array_keys($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); Common::saveCacheToFile("{$cacheKey}_keys", $indexKeys, $cacheDir);

6
themes/beauty/controller/ListController.php

@ -501,7 +501,7 @@ Class ListController extends Controller {
//只显示有数据的月份 //只显示有数据的月份
$monthsByType = []; $monthsByType = [];
foreach($cacheData as $month => $arr) { foreach($cacheData as $month => $arr) {
if (!empty($arr)) { if ($month != 'total' && !empty($arr)) {
array_push($monthsByType, $month); array_push($monthsByType, $month);
} }
} }
@ -521,7 +521,9 @@ Class ListController extends Controller {
//把所有文件拼接到一个数组里 //把所有文件拼接到一个数组里
$allFiles = []; $allFiles = [];
foreach($cacheData as $month => $files) { 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'])) {
$selectedId = $viewData['para_month']; $selectedId = $viewData['para_month'];
} }
$cacheData = !empty($viewData['cacheData']) ? $viewData['cacheData'] : [];
?><!-- 顶部导航栏模块 --> ?><!-- 顶部导航栏模块 -->
<nav class="navbar navbar-default navbar-fixed-top navbarJS"> <nav class="navbar navbar-default navbar-fixed-top navbarJS">
<div class="container-fluid"> <div class="container-fluid">
@ -69,8 +70,18 @@ if (!empty($viewData['para_month'])) {
foreach($arrYears as $year) { foreach($arrYears as $year) {
$intYear = str_replace('y', '', $year); $intYear = str_replace('y', '', $year);
$selected = $year == $viewData['para_year'] ? 'active' : ''; $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 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; eof;
} }
}else { }else {
@ -86,16 +97,19 @@ eof;
<?php <?php
if (!empty($viewData['menus'])) { //只显示第一级目录 if (!empty($viewData['menus'])) { //只显示第一级目录
foreach ($viewData['menus'] as $index => $item) { foreach ($viewData['menus'] as $index => $item) {
$fileTotal = 0; $htmlFileTotal = '';
if ( !empty($viewData['dirCounters']) && !empty($viewData['dirCounters'][$item['id']]) ) { if ( !empty($viewData['dirCounters']) && !empty($viewData['dirCounters'][$item['id']]) ) {
$dirTotal = $viewData['dirCounters'][$item['id']]; $dirTotal = $viewData['dirCounters'][$item['id']];
$fileTotal = $dirTotal['image_total'] + $dirTotal['video_total'] + $dirTotal['audio_total']; $fileTotal = $dirTotal['image_total'] + $dirTotal['video_total'] + $dirTotal['audio_total'];
$htmlFileTotal = <<<eof
<small class="badge">{$fileTotal}</small>
eof;
} }
echo <<<eof echo <<<eof
<li><a href="{$item['path']}"> <li><a href="{$item['path']}">
<img src="/img/beauty/folder.svg" alt="directories" width="17" class="menu-icon"> <img src="/img/beauty/folder.svg" alt="directories" width="17" class="menu-icon">
{$item['directory']} {$item['directory']}
<small class="badge">{$fileTotal}</small> {$htmlFileTotal}
</a></li> </a></li>
eof; eof;
} }
@ -110,7 +124,6 @@ eof;
<!-- 内容主题 --> <!-- 内容主题 -->
<div class="img_main <?=$main_view_cls?>"> <div class="img_main <?=$main_view_cls?>">
<?php <?php
$cacheData = !empty($viewData['cacheData']) ? $viewData['cacheData'] : [];
$btnSetSnap = ''; $btnSetSnap = '';
$total = 0; $total = 0;
@ -208,6 +221,7 @@ eof;
} }
foreach ($months as $month) { foreach ($months as $month) {
if (strpos($month, 'm') === false) {continue;}
$intMonth = str_replace('m', '', $month); $intMonth = str_replace('m', '', $month);
$activedClass = $month == $viewData['para_month'] ? 'active' : ''; $activedClass = $month == $viewData['para_month'] ? 'active' : '';
$monthLink = Html::getLinkByParams(FSC::$app['requestUrl'], array( $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';
arsort($arrYears); arsort($arrYears);
foreach($arrYears as $year) { foreach($arrYears as $year) {
$intYear = str_replace('y', '', $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 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; eof;
} }
}else { }else {

Loading…
Cancel
Save