Commit 08fe4eb5 authored by Jack Stupple's avatar Jack Stupple

resources are localized

parent b952198f
......@@ -6,7 +6,9 @@ use App\Resource;
class ResourceController extends Controller
{
public function index() {
public function index(Request $request) {
$player = get_player($request);
$subquery = \DB::table('player_history')
->select('resource_resource_category.resource_id')
->leftJoin('answers', 'answers.id', 'player_history.answer_id')
......@@ -18,10 +20,15 @@ class ResourceController extends Controller
$recommended = \DB::table('resources')
->whereRaw('resources.id IN (' . $subquery->toSql() . ')')
->where('resources.language_id', $player->language_id)
->limit(5)
->get();
$resources = \App\Resource::with('categories')->get();
$resources = \App\Resource::with('categories')
->where('resources.language_id', $player->language_id)
->get();
$resource_categories = \App\ResourceCategory::all();
$groups = [];
// recommended should always be first
......@@ -30,15 +37,17 @@ class ResourceController extends Controller
'resources' => $recommended
];
// if we build up the resource categories external to resources, it means they will always show but can be empty
foreach ($resource_categories as $resource_category) {
$parent_category = $resource_category->parent_category;
$groups[$parent_category] = [
'icon' => $this->getIconFor($parent_category),
'resources' => []
];
}
foreach ($resources as $resource) {
$parent_category = $resource->categories->first()->parent_category;
if (!isset($groups[$parent_category])) {
$groups[$parent_category] = [
'icon' => $this->getIconFor($parent_category),
'resources' => []
];
}
$groups[$parent_category]['resources'][] = $resource;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment