-
Notifications
You must be signed in to change notification settings - Fork 14
Suggestions to use periodicEvents for AnonymousQuestions #554
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
base: development
Are you sure you want to change the base?
Changes from all commits
1c74af1
8eb614e
18b3041
bdf8f3a
a0a4cdc
9085d63
4fedf40
78af51b
6932d44
a95736f
5c37f2a
42ab4dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,19 +3,21 @@ | |
| namespace App\Http\Controllers\StudentsCouncil; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Carbon\Carbon; | ||
| use App\Http\Controllers\Controller; | ||
| use Illuminate\Support\Facades\Validator; | ||
| use Illuminate\Support\Facades\DB; | ||
| use Illuminate\Support\Facades\Validator; | ||
| use Maatwebsite\Excel\Facades\Excel; | ||
|
|
||
| use App\Models\AnonymousQuestions\AnswerSheet; | ||
| use App\Models\PeriodicEvent; | ||
| use App\Models\Semester; | ||
| use App\Models\Question; | ||
| use App\Models\QuestionOption; | ||
| use App\Utils\HasPeriodicEvent; | ||
| use App\Exports\UsersSheets\AnonymousQuestionsExport; | ||
|
|
||
| use App\Http\Controllers\Secretariat\SemesterEvaluationController; | ||
|
|
||
| /** | ||
| * Controls actions related to anonymous questions. | ||
| */ | ||
|
|
@@ -27,8 +29,7 @@ class AnonymousQuestionController extends Controller | |
| */ | ||
| public function __construct() | ||
| { | ||
| $this->underlyingControllerName = | ||
| \App\Http\Controllers\Secretariat\SemesterEvaluationController::class; | ||
| $this->underlyingControllerName = SemesterEvaluationController::class; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -37,38 +38,51 @@ public function __construct() | |
| * the list of questions | ||
| * and the option to add new ones. | ||
| */ | ||
| public function indexSemesters() | ||
| public function index() | ||
| { | ||
| $this->authorize('administer', AnswerSheet::class); | ||
|
|
||
| return view('student-council.anonymous-questions.index_semesters'); | ||
| return view('student-council.anonymous-questions.index'); | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether the form exists and has not yet been closed; | ||
| * aborts the request if necessary. | ||
| * If successful, it returns the periodic event. | ||
| */ | ||
| private function checkPeriodicEvent(): PeriodicEvent | ||
| { | ||
| $periodicEvent = $this->periodicEvent(); | ||
| if (is_null($periodicEvent)) { | ||
| abort(404, "no evaluation form exists yet"); | ||
| } elseif ($periodicEvent->endDate()?->isPast() ?? false) { | ||
| abort(403, "tried to add a question to a closed form"); | ||
| } else { | ||
| return $periodicEvent; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns the 'new question' page. | ||
| */ | ||
| public function create(Semester $semester) | ||
| public function create() | ||
| { | ||
| $this->authorize('administer', AnswerSheet::class); | ||
| $this->checkPeriodicEvent(); | ||
|
|
||
| if ($semester->isClosed()) { | ||
| abort(403, "tried to add a question to a closed semester"); | ||
| } | ||
| return view('student-council.anonymous-questions.create', [ | ||
| "semester" => $semester | ||
| ]); | ||
| return view('student-council.anonymous-questions.create'); | ||
|
viktorcsimma marked this conversation as resolved.
|
||
| } | ||
|
|
||
| /** | ||
| * Saves a new question. | ||
| * Saves a new question for the semester | ||
| * to which the current evaluation form belongs. | ||
| */ | ||
| public function store(Request $request, Semester $semester) | ||
| public function store(Request $request) | ||
| { | ||
| $this->authorize('administer', AnswerSheet::class); | ||
|
|
||
| if ($semester->isClosed()) { | ||
| abort(403, "tried to add a question to a closed semester"); | ||
| } | ||
| $periodicEvent = $this->checkPeriodicEvent(); | ||
| $semester = $periodicEvent->semester; | ||
|
|
||
| $validator = Validator::make($request->all(), [ | ||
| 'title' => 'required|string', | ||
|
|
@@ -90,14 +104,12 @@ public function store(Request $request, Semester $semester) | |
| } | ||
| $validator->validate(); | ||
|
|
||
| $event = $this->periodicEventForSemester($semester); | ||
|
|
||
| $question = $semester->questions()->create([ | ||
| 'title' => $request->title, | ||
| 'max_options' => $hasLongAnswers ? 0 : $request->max_options, | ||
| 'has_long_answers' => $hasLongAnswers, | ||
| 'opened_at' => $event?->start_date ?? null, | ||
| 'closed_at' => $event?->end_date ?? null | ||
| 'opened_at' => $periodicEvent->startDate(), | ||
| 'closed_at' => $periodicEvent->endDate() | ||
| ]); | ||
| if (!$hasLongAnswers) { | ||
| foreach ($options as $option) { | ||
|
|
@@ -108,31 +120,27 @@ public function store(Request $request, Semester $semester) | |
| } | ||
| } | ||
|
|
||
| session()->put('section', $semester->id); | ||
| return redirect()->route('anonymous_questions.index_semesters') | ||
| //session()->put('section', $semester->id); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The redirect route - return redirect()->route('anonymous_questions.index_semesters')
+ return redirect()->route('anonymous_questions.index')This change aligns the redirection with the updated routing structure.
|
||
| return redirect()->route('anonymous_questions.index') | ||
| ->with('message', __('general.successful_modification')); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a page with the options (and results, if authorized) of a question. | ||
| */ | ||
| public function show(Semester $semester, Question $question) | ||
| { | ||
| $this->authorize('administer', AnswerSheet::class); | ||
|
|
||
| return view('anonymous_questions.show', [ | ||
| "question" => $question | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Stores the answers given by a user. | ||
| * Handles all questions at once | ||
| * and creates an answer sheet for them. | ||
| */ | ||
| public function storeAnswerSheet(Request $request, Semester $semester) | ||
| public function storeAnswers(Request $request) | ||
| { | ||
| $this->authorize('is-collegist'); | ||
| $semester = $this->semester(); //semester connected to periodicEvent | ||
|
|
||
| if (!$this->isActive()) { | ||
| abort(403, "tried to save an answer when the questionnaire is not open"); | ||
| } | ||
|
viktorcsimma marked this conversation as resolved.
|
||
|
|
||
| // Answers for all available questions are stored each time, grouped to an answerSheet. | ||
| // However, the available questions might change. | ||
|
|
||
| $validator = Validator::make( | ||
| $request->all(), | ||
|
|
@@ -184,7 +192,7 @@ function (int $id) {return QuestionOption::find($id);}, | |
| * Returns an Excel sheet containing all the answers | ||
| * to the questions of a given semester. | ||
| */ | ||
| public function exportAnswerSheets(Semester $semester) | ||
| public function exportAnswers(Semester $semester) | ||
| { | ||
| $this->authorize('administer', AnswerSheet::class); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <?php | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
| use Illuminate\Support\Facades\DB; | ||
|
|
||
| return new class () extends Migration { | ||
| /** | ||
| * Run the migrations. | ||
| */ | ||
| public function up(): void | ||
| { | ||
| Schema::table('long_answers', function (Blueprint $table) { | ||
| $table->text('text')->nullable()->change(); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Reverse the migrations. | ||
| */ | ||
| public function down(): void | ||
| { | ||
| DB::table('long_answers')->whereNull('text')->update(['text' => '-']); // a dash | ||
| Schema::table('long_answers', function (Blueprint $table) { | ||
| $table->text('text')->nullable(false)->change(); | ||
| }); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are already in the controlller. Use $this->semester().