torrent detail show tags

This commit is contained in:
xiaomlove
2022-09-17 20:38:54 +08:00
parent 1a0ad86b32
commit cbd6f2c00d
7 changed files with 40 additions and 21 deletions
+25 -12
View File
@@ -11,6 +11,8 @@ class TagRepository extends BaseRepository
{ {
private static $orderByFieldIdString; private static $orderByFieldIdString;
private static $allTags;
public function getList(array $params) public function getList(array $params)
{ {
$query = $this->createBasicQuery(); $query = $this->createBasicQuery();
@@ -61,20 +63,25 @@ class TagRepository extends BaseRepository
return $html; return $html;
} }
public function renderSpan(Collection $tagKeyById, array $renderIdArr = [], $withFilterLink = false): string public function renderSpan(array $renderIdArr = [], $withFilterLink = false): string
{ {
if (empty(self::$allTags)) {
self::$allTags = self::createBasicQuery()->get();
}
$html = ''; $html = '';
foreach ($renderIdArr as $tagId) { foreach (self::$allTags as $value) {
$value = $tagKeyById->get($tagId); if (in_array($value->id, $renderIdArr) || (isset($renderIdArr[0]) && $renderIdArr[0] == '*')) {
if ($value) { $tagId = $value->id;
$item = sprintf( if ($value) {
"<span style=\"background-color:%s;color:%s;border-radius:%s;font-size:%s;margin:%s;padding:%s\">%s</span>", $item = sprintf(
$value->color, $value->font_color, $value->border_radius, $value->font_size, $value->margin, $value->padding, $value->name "<span style=\"background-color:%s;color:%s;border-radius:%s;font-size:%s;margin:%s;padding:%s\">%s</span>",
); $value->color, $value->font_color, $value->border_radius, $value->font_size, $value->margin, $value->padding, $value->name
if ($withFilterLink) { );
$html .= sprintf('<a href="?tag_id=%s">%s</a>', $tagId, $item); if ($withFilterLink) {
} else { $html .= sprintf('<a href="?tag_id=%s">%s</a>', $tagId, $item);
$html .= $item; } else {
$html .= $item;
}
} }
} }
} }
@@ -141,5 +148,11 @@ class TagRepository extends BaseRepository
return self::$orderByFieldIdString; return self::$orderByFieldIdString;
} }
public function listAll()
{
self::$allTags = self::createBasicQuery()->get();
return self::$allTags;
}
} }
+2 -5
View File
@@ -3320,10 +3320,7 @@ function torrenttable($rows, $variant = "torrent", $searchBoxId = 0) {
$torrentSeedingLeechingStatus = $torrent->listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr); $torrentSeedingLeechingStatus = $torrent->listLeechingSeedingStatus($CURUSER['id'], $torrentIdArr);
$tagRep = new \App\Repositories\TagRepository(); $tagRep = new \App\Repositories\TagRepository();
$tagCollection = $tagRep->createBasicQuery()->get(); $torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->get();
$tagIdStr = $tagCollection->implode('id', ',') ?: '0';
$torrentTagCollection = \App\Models\TorrentTag::query()->whereIn('torrent_id', $torrentIdArr)->orderByRaw("field(tag_id,$tagIdStr)")->get();
$tagKeyById = $tagCollection->keyBy('id');
$torrentTagResult = $torrentTagCollection->groupBy('torrent_id'); $torrentTagResult = $torrentTagCollection->groupBy('torrent_id');
$showCover = false; $showCover = false;
$showSeedBoxIcon = get_setting('seed_box.enabled') == 'yes'; $showSeedBoxIcon = get_setting('seed_box.enabled') == 'yes';
@@ -3573,7 +3570,7 @@ foreach ($rows as $row)
*/ */
$tagOwns = $torrentTagResult->get($id); $tagOwns = $torrentTagResult->get($id);
if ($tagOwns) { if ($tagOwns) {
$tags = $tagRep->renderSpan($tagKeyById, $tagOwns->pluck('tag_id')->toArray()); $tags = $tagRep->renderSpan($tagOwns->pluck('tag_id')->toArray());
} else { } else {
$tags = ''; $tags = '';
} }
+1
View File
@@ -239,6 +239,7 @@ $lang_details = array
'claim_label' => '认领种子', 'claim_label' => '认领种子',
'claim_confirm' => '确定要认领此种子吗?', 'claim_confirm' => '确定要认领此种子吗?',
'action_approval' => '审核', 'action_approval' => '审核',
'row_tags' => '标签',
); );
?> ?>
+1
View File
@@ -238,6 +238,7 @@ $lang_details = array
'claim_label' => '認領種子', 'claim_label' => '認領種子',
'claim_confirm' => '確定要認領此種子嗎?', 'claim_confirm' => '確定要認領此種子嗎?',
'action_approval' => '審核', 'action_approval' => '審核',
'row_tags' => '標簽',
); );
?> ?>
+1
View File
@@ -238,6 +238,7 @@ $lang_details = array
'claim_label' => 'Claim torrent', 'claim_label' => 'Claim torrent',
'claim_confirm' => 'Are you sure to claim this torrent?', 'claim_confirm' => 'Are you sure to claim this torrent?',
'action_approval' => 'Approval', 'action_approval' => 'Approval',
'row_tags' => 'Tags',
); );
?> ?>
+7
View File
@@ -126,6 +126,13 @@ if (!$row) {
if ($smalldescription_main == 'yes') if ($smalldescription_main == 'yes')
tr($lang_details['row_small_description'],htmlspecialchars(trim($row["small_descr"])),true); tr($lang_details['row_small_description'],htmlspecialchars(trim($row["small_descr"])),true);
//tag
$torrentTags = \App\Models\TorrentTag::query()->where('torrent_id', $row['id'])->get();
if ($torrentTags->isNotEmpty()) {
$tagRep = new \App\Repositories\TagRepository();
tr($lang_details['row_tags'], $tagRep->renderSpan($torrentTags->pluck('tag_id')->toArray()),true);
}
$size_info = "<b>".$lang_details['text_size']."</b>" . mksize($row["size"]); $size_info = "<b>".$lang_details['text_size']."</b>" . mksize($row["size"]);
$type_info = "&nbsp;&nbsp;&nbsp;<b>".$lang_details['row_type'].":</b>&nbsp;".$row["cat_name"]; $type_info = "&nbsp;&nbsp;&nbsp;<b>".$lang_details['row_type'].":</b>&nbsp;".$row["cat_name"];
$source_info = $medium_info = $codec_info = $audiocodec_info = $standard_info = $processing_info = $team_info = ''; $source_info = $medium_info = $codec_info = $audiocodec_info = $standard_info = $processing_info = $team_info = '';
+3 -4
View File
@@ -10,8 +10,7 @@ parked();
* tags * tags
*/ */
$tagRep = new \App\Repositories\TagRepository(); $tagRep = new \App\Repositories\TagRepository();
$tagKeyById = $tagRep->createBasicQuery()->get()->keyBy('id'); $allTags = $tagRep->listAll();
$renderKeyArr = $tagKeyById->keys()->toArray();
$elasticsearchEnabled = nexus_env('ELASTICSEARCH_ENABLED'); $elasticsearchEnabled = nexus_env('ELASTICSEARCH_ENABLED');
//check searchbox //check searchbox
@@ -1143,8 +1142,8 @@ if (!$Cache->get_page()){
} }
echo $Cache->next_row(); echo $Cache->next_row();
if ($tagKeyById->isNotEmpty()) { if ($allTags->isNotEmpty()) {
echo '<tr><td colspan="3" class="embedded" style="padding-top: 4px">' . $tagRep->renderSpan($tagKeyById, $renderKeyArr, true) . '</td></tr>'; echo '<tr><td colspan="3" class="embedded" style="padding-top: 4px">' . $tagRep->renderSpan(['*'], true) . '</td></tr>';
} }
?> ?>