verification for seats left and already registered students added

This commit is contained in:
s416422 2020-01-17 23:29:28 +01:00
parent e6a11127c8
commit 25d7ea4fe3
4 changed files with 111 additions and 59 deletions

View File

@ -123,43 +123,63 @@ class UserClassesController extends Controller
$student_name = $request->input('student_name');
$student_surname = $request->input('student_surname');
$classes = Classes::find($request->get('classes_id'));
$subject = Subject::find($classes->subject_id);
$room_capacity = Room::find($subject->room_id)->capacity;
$attendances = Attendance::where('classes_id', $classes->id)->get();
$student_ids = $attendances->pluck('student_id_number')->toArray();
$seat_numbers = $attendances->pluck('seat_number')->toArray();
if($classes->mode == 'quick') {
Attendance::create([
'classes_id' => $classes->id,
'student_id_number' => $student_id_number,
'student_name' => $student_name,
'student_surname' => $student_surname,
'seat_number' => null
]);
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => null, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'mode' => $classes->mode]);
if(in_array($student_id_number, $student_ids)) { // if student attendance record already exists
$student_seat_number = Attendance::where('student_id_number', $student_id_number)->first()->seat_number;
$warning = 'Ten numer indeksu został już wcześniej zapisany na te zajęcia.';
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $student_seat_number, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'mode' => $classes->mode, 'warning' => $warning]);
} else {
$attendances = Attendance::where('classes_id', $classes->id)->get();
$seat_numbers = $attendances->pluck('seat_number')->toArray();
$subject = Subject::find($classes->subject_id);
$room_arrangement = Room::find($subject->room_id)->arrangement;
if(!$room_arrangement) {
$room_arrangement = Room::where('name', 'Inna sala')->first()->arrangement;
}
$room_rows = count(explode("++", $room_arrangement));
if($room_rows > 4) { //max 4 rows on one page
$multi_parts = true;
$parts_number = ceil($room_rows/4);
if (count($seat_numbers) >= $room_capacity) { // if there are no more free seats in room, add student without assigning seat number (regardless of the classes mode)
Attendance::create([
'classes_id' => $classes->id,
'student_id_number' => $student_id_number,
'student_name' => $student_name,
'student_surname' => $student_surname,
'seat_number' => null
]);
$warning = "Zostałeś zapisany na listę obecności, ale bez przyznanego miejsca.";
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => null, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'mode' => $classes->mode, 'warning' => $warning]);
} else {
$multi_parts = false;
$parts_number = 1;
}
if ($classes->mode == 'quick') {
Attendance::create([
'classes_id' => $classes->id,
'student_id_number' => $student_id_number,
'student_name' => $student_name,
'student_surname' => $student_surname,
'seat_number' => null
]);
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => null, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'mode' => $classes->mode, 'warning' => null]);
} else {
// prepare seat map
$room_arrangement = Room::find($subject->room_id)->arrangement;
if (!$room_arrangement) {
$room_arrangement = Room::where('name', 'Inna sala')->first()->arrangement;
}
$room_rows = count(explode("++", $room_arrangement));
if ($room_rows > 4) { //max 4 rows on one page
$multi_parts = true;
$parts_number = ceil($room_rows / 4);
} else {
$multi_parts = false;
$parts_number = 1;
}
if($classes->mode == 'test') {
$room_capacity = Room::find($subject->room_id)->capacity;
$random_seat = rand(1, $room_capacity);
while(in_array($random_seat, $seat_numbers)) {
$random_seat = rand(1, $room_capacity);
if ($classes->mode == 'test') {
$random_seat = rand(1, $room_capacity);
while (in_array($random_seat, $seat_numbers)) {
$random_seat = rand(1, $room_capacity);
}
return view('map.seat_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $random_seat, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'seat_numbers' => $seat_numbers, 'room_arrangement' => $room_arrangement, 'multi_parts' => $multi_parts, 'parts_number' => $parts_number, 'mode' => 'test', 'random_seat' => $random_seat]);
} else {
return view('map.seat_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'seat_numbers' => $seat_numbers, 'room_arrangement' => $room_arrangement, 'multi_parts' => $multi_parts, 'parts_number' => $parts_number, 'mode' => null]);
}
}
return view('map.seat_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $random_seat, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'seat_numbers' => $seat_numbers, 'room_arrangement' => $room_arrangement, 'multi_parts' => $multi_parts, 'parts_number' =>$parts_number, 'mode' => 'test', 'random_seat' => $random_seat]);
}
return view('map.seat_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'student_id_number' => $student_id_number, 'classes_id' => $classes->id, 'seat_numbers' => $seat_numbers, 'room_arrangement' => $room_arrangement, 'multi_parts' => $multi_parts, 'parts_number' =>$parts_number, 'mode' => null]);
}
}
@ -177,7 +197,7 @@ class UserClassesController extends Controller
'student_surname' => $student_surname,
'seat_number' => $seat_number
]);
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $seat_number, 'student_id_number' => $student_id_number, 'classes_id' => $classes_id, 'mode' => null]);
return view('map.summary_map', ['student_name' => $student_name, 'student_surname' => $student_surname, 'seat_number' => $seat_number, 'student_id_number' => $student_id_number, 'classes_id' => $classes_id, 'mode' => null, 'warning' => null]);
}
public function preview_classes($classes_id, $orderBy='student_surname', $orderDirection='ASC')

