Commit f42dddd9 authored by Jack Stupple's avatar Jack Stupple

return all reosurces related to a bad question, but if you answer successfully filter those out

parent bc72fc3d
......@@ -6,22 +6,32 @@ use App\Resource;
class ResourceController extends Controller
{
protected function getBaseSubquery()
{
$player = get_player(false);
return \DB::table('player_history')
->select('resource_category_id')
->join('answers', 'answers.id', 'player_history.answer_id')
->join('answer_resource_category', 'answers.id', 'answer_resource_category.answer_id')
->whereRaw('player_id = ' . $player->id)
->groupBy('resource_category_id');
}
protected function buildRecommendedQuery($player)
{
if (!$player) {
return 0;
}
$subquery = \DB::table('player_history')
->select('resource_resource_category.resource_id')
->leftJoin('answer_resource_category', 'answer_resource_category.answer_id', 'player_history.answer_id')
->leftJoin('resource_categories', 'answer_resource_category.resource_category_id', 'resource_categories.id')
->leftJoin('resource_resource_category', 'resource_categories.id', 'resource_resource_category.resource_category_id')
->groupBy('resource_resource_category.resource_id');
$bad_answers = $this->getBaseSubquery()->whereRaw('answers.weight < 0.5');
$good_answers = $this->getBaseSubquery()->whereRaw('answers.weight >= 0.5');
$recommended = \DB::table('resources')
->whereRaw('resources.id IN (' . $subquery->toSql() . ')')
->where('resources.language_id', $player->language_id);
->join('resource_resource_category', 'resources.id', 'resource_resource_category.resource_id')
->whereRaw('resource_resource_category.resource_category_id IN (' . $bad_answers->toSql() . ')')
->whereRaw('resource_resource_category.resource_category_id NOT IN (' . $good_answers->toSql() . ')')
->whereRaw('resources.language_id = ' . $player->language_id);
return $recommended;
}
......
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