]> _ Git - psq.git/commitdiff
added poll types
authorLouis Jeckel <louis.jeckel@outlook.com>
Thu, 22 Oct 2020 11:44:23 +0000 (13:44 +0200)
committerLouis Jeckel <louis.jeckel@outlook.com>
Thu, 22 Oct 2020 11:44:23 +0000 (13:44 +0200)
app/Http/Controllers/Admin/PollController.php
config/app.php
config/twill.php
resources/js/components/PollAnswers/PollAnswers.vue
resources/views/admin/blocks/poll_rating.blade.php [new file with mode: 0644]
resources/views/admin/blocks/poll_yes_no.blade.php [new file with mode: 0644]
resources/views/admin/polls/form.blade.php
resources/views/site/blocks/poll_rating.blade.php [new file with mode: 0644]
resources/views/site/blocks/poll_yes_no.blade.php [new file with mode: 0644]
resources/views/site/layouts/block.blade.php

index 08f107225025d325a01fa18c3c280bbf5dd37a55..354052832f3aa043daf9075dd1b783a4a3690b3b 100644 (file)
@@ -50,12 +50,21 @@ class PollController extends ModuleController
                 ];
             }, array_keys($ansCountBy), $ansCountBy);
 
+            $more = [];
 
+            if($question['type'] === 'poll_rating') {
+                $numberOnly = array_filter($ansCountBy, fn($ans) => is_numeric($ans['value']));
+                $count = array_sum(array_column($numberOnly, 'count'));
+                $score = array_reduce($numberOnly, fn($acc, $ans) => $acc + $ans['value'] * $ans['count']);
+                $more['mean'] = number_format($score/$count, 2);
+            }
 
 
-            return array_merge($question, [
+
+
+            return $question + [
                 'answers' => $ansCountBy
-            ]);
+            ] + $more;
         });
 
 
index 64c5f76409cd468f2a437ad08f5f9131881f6f6e..b464dc2d7c4ca5cf452e478e3fbdc82bf74f6a6f 100644 (file)
@@ -125,7 +125,7 @@ return [
 
     'aws_s3_url' => 'https://prescription-sante.s3.eu-west-3.amazonaws.com',
 
-    'version' => '0.4.2 beta 3',
+    'version' => '0.6.1 beta 4',
 
 
     /*
index cb23f700fc57f33bc78c883fbc5cff35e24d0f7e..bb886dd528651ee1aa62a240b71c09fca2359bc7 100644 (file)
@@ -308,6 +308,16 @@ return [
                 'icon' => 'check',
                 'component' => 'a17-block-poll_check_item',
             ],
+            'poll_yes_no' => [
+                'title' => 'Oui / Non',
+                'icon' => 'check',
+                'component' => 'a17-block-poll_yes_no',
+            ],
+            'poll_rating' => [
+                'title' => 'Notation (0-10)',
+                'icon' => 'check',
+                'component' => 'a17-block-poll_rating',
+            ],
 
         ],
         'crops' => [
index 9499d6c14d565345ee04e6ed167c1742f429f0f4..eb948a0c05087f635c247a9016ce693e873b9044 100644 (file)
                     </div>
 
                     <div v-else>
+
+                        <div class="alert alert-info my-2" v-if="selected_question.type === 'poll_rating'">
+                            Le score moyen obtenu est de {{selected_question.mean}}
+                        </div>
+
                         <table class="table table-hover">
                             <thead class="thead-light">
                                 <tr>
diff --git a/resources/views/admin/blocks/poll_rating.blade.php b/resources/views/admin/blocks/poll_rating.blade.php
new file mode 100644 (file)
index 0000000..04acdf0
--- /dev/null
@@ -0,0 +1,9 @@
+@twillRepeaterTitle('Notation 0-10')
+@twillRepeaterGroup('app')
+
+@formField('input', [
+    'name' => 'question',
+    'label' => 'Question',
+    'maxlength' => 250,
+    'required' => true,
+])
diff --git a/resources/views/admin/blocks/poll_yes_no.blade.php b/resources/views/admin/blocks/poll_yes_no.blade.php
new file mode 100644 (file)
index 0000000..fc192bc
--- /dev/null
@@ -0,0 +1,9 @@
+@twillRepeaterTitle('Oui / Non')
+@twillRepeaterGroup('app')
+
+@formField('input', [
+    'name' => 'question',
+    'label' => 'Question',
+    'maxlength' => 250,
+    'required' => true,
+])
index aef467a986d2665bf72b616f7d1d1866c31377ad..583ea03dd78da6f91274cf7ff51c2edfe03be036 100644 (file)
@@ -7,7 +7,7 @@
         'maxlength' => 100
     ])
 
-    @formField('block_editor', ['blocks' => ['poll_text', 'poll_check', 'image']])
+    @formField('block_editor', ['blocks' => ['poll_text', 'poll_check', 'poll_yes_no', 'poll_rating', 'image']])
 
 
 
diff --git a/resources/views/site/blocks/poll_rating.blade.php b/resources/views/site/blocks/poll_rating.blade.php
new file mode 100644 (file)
index 0000000..cfc93e0
--- /dev/null
@@ -0,0 +1,20 @@
+@php
+    $slug = Str::slug($question = $block->input('question'))
+@endphp
+<div class="form-group">
+    <label for="{{$slug}}">{{$question}}</label>
+    <div>
+        @for($i = 0; $i <= 10; $i++)
+
+        <div class="form-check form-check-inline">
+            <input class="form-check-input" type="radio" name="{{$slug}}" id="answer-{{$i}}-{{$slug}}" value="{{$i}}">
+            <label class="form-check-label" for="answer-{{$i}}-{{$slug}}">
+                {{$i}}
+            </label>
+        </div>
+        @endfor
+
+    </div>
+
+
+</div>
diff --git a/resources/views/site/blocks/poll_yes_no.blade.php b/resources/views/site/blocks/poll_yes_no.blade.php
new file mode 100644 (file)
index 0000000..85daa92
--- /dev/null
@@ -0,0 +1,23 @@
+@php
+    $slug = Str::slug($question = $block->input('question'))
+@endphp
+<div class="form-group">
+    <label for="{{$slug}}">{{$question}}</label>
+    <div>
+        <div class="form-check form-check-inline">
+            <input class="form-check-input" type="radio" name="{{$slug}}" id="answer-yes-{{$slug}}" value="Oui">
+            <label class="form-check-label" for="answer-yes-{{$slug}}">
+                Oui
+            </label>
+        </div>
+        <div class="form-check form-check-inline">
+            <input class="form-check-input" type="radio" name="{{$slug}}" id="answer-no-{{$slug}}" value="Non">
+            <label class="form-check-label" for="answer-no-{{$slug}}">
+                Non
+            </label>
+        </div>
+
+    </div>
+
+
+</div>
index 43f1dce2beba830d37ae0c6b10432d71412665a6..5ca9c93f75f2c7ade577e43aa006a75d29672948 100644 (file)
@@ -1,4 +1,4 @@
-@extends('layouts.app', ['hideNav' => true])
+@extends('layouts.app', ['hideNav' => true, 'hideFooter' => true])
 
 @section('content')
     <article class="container">