View File

@ -5,34 +5,37 @@ function assignPlaces() {
const seat_number = $(this).attr('id').split('++')[0];
const name = $(this).attr('id').split('++')[1];
const surname = $(this).attr('id').split('++')[2];
let map_seat = '';
if(!multi_parts) {
map_seat = $('#seat-map').find(`#${seat_number}`);
} else {
const parts_number = $('#multi_parts_number').val();
let index = 0;
map_seat = $('#seat-map-0').find(`#${seat_number}`);
while (!map_seat.length && index < parts_number) {
index++;
map_seat = $(`#seat-map-${index}`).find(`#${seat_number}`);
if(seat_number) {
let map_seat = '';
if(!multi_parts) {
map_seat = $('#seat-map').find(`#${seat_number}`);
} else {
const parts_number = $('#multi_parts_number').val();
let index = 0;
map_seat = $('#seat-map-0').find(`#${seat_number}`);
while (!map_seat.length && index < parts_number) {
index++;
map_seat = $(`#seat-map-${index}`).find(`#${seat_number}`);
}
}
if(map_seat.length) {
map_seat.html(`<b>${seat_number}</b> <br><span class="preview-name">${name} ${surname}</span>`);
map_seat.on('mouseover', () => {
map_seat.css('backgroundColor', 'lightgrey');
$(this).css('backgroundColor', 'lightgrey');
}).on('mouseleave', () => {
map_seat.css('backgroundColor', '#649a24');
$(this).css('backgroundColor', 'unset');
});
$(this).on('mouseover', () => {
map_seat.css('backgroundColor', 'lightgrey');
$(this).css('backgroundColor', 'lightgrey');
}).on('mouseleave', () => {
map_seat.css('backgroundColor', '#649a24');
$(this).css('backgroundColor', 'unset');
})
}
}
console.log(map_seat);
map_seat.html(`<b>${seat_number}</b> <br><span class="preview-name">${name} ${surname}</span>`);
map_seat.on('mouseover', () => {
map_seat.css('backgroundColor', 'lightgrey');
$(this).css('backgroundColor', 'lightgrey');
}).on('mouseleave', () => {
map_seat.css('backgroundColor', '#649a24');
$(this).css('backgroundColor', 'unset');
});
$(this).on('mouseover', () => {
map_seat.css('backgroundColor', 'lightgrey');
$(this).css('backgroundColor', 'lightgrey');
}).on('mouseleave', () => {
map_seat.css('backgroundColor', '#649a24');
$(this).css('backgroundColor', 'unset');
})
})
}

View File

@ -34,6 +34,27 @@
<button type="submit" id="submit" class="checkout-button"> Dodaj studenta </button>
</form>
</div>
<div class="modal fade" id="already-exist-modal" tabindex="-1" role="dialog" aria-labelledby="already-exist-modal" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5>Taki student już istnieje</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p> Student <span class="student"></span> już istnieje </p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" title="OK"> OK </button>
</div>
</div>
</div>
</div>
<script>
var classes_code_input = $('#classes_code_input').html();
const client = new WebSocket('ws://127.0.0.1:8888', classes_code_input);

View File

@ -10,9 +10,17 @@
<div class="map-buttons">
<a href="{{ route('user_classes') }}" class="checkout-button end-button"> Zakończ zapisy </a>
</div>
<h1> Zostałeś poprawnie zapisany.</h1>
@if($warning)
<h1> {{ $warning }} </h1>
@else
<h1> Zostałeś poprawnie zapisany.</h1>
@endif
<br><br>
<h2> {{ $student_name }} {{ $student_surname }} </h2>
<br><br>
<h3> {{ $student_id_number }} </h3>
<br><br>
@if(!$mode == "quick")
<h3> miejsce: </h3>
<ul id="sel-seat"> {{ $seat_number }} </ul>