Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Update) Polls System #1153

Merged
merged 17 commits into from
Feb 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions app/Http/Controllers/Staff/PollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,103 @@ public function store(StorePoll $request)
return redirect()->route('staff.polls.index')
->withSuccess('Your poll has been created.');
}

/**
* Poll Edit Form.
*
* @param $id
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function edit($id)
{
$poll = Poll::findOrFail($id);

return view('Staff.poll.edit', ['poll' => $poll]);
}

/**
* Update A New Poll.
*
* @param StorePoll $request
*
* @return Illuminate\Http\RedirectResponse
*/
public function update(StorePoll $request, $id)
{
$poll = Poll::findOrFail($id);

$poll->title = $request->input('title');

if ($request->input('multiple_choice')) {
$poll->multiple_choice = true;
} else {
$poll->multiple_choice = false;
}

// Remove the deleted options in poll
$oldOptionIds = collect($poll->options)->map(function ($option) {
return $option->id;
})->all();

$existingOldOptionIds = collect($request->input('option-id'))->map(function ($id) {
return intval($id);
})->all();

$idsOfOptionToBeRemove = array_diff($oldOptionIds, $existingOldOptionIds);

foreach ($idsOfOptionToBeRemove as $id) {
$option = Option::findOrFail($id);
$option->delete();
}

// Update existing options
$existingOldOptionContents = collect($request->input('option-content'))->map(function ($content) {
return strval($content);
})->all();

if (count($existingOldOptionContents) === count($existingOldOptionIds)) {
$len = count($existingOldOptionContents);
for ($i = 0; $i < $len; $i++) {
$option = Option::findOrFail($existingOldOptionIds[$i]);
$option->name = $existingOldOptionContents[$i];
$option->save();
}
}

// Insert new options
$newOptions = collect($request->input('new-option-content'))->map(function ($content) {
return new Option(['name' => $content]);
});

$poll->options()->saveMany($newOptions);

// Last work from store()
$poll_url = hrefPoll($poll);

$this->chat->systemMessage(
"A poll has been updated [url={$poll_url}]{$poll->title}[/url] vote on it now! :slight_smile:"
);

$poll->save();

return redirect()->route('staff.polls.index')
->withSuccess('Your poll has been edited.');
}

