Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function updateEvaluationPeriod(Request $request): RedirectResponse

$this->updatePeriodicEvent($semester, $startDate, $endDate);

// setting start and end dates of questions
// updating start and end dates of questions
$semester->questions()->update([
'opened_at' => $startDate,
'closed_at' => $endDate
Expand Down Expand Up @@ -136,6 +136,9 @@ public function show()
$this->authorize('fillOrManage', SemesterEvaluation::class);

return view('secretariat.evaluation-form.app', [
// let the current semester be found based on the periodic event itself
// we can safely assume it is not null
'semester' => app(\App\Http\Controllers\Secretariat\SemesterEvaluationController::class)->semester(),

Copy link
Copy Markdown
Contributor Author

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().

'phd' => user()->educationalInformation->studyLines()->currentlyEnrolled()->where('type', 'phd')->exists(),
'user' => user(),
'faculties' => Faculty::all(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -27,8 +29,7 @@ class AnonymousQuestionController extends Controller
*/
public function __construct()
{
$this->underlyingControllerName =
\App\Http\Controllers\Secretariat\SemesterEvaluationController::class;
$this->underlyingControllerName = SemesterEvaluationController::class;
}

/**
Expand All @@ -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');
Comment thread
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',
Expand All @@ -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) {
Expand All @@ -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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The redirect route anonymous_questions.index_semesters appears to be outdated or incorrect as per the changes in this PR which suggest a simplification of route names.

- return redirect()->route('anonymous_questions.index_semesters')
+ return redirect()->route('anonymous_questions.index')

This change aligns the redirection with the updated routing structure.

Committable suggestion was skipped due to low confidence.

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");
}
Comment thread
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(),
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions app/Models/Question.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function hasVoted(User $user): bool
* if the user has already answered the question
* or if a long textual answer is provided for a question which does not support it.
*/
public function storeAnswers(User $user, QuestionOption|array|string $answer, ?AnswerSheet $answerSheet = null): void
public function storeAnswers(User $user, QuestionOption|array|string|null $answer, ?AnswerSheet $answerSheet = null): void
{
// the additional check is needed for the seeder
if (!$this->isOpen() && (!app()->runningInConsole() || app()->runningUnitTests())) {
Expand Down Expand Up @@ -225,7 +225,7 @@ public function storeAnswers(User $user, QuestionOption|array|string $answer, ?A
]);
}
}
} // else it is a string
} // else it is a string or null for a question with long answers
elseif (!$this->has_long_answers) {
throw new Exception("This question does not support long answers");
} else {
Expand Down Expand Up @@ -262,7 +262,7 @@ public function validationRules(): array
$key = $this->formKey();
$rules = [];
if ($this->has_long_answers) {
$rules[$key] = 'required|string';
$rules[$key] = 'nullable|string';
} elseif ($this->isMultipleChoice()) {
$rules[$key] = [
'required',
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Semester.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function isActive($user)
*/
public function transactions(): HasMany
{
return $this->hasMany(App\Models\Transaction::class, 'semester_id');
return $this->hasMany(\App\Models\Transaction::class, 'semester_id');
}

public function communityServices(): HasMany
Expand All @@ -247,7 +247,7 @@ public function transactionsInCheckout(Checkout $checkout)
*/
public function workshopBalances(): HasMany
{
return $this->hasMany(App\Models\WorkshopBalance::class);
return $this->hasMany(\App\Models\WorkshopBalance::class);
}

/**
Expand Down
17 changes: 0 additions & 17 deletions app/Utils/HasPeriodicEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,6 @@ final public function periodicEvent(): ?PeriodicEvent
->first();
}

/**
* Get the PeriodicEvent connected to the controller
* and belonging to the given semester
* (by default the current one).
*
* @return PeriodicEvent|null
*/
final public function periodicEventForSemester(?Semester $semester): ?PeriodicEvent
{
if (is_null($semester)) {
$semester = Semester::current();
}
return PeriodicEvent::where('event_model', $this->underlyingControllerName)
->where('semester_id', $semester->id)
->first();
}

/**
* Create or update the current PeriodicEvent connected to the model.
* Make sure the $data is properly validated:
Expand Down
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();
});
}
};
5 changes: 5 additions & 0 deletions resources/lang/en/anonymous_questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
'all_questions_filled' => 'You have filled all these questions; thank you!',
'anonymous_questions' => 'Anonymous questions',
'create_question' => 'Create question',
'creation_for_current_only' => 'Creating new questions is allowed only for the semester
for which the current evaluation form has been created.<br />
If you cannot create a question,
simply <a href="/secretariat/evaluation">save the form</a> for the correct semester
with a future start date.',
'export' => 'Export',
'has_long_answers' => 'expects long, written answers',
'information_text' => "The following questions are going to be used to assess
Expand Down
6 changes: 6 additions & 0 deletions resources/lang/hu/anonymous_questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
'all_questions_filled' => 'Már kitöltötted ezeket a kérdéseket; köszönjük!',
'anonymous_questions' => 'Anonim visszajelzések',
'create_question' => 'Kérdés hozzáadása',
'creation_for_current_only' => 'Csak ahhoz a szemeszterhez tudsz kérdést létrehozni,
amihez az aktuális értékelő kérdőív tartozik.<br />
Ha a rendszer nem enged kérdést létrehozni,
egyszerűen <a href="/secretariat/evaluation">mentsd el a formot</a>
a megfelelő félévhez,
akár egy jövőbeli megnyitási időponttal.',
'export' => 'Exportálás',
'has_long_answers' => 'kifejtős',
'information_text' => "Ezek a visszajelzések a Választmánynak segítenek,
Expand Down
2 changes: 1 addition & 1 deletion resources/views/layouts/navbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class="material-icons left">person_search</i>Felvételi</a></li>
{{-- results of anonymous questions --}}
@can('administer', \App\Models\AnonymousQuestions\AnswerSheet::class)
<li>
<a class="waves-effect" href="{{ route('anonymous_questions.index_semesters') }}">
<a class="waves-effect" href="{{ route('anonymous_questions.index') }}">
<i class="material-icons left">assessment</i>
@lang('anonymous_questions.anonymous_questions')
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<blockquote>
@lang('anonymous_questions.information_text')
</blockquote>
<form method="POST" action="{{ route('anonymous_questions.store_answer_sheet', App\Models\Semester::current()) }}">

<form method="POST" action="{{ route('anonymous_questions.store_answers', $semester) }}">
@csrf
<input type="hidden" name="section" value="anonymous_questions">

@php
// We only take the questions that have been answered.
$questions = App\Models\Semester::current()->questionsNotAnsweredBy(user());
$questions = $semester->questionsNotAnsweredBy(user());
@endphp

@if ($questions->isEmpty())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@extends('layouts.app')

@section('title')
<a href="{{route('anonymous_questions.index_semesters')}}" class="breadcrumb" style="cursor: pointer">@lang('anonymous_questions.anonymous_questions')</a>
<a href="{{route('anonymous_questions.index_semesters')}}" class="breadcrumb" style="cursor: pointer">{{ $semester->tag }}</a>
<a href="{{route('anonymous_questions.index')}}" class="breadcrumb" style="cursor: pointer">@lang('anonymous_questions.anonymous_questions')</a>
<a href="#!" class="breadcrumb">@lang('anonymous_questions.create_question')</a>

@endsection
Expand All @@ -13,13 +12,13 @@
<div class="row">
<div class="col s12">
<div class="card">
<form action="{{route('anonymous_questions.store', ['semester' => $semester])}}" method="POST">
<form action="{{route('anonymous_questions.store')}}" method="POST">
@csrf

@include('utils.question_card', ['canHaveLongAnswers' => true])

<div class="card-action right-align">
<a href="{{route('anonymous_questions.index', $semester)}}" class="waves-effect btn">@lang('general.cancel')</a>
<a href="{{route('anonymous_questions.index')}}" class="waves-effect btn">@lang('general.cancel')</a>
<button type="submit" class="waves-effect btn">@lang('general.save')</button>
</div>
</form>
Expand Down
Loading