Skip to content

Commit

Permalink
1. 修复权重排序的bug 2. getRank()方法增加orderBy返回值
Browse files Browse the repository at this point in the history
  • Loading branch information
laozhu committed Jul 16, 2024
1 parent f0f2db7 commit 31c6100
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* @package LZStat
* @author laozhu
* @version 1.2.2
* @version 1.2.3
* @link https://ilaozhu.com/archives/2068/
*/
class Plugin implements PluginInterface
Expand Down Expand Up @@ -197,8 +197,13 @@ public static function selectHandler(Archive $archive)
}
}

$select->where('table.contents.created < ?', Date::time())
->order($plugin->orderBy, Db::SORT_DESC);
$select->where('table.contents.created < ?', Date::time());
if ($plugin->orderBy == 'weight') {
// typecho获取文章总数的逻辑有bug,为了不修改源码,暂时只能这么实现
$select->order('likesNum * 100 + viewsNum', Db::SORT_DESC);
} else {
$select->order($plugin->orderBy, Db::SORT_DESC);
}
return $select;
}

Expand Down Expand Up @@ -246,6 +251,7 @@ function statHandler(event, type) {

/**
* 获取榜单
*
* @param string $orderBy 排序方式(created,viewsNum,likesNum,weight),为空则根据配置排序
*/
public static function getRank(string $orderBy = null)
Expand All @@ -264,6 +270,7 @@ public static function getRank(string $orderBy = null)
Rank::alloc(['orderBy' => $orderBy])->to($posts);
return [
'title' => $title,
'orderBy' => $orderBy,
'posts' => $posts
];
}
Expand Down

0 comments on commit 31c6100

Please sign in to comment.