/**
* Delete A Poll.
*
* @param $id
*
* @return Illuminate\Http\RedirectResponse
*/
public function destroy($id)
{
$poll = Poll::findOrFail($id);
$poll->delete();

return redirect()->route('staff.polls.index')
->withSuccess('Poll has successfully been deleted');
}
}
3 changes: 0 additions & 3 deletions app/Models/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @property int $user_id
* @property string $title
* @property string $slug
* @property int $ip_checking
* @property int $multiple_choice
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
Expand All @@ -37,7 +36,6 @@
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Poll query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Poll whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Poll whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Poll whereIpChecking($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Poll whereMultipleChoice($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Poll whereSlug($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Poll whereTitle($value)
Expand All @@ -60,7 +58,6 @@ class Poll extends Model
protected $fillable = [
'title',
'slug',
'ip_checking',
'multiple_choice',
];

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddForeignKeyToOptionsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('options', function (Blueprint $table) {
$table->foreign('poll_id', 'fk_options_poll')->references('id')->on('polls')->onUpdate('RESTRICT')->onDelete('CASCADE');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('options', function (Blueprint $table) {
$table->dropForeign('fk_options_poll');
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class DropIpCheckingInPollsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('polls', function (Blueprint $table) {
$table->dropColumn('ip_checking');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('polls', function (Blueprint $table) {
$table->boolean('ip_checking')->default(0);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class DropIpAddressInVotersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('voters', function (Blueprint $table) {
$table->dropColumn('ip_address');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('voters', function (Blueprint $table) {
$table->string('ip_address')->default('dbRollback');
});
}
}
2 changes: 0 additions & 2 deletions resources/lang/ar/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'إنشاء استطلاع',
'current' => 'الاستطلاع الحالي',
'delete-option' => 'حذف الخيار',
'ip-checking' => 'هذا الاستطلاع مكررة التحقق من التصويت. يمكنك التصويت مرة واحدة فقط.',
'ip-checking-warrning' => 'هناك حاجة فقط إذا كان الموقع في الوضع العام',
'multiple-choice' => 'هذا استطلاع متعدد الاختيارات. حدد العديد من الإجابات التي تريدها.',
'option' => 'اختيار',
'poll' => 'تصويت',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/az/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Anket yaradın',
'current' => 'Cari Anket (lər)',
'delete-option' => 'Seçimi sil',
'ip-checking' => 'Bu sorğuda təkrarlanan səs yoxlanışı var. Yalnız bir dəfə səs verə bilərsiniz.',
'ip-checking-warrning' => 'Yalnız ictimai rejimdə site tələb olunur',
'multiple-choice' => 'Bu çoxsaylı seçki anketidir. Istədiyiniz qədər çox cavabı seçin.',
'option' => 'Seçim',
'poll' => 'Anket',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/be/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'стварыць апытанне',
'current' => 'Бягучы апытанне (ы)',
'delete-option' => 'выдаліць варыянт',
'ip-checking' => 'Гэты апытанне мае дублікат праверкі галасоў. Вы можаце прагаласаваць толькі адзін раз.',
'ip-checking-warrning' => 'Неабходна толькі, калі сайт у грамадскім рэжыме',
'multiple-choice' => 'Гэта множны выбар апытанне. Абярыце столькі адказаў, як вам падабаецца.',
'option' => 'варыянт',
'poll' => 'галасаванне',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/bg/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Създайте анкета',
'current' => 'Текущи анкети',
'delete-option' => 'Изтриване на опцията',
'ip-checking' => 'Тази анкета има проверка на дублирания вот. Можете да гласувате само веднъж.',
'ip-checking-warrning' => 'Необходимо е само ако сайтът е в публичен режим',
'multiple-choice' => 'Това е анкета с множествен избор. Изберете колкото искате отговори.',
'option' => 'опция',
'poll' => 'гласуване',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/bn/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'পোল তৈরি করুন',
'current' => 'বর্তমান পোল (গুলি)',
'delete-option' => 'অপশন মুছে দিন',
'ip-checking' => 'এই পোল সদৃশ ভোট পরীক্ষা আছে। আপনি শুধুমাত্র একবার ভোট দিতে পারেন।',
'ip-checking-warrning' => 'পাবলিক মোড সাইটে শুধুমাত্র প্রয়োজন হলে',
'multiple-choice' => 'এটি একটি একাধিক পছন্দ পোল। আপনি চান হিসাবে অনেক উত্তর নির্বাচন করুন।',
'option' => 'পছন্দ',
'poll' => 'ভোটগ্রহণ',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/bs/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Napravite anketu',
'current' => 'Trenutna anketa (e)',
'delete-option' => 'Izbriši opciju',
'ip-checking' => 'Ova anketa ima dvostruku provjeru glasova. Možete glasati samo jednom.',
'ip-checking-warrning' => 'Potrebno je samo ako je stranica u javnom modu',
'multiple-choice' => 'Ovo je anketa sa višestrukim izborom. Izaberite onoliko odgovora koliko želite.',
'option' => 'Opcija',
'poll' => 'Poll',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/ca/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Crea una enquesta',
'current' => 'Enquesta actual (s)',
'delete-option' => 'Esborra l’opció',
'ip-checking' => 'Aquesta enquesta té un control de vots duplicat. Només podeu votar una vegada.',
'ip-checking-warrning' => 'Només és necessari si el lloc es troba en mode públic',
'multiple-choice' => 'Aquesta és una enquesta d elecció múltiple. Seleccioneu tantes respostes com vulgueu.',
'option' => 'Opció',
'poll' => 'Enquesta',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/cs/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Vytvořit anketu',
'current' => 'Aktuální ankety',
'delete-option' => 'Možnost Odstranit',
'ip-checking' => 'Tato anketa má duplicitní kontrolu hlasování. Hlasovat můžete pouze jednou.',
'ip-checking-warrning' => 'Je potřeba pouze pokud je web ve veřejném režimu',
'multiple-choice' => 'Toto je anketa s více volbami. Vyberte tolik odpovědí, kolik chcete.',
'option' => 'Volba',
'poll' => 'Hlasování',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/cy/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Creu pôl',
'current' => 'Pôl (au) Cyfredol',
'delete-option' => 'Dileu opsiwn',
'ip-checking' => 'Mae r arolwg hwn wedi dyblygu pleidlais. Dim ond unwaith y gallwch bleidleisio.',
'ip-checking-warrning' => 'Dim ond ei angen os yw r safle ar ffurf gyhoeddus',
'multiple-choice' => 'Pôl aml-ddewis yw hwn. Dewiswch gymaint o atebion ag y dymunwch.',
'option' => 'Opsiwn',
'poll' => 'Pôl',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/da/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Opret afstemning',
'current' => 'Nuværende afstemning (r)',
'delete-option' => 'Slet valgmulighed',
'ip-checking' => 'Denne afstemning har dobbelt stemme kontrol. Du kan kun stemme en gang.',
'ip-checking-warrning' => 'Kun nødvendig, hvis webstedet er i offentlig tilstand',
'multiple-choice' => 'Dette er en multiple choice poll. Vælg så mange svar som du vil.',
'option' => 'Mulighed',
'poll' => 'Afstemning',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/de/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Umfrage erstellen',
'current' => 'Aktuelle Umfrage (n)',
'delete-option' => 'Option löschen',
'ip-checking' => 'Diese Umfrage hat eine doppelte Stimmprüfung. Sie können nur einmal abstimmen.',
'ip-checking-warrning' => 'Wird nur benötigt, wenn die Site im öffentlichen Modus ist',
'multiple-choice' => 'Dies ist eine Multiple-Choice-Umfrage. Wählen Sie so viele Antworten aus, wie Sie möchten.',
'option' => 'Möglichkeit',
'poll' => 'Umfrage',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/el/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Δημιουργία δημοσκόπησης',
'current' => 'Τρέχουσα δημοσκόπηση',
'delete-option' => 'Διαγραφή επιλογής',
'ip-checking' => 'Αυτή η δημοσκόπηση έχει διπλό έλεγχο ψηφοφορίας. Μπορείτε να ψηφίζετε μόνο μία φορά.',
'ip-checking-warrning' => 'Απαιτείται μόνο αν το site βρίσκεται σε κατάσταση δημόσιας προβολής',
'multiple-choice' => 'Αυτή είναι μια δημοσκόπηση πολλαπλών επιλογών. Επιλέξτε όσες απαντήσεις θέλετε.',
'option' => 'Επιλογή',
'poll' => 'Ψηφοφορία',
Expand Down
3 changes: 0 additions & 3 deletions resources/lang/en/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
'current' => 'Current Poll(s)',
'delete-option' => 'Delete Option',
'edit-poll' => 'Edit Poll',
'ip-checking' => 'Enable Duplicate IP Checking',
'ip-checking' => 'This poll has duplicate vote checking. You can only vote once.',
'ip-checking-warrning' => 'Only needed if site is in public mode',
'multiple-choice' => 'Allow Multiple Answers',
'multiple-choice' => 'This is a multiple choice poll. Select as many answers as you like.',
'option' => 'Option',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/es/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Crear encuesta',
'current' => 'Encuesta(s) actual(es)',
'delete-option' => 'Opción de eliminar',
'ip-checking' => 'Esta encuesta tiene la verificación de votos duplicados. Solo puedes votar una vez.',
'ip-checking-warrning' => 'Solo es necesario si el sitio está en modo público.',
'multiple-choice' => 'Esta es una encuesta de opción múltiple. Selecciona tantas respuestas como quieras.',
'option' => 'Opción',
'poll' => 'Encuesta',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/et/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Loo küsitlus',
'current' => 'Praegune küsitlus',
'delete-option' => 'Kustuta valik',
'ip-checking' => 'Sellel küsitlusel on kahekordne hääletuskontroll. Te saate hääletada ainult üks kord.',
'ip-checking-warrning' => 'Vajalik ainult siis, kui sait on avalikus režiimis',
'multiple-choice' => 'See on mitme valiku küsitlus. Valige nii palju vastuseid kui soovite.',
'option' => 'Võimalus',
'poll' => 'Küsitlus',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/eu/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Sortu inkesta',
'current' => 'Oraingo inkesta (k)',
'delete-option' => 'Ezabatu aukera',
'ip-checking' => 'Inkesta honek boto bikoiztuaren egiaztapena du. Behin botoa eman dezakezu.',
'ip-checking-warrning' => 'Modu publikoan gunea baldin badago bakarrik behar da',
'multiple-choice' => 'Aukera anitzeko inkesta da. Hautatu nahi dituzun erantzunak.',
'option' => 'aukera',
'poll' => 'inkesta',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/fa/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'ایجاد نظرسنجی',
'current' => 'نظرسنجی فعلی',
'delete-option' => 'گزینه را حذف کنید',
'ip-checking' => 'این نظرسنجی دارای رأی گیری تکراری است. شما فقط می توانید یک بار رأی دهید',
'ip-checking-warrning' => 'فقط اگر سایت در حالت عمومی مورد نیاز باشد',
'multiple-choice' => 'این نظرسنجی چند گزینه ای است. به عنوان بسیاری از پاسخ را انتخاب کنید که دوست دارید.',
'option' => 'گزینه',
'poll' => 'نظرسنجی',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/fi/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Luo kysely',
'current' => 'Nykyinen kysely (t)',
'delete-option' => 'Poista vaihtoehto',
'ip-checking' => 'Tällä kyselyllä on kaksinkertainen äänestys. Voit äänestää vain kerran.',
'ip-checking-warrning' => 'Tarvitaan vain, jos sivusto on julkisessa tilassa',
'multiple-choice' => 'Tämä on monivalintakysely. Valitse niin monta vastausta kuin haluat.',
'option' => 'Vaihtoehto',
'poll' => 'äänestys',
Expand Down
2 changes: 0 additions & 2 deletions resources/lang/fr/poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
'create-poll' => 'Créer un sondage',
'current' => 'Sondage (s) actuel (s)',
'delete-option' => 'Supprimer l option',
'ip-checking' => 'Ce sondage a une vérification de vote en double. Vous pouvez voter seulement une fois.',
'ip-checking-warrning' => 'Nécessaire uniquement si le site est en mode public',
'multiple-choice' => 'Ceci est un sondage à choix multiples. Sélectionnez autant de réponses que vous le souhaitez.',
'option' => 'Option',
'poll' => 'Sondage',
Expand Down
Loading