pollthingy/resources/views/view_poll_results.blade.php

63 lines
2.6 KiB
PHP
Raw Normal View History

@extends('layouts.app')
@section('title', "Results for '" . $poll->question . "'")
@section('content')
@if ($voted)
<section class="primary-box">
<span>Your vote has been recorded!</span><br>
</section>
@endif
@if($poll->results_visible)
2018-10-18 05:37:08 +02:00
@php ($sortedOptions = $poll->options->sortByDesc(function($option) use($poll) { return $poll->votes->where('poll_option_id', $option->id)->count(); }))
@php ($nonZeroOptions = $sortedOptions->filter(function($option) use($poll) { return $poll->votes->where('poll_option_id', $option->id)->count() > 0; }))
2018-10-18 01:16:03 +02:00
<section class="grid grid--large some-top-margin">
<div class="some-bottom-margin">
<div class="primary-box">
2018-10-18 01:16:03 +02:00
@php ($total = $poll->votes->count())
2018-10-18 05:37:08 +02:00
@foreach ($sortedOptions as $option)
2018-10-18 01:16:03 +02:00
@php ($votes = $poll->votes->where('poll_option_id', $option->id)->count())
<div class="some-more-bottom-margin">
<div>
<span>{{ $option->text }}</span>
<span style="float:right">{{ $votes }} votes</span>
</div>
<div>
2018-10-18 05:37:08 +02:00
<!-- TODO: title attribute -->
2018-10-18 01:16:03 +02:00
<div style="background-color:#e83fb8;height:2rem;width:{{ $votes / $total * 100 }}%;">
</div>
</div>
</div>
@endforeach
<div class="some-top-margin">
<span>Total votes: {{ $total }}</span>
</div>
</div>
</div>
<div>
2018-10-18 05:37:08 +02:00
@php ($cache = Cache::get($poll->id))
<div class="primary-box">
2018-10-18 05:37:08 +02:00
<img src="{{ $cache['pie_chart']}}" style="display:block;margin: 0 auto">
<br>
@foreach ($nonZeroOptions as $option)
<!-- TODO: Generate images so this works on text browsers -->
<div style="display:inline-block;height:1rem;width:1rem;background-color:{{$cache['colours'][$option->id]}};margin-right:1rem"></div>
<span>{{ $option->text }}</span>
<br>
@endforeach
</div>
</div>
</section>
@else
<section class="primary-box some-top-margin">
<span>Results for this poll are hidden until the poll is closed.</span>
</section>
@endif
@endsection