mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
improve claim + horizon instead queue:work
This commit is contained in:
+90
-4
@@ -2,8 +2,26 @@
|
||||
require "../include/bittorrent.php";
|
||||
dbconn();
|
||||
loggedinorreturn();
|
||||
$sortAllowed = [
|
||||
'created_at' => nexus_trans('claim.th_claim_at'),
|
||||
'last_settle_at' => nexus_trans('claim.th_last_settle'),
|
||||
'seed_time' => nexus_trans('claim.th_seed_time_this_month'),
|
||||
'uploaded' => nexus_trans('claim.th_uploaded_this_month'),
|
||||
];
|
||||
$orderAllowed = [
|
||||
'asc' => nexus_trans('nexus.asc'),
|
||||
'desc' => nexus_trans('nexus.desc'),
|
||||
];
|
||||
$torrentId = $uid = 0;
|
||||
$actionTh = $actionTd = '';
|
||||
$sort = $_GET['sort'] ?? 'created_at';
|
||||
if (!isset($sortAllowed[$sort])) {
|
||||
$sort = "created_at";
|
||||
}
|
||||
$order = $_GET['order'] ?? 'asc';
|
||||
if (!isset($orderAllowed[$order])) {
|
||||
$order = "asc";
|
||||
}
|
||||
if (!empty($_GET['torrent_id'])) {
|
||||
$torrentId = $_GET['torrent_id'];
|
||||
int_check($torrentId,true);
|
||||
@@ -13,7 +31,7 @@ if (!empty($_GET['torrent_id'])) {
|
||||
}
|
||||
stdhead(nexus_trans('claim.title_for_torrent'));
|
||||
$query = \App\Models\Claim::query()->where('torrent_id', $torrentId);
|
||||
$pagerParam = "?torrent_id=$torrentId";
|
||||
$pagerParam = "?torrent_id=$torrentId&sort=$sort&order=$order";
|
||||
print("<h1 align=center>".nexus_trans('claim.title_for_torrent') . "<a href=details.php?id=" . htmlspecialchars($torrentId) . "><b> ".htmlspecialchars($torrent['name'])."</b></a></h1>");
|
||||
} elseif (!empty($_GET['uid'])) {
|
||||
$uid = $_GET['uid'];
|
||||
@@ -24,7 +42,7 @@ if (!empty($_GET['torrent_id'])) {
|
||||
}
|
||||
stdhead(nexus_trans('claim.title_for_user'));
|
||||
$query = \App\Models\Claim::query()->where('uid', $uid);
|
||||
$pagerParam = "?uid=$uid";
|
||||
$pagerParam = "?uid=$uid&sort=$sort&order=$order";
|
||||
print("<h1 align=center>".nexus_trans('claim.title_for_user') . "<a href=userdetails.php?id=" . htmlspecialchars($uid) . "><b> ".htmlspecialchars($user->username)."</b></a></h1>");
|
||||
if ($uid == $CURUSER['id']) {
|
||||
$actionTh = sprintf("<td class='colhead' align='center'>%s</td>", nexus_trans("claim.th_action"));
|
||||
@@ -34,9 +52,69 @@ if (!empty($_GET['torrent_id'])) {
|
||||
}
|
||||
|
||||
begin_main_frame();
|
||||
$textSelectOnePlease = nexus_trans('nexus.select_one_please');
|
||||
$sortOptions = $orderOptions = '';
|
||||
foreach ($sortAllowed as $name => $text) {
|
||||
$sortOptions .= sprintf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
$name, $_GET['sort'] == $name ? ' selected' : '', $text
|
||||
);
|
||||
}
|
||||
foreach ($orderAllowed as $name => $text) {
|
||||
$orderOptions .= sprintf(
|
||||
'<option value="%s"%s>%s</option>',
|
||||
$name, $_GET['order'] == $name ? ' selected' : '', $text
|
||||
);
|
||||
}
|
||||
$resetText = nexus_trans('label.reset');
|
||||
$submitText = nexus_trans('label.submit');
|
||||
$sortText = nexus_trans('nexus.sort');
|
||||
$orderText = nexus_trans('nexus.order');
|
||||
$filterForm = <<<FORM
|
||||
<div>
|
||||
<form id="filterForm" action="{$_SERVER['REQUEST_URI']}" method="get">
|
||||
<input type="hidden" name="uid" value="{$uid}" />
|
||||
<input type="hidden" name="torrent_id" value="{$torrentId}" />
|
||||
<span>{$sortText}:</span>
|
||||
<select name="sort">
|
||||
<option value="">-{$textSelectOnePlease}-</option>
|
||||
{$sortOptions}
|
||||
</select>
|
||||
|
||||
<span>{$orderText}:</span>
|
||||
<select name="order">
|
||||
<option value="">-{$textSelectOnePlease}-</option>
|
||||
{$orderOptions}
|
||||
</select>
|
||||
|
||||
<input type="submit" value="{$submitText}">
|
||||
<input type="button" id="reset" value="{$resetText}">
|
||||
</form>
|
||||
</div>
|
||||
FORM;
|
||||
$resetJs = <<<JS
|
||||
jQuery("#reset").on('click', function () {
|
||||
jQuery("select[name=sort]").val('')
|
||||
jQuery("select[name=order]").val('')
|
||||
})
|
||||
JS;
|
||||
\Nexus\Nexus::js($resetJs, 'footer', false);
|
||||
|
||||
|
||||
$total = (clone $query)->count();
|
||||
list($pagertop, $pagerbottom, $limit, $offset, $pageSize) = pager(50, $total, "$pagerParam&");
|
||||
$list = (clone $query)->with(['user', 'torrent', 'snatch'])->offset($offset)->limit($pageSize)->orderBy('id', 'desc')->get();
|
||||
$query = (clone $query)->with(['user', 'torrent', 'snatch'])->offset($offset)->limit($pageSize);
|
||||
if ($sort == 'seed_time') {
|
||||
$query->join("snatched", "claims.snatched_id", "=", "snatched.id")
|
||||
->orderByRaw("(snatched.seedtime - claims.seed_time_begin) $order");
|
||||
} elseif ($sort == 'uploaded') {
|
||||
$query->join("snatched", "claims.snatched_id", "=", "snatched.id")
|
||||
->orderByRaw("(snatched.uploaded - claims.uploaded_begin) $order");
|
||||
} else {
|
||||
$query->orderBy($sort, $order);
|
||||
}
|
||||
$list = $query->get();
|
||||
print($filterForm);
|
||||
print("<table id='claim-table' width='100%'>");
|
||||
print("<tr>
|
||||
<td class='colhead' align='center'>".nexus_trans('claim.th_id')."</td>
|
||||
@@ -55,6 +133,9 @@ $now = \Carbon\Carbon::now();
|
||||
$seedTimeRequiredHours = \App\Models\Claim::getConfigStandardSeedTimeHours();
|
||||
$uploadedRequiredTimes = \App\Models\Claim::getConfigStandardUploadedTimes();
|
||||
$claimRep = new \App\Repositories\ClaimRepository();
|
||||
$torrentTool = new \Nexus\Torrent\Torrent();
|
||||
$torrentIdList = $list->pluck('torrent_id')->toArray();
|
||||
$leechingSeedingStatus = $torrentTool->listLeechingSeedingStatus($CURUSER['id'], $torrentIdList);
|
||||
foreach ($list as $row) {
|
||||
if (
|
||||
bcsub($row->snatch->seedtime, $row->seed_time_begin) >= $seedTimeRequiredHours * 3600
|
||||
@@ -68,10 +149,15 @@ foreach ($list as $row) {
|
||||
if ($actionTh) {
|
||||
$actionTd = sprintf('<td class="rowfollow nowrap" align="center">%s</td>', $claimRep->buildActionButtons($row->torrent_id, $row, 1));
|
||||
}
|
||||
$torrentName = $row->torrent->name;
|
||||
$torrentId = $row->torrent_id;
|
||||
if (isset($leechingSeedingStatus[$torrentId])) {
|
||||
$torrentName .= $torrentTool->renderProgressBar($leechingSeedingStatus[$torrentId]['active_status'], $leechingSeedingStatus[$torrentId]['progress']);
|
||||
}
|
||||
print("<tr>
|
||||
<td class='rowfollow nowrap' align='center'>" . $row->id . "</td>
|
||||
<td class='rowfollow' align='left'><a href='userdetails.php?id=" . $row->uid . "'>" . $row->user->username . "</a></td>
|
||||
<td class='rowfollow' align='left'><a href='details.php?id=" . $row->torrent_id . "'>" . $row->torrent->name . "</a></td>
|
||||
<td class='rowfollow' align='left'><a href='details.php?id=" . $row->torrent_id . "'>" . $torrentName . "</a></td>
|
||||
<td class='rowfollow nowrap' align='center'>" . mksize($row->torrent->size) . "</td>
|
||||
<td class='rowfollow nowrap' align='center'>" . mkprettytime($row->torrent->added->diffInSeconds($now, true)) . "</td>
|
||||
<td class='rowfollow nowrap' align='center'>" . format_datetime($row->created_at) . "</td>
|
||||
|
||||
Reference in New Issue
Block a user