Browse Source

Add a "top tag" section in Communities

pull/863/head
Timothée Jaussoin 6 years ago
parent
commit
f76c834ae3
  1. 25
      app/widgets/Communities/Communities.php
  2. 12
      app/widgets/Communities/_communities.tpl

25
app/widgets/Communities/Communities.php

@ -4,6 +4,7 @@ use Movim\Widget\Base;
use Respect\Validation\Validator;
use App\Configuration;
use Carbon\Carbon;
include_once WIDGETS_PATH . 'Post/Post.php';
@ -28,11 +29,27 @@ class Communities extends Base
->restrictNSFW()
->recents()
->orderBy('posts.published', 'desc')
->where('open', true)
->take(30)
->get();
->where('open', true);
$view->assign('posts', $posts);
$postsIds = $posts->take(200)->pluck('id')->toArray();
$tags = \App\Tag::whereIn('id', function ($query) use ($postsIds) {
$query->select('tag_id')
->fromSub(function ($query) use ($postsIds) {
$query->selectRaw('tag_id, count(tag_id) as count')
->fromSub(function ($query) use ($postsIds) {
$query->from('post_tag')
->whereIn('post_id', $postsIds)
->get();
}, 'last_month')
->groupBy('tag_id')
->orderBy('count', 'desc')
->take(20);
}, 'top');
})->get();
$view->assign('tags', $tags);
$view->assign('posts', $posts->take(30)->get());
$view->assign('communities', $this->user->session->interestingCommunities()
->take(6)
->get());

12
app/widgets/Communities/_communities.tpl

@ -1,3 +1,15 @@
{if="$tags->isNotEmpty()"}
<ul class="list">
<li>
<p class="line normal">
{loop="$tags"}
<a class="button flat narrow" href="{$c->route('tag', $value->name)}">#{$value->name}</a>
{/loop}
</p>
</li>
</ul>
{/if}
{if="!$communities->isEmpty()"}
<ul class="list middle flex third active all">
<li class="subheader block large">

Loading…
Cancel
Save