Compare commits
No commits in common. "master" and "feature/task-fixes" have entirely different histories.
master
...
feature/ta
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Grade;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class AddScores extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'app:add-scores {grade}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Add 4 and 5 scores for students';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$grade = Grade::firstWhere('id', $this->argument('grade'));
|
||||
|
||||
$grade->students->random(7)->each(function ($student) {
|
||||
$student
|
||||
->lessons()
|
||||
->syncWithPivotValues($student->lessons()->pluck('id'), ['score' => 4]);
|
||||
});
|
||||
|
||||
$grade->students->random(5)->each(function ($student) {
|
||||
$student
|
||||
->lessons()
|
||||
->syncWithPivotValues($student->lessons()->pluck('id'), ['score' => 5]);
|
||||
});
|
||||
}
|
||||
}
|
@ -69,7 +69,7 @@ class GradeController extends Controller
|
||||
*/
|
||||
public function edit(Grade $grade): View
|
||||
{
|
||||
if(request()->user()->cannot('update', $grade)) {
|
||||
if(request()->user()->cannot('update', Grade::class)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
@ -83,13 +83,11 @@ class GradeController extends Controller
|
||||
*/
|
||||
public function update(GradePostRequest $request, Grade $grade): RedirectResponse
|
||||
{
|
||||
if(request()->user()->cannot('update', $grade)) {
|
||||
if(request()->user()->cannot('update', Grade::class)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$grade->update($request->validated());
|
||||
|
||||
return redirect()->route('grades.show', $grade);
|
||||
return redirect()->route('grades.show', $grade->update($request->validated()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,10 +95,9 @@ class GradeController extends Controller
|
||||
*/
|
||||
public function destroy(Grade $grade): RedirectResponse
|
||||
{
|
||||
if(request()->user()->cannot('delete', $grade)) {
|
||||
if(request()->user()->cannot('delete', Grade::class)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$grade->delete();
|
||||
|
||||
return redirect()->route('grades.index');
|
||||
|
@ -113,9 +113,12 @@ class LessonController extends Controller
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$lesson->update($request->validated());
|
||||
|
||||
return redirect()->route('grades.lessons.show',[$grade, $lesson,]);
|
||||
return redirect()->route(
|
||||
'grades.lessons.show',[
|
||||
$grade,
|
||||
$lesson->update($request->validated()),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,6 @@ use App\Http\Requests\StudentPostRequest;
|
||||
use App\Models\Grade;
|
||||
use App\Models\Student;
|
||||
use App\Models\Subject;
|
||||
use App\Services\FileService;
|
||||
use App\Services\StudentService;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\View\View;
|
||||
@ -135,9 +134,4 @@ class StudentController extends Controller
|
||||
'lessons' => $service->getDebts(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function exportAvgScores(StudentService $service)
|
||||
{
|
||||
return $service->exportAvgScores();
|
||||
}
|
||||
}
|
||||
|
@ -82,9 +82,10 @@ class SubjectController extends Controller
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$subject->update($request->validated());
|
||||
|
||||
return redirect()->route('subjects.show', $subject);
|
||||
return redirect()->route(
|
||||
'subjects.show',
|
||||
$subject->update($request->validated())
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,6 @@ use App\Models\Admin;
|
||||
use App\Models\Grade;
|
||||
use App\Models\Lesson;
|
||||
use App\Models\Student;
|
||||
use App\Models\Teacher;
|
||||
use App\Models\User;
|
||||
|
||||
class LessonPolicy
|
||||
@ -14,9 +13,9 @@ class LessonPolicy
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
public function viewAny(User $user, Grade $grade): bool
|
||||
{
|
||||
return $user->userable_type == Teacher::class;
|
||||
return $user->userable_type != Student::class || $user->userable->grade_id == $grade->id;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,7 +23,7 @@ class LessonPolicy
|
||||
*/
|
||||
public function view(User $user, Lesson $lesson): bool
|
||||
{
|
||||
return $user->userable_type == Teacher::class;
|
||||
return $user->userable_type != Student::class || $user->userable->grade_id == $lesson->grade_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -32,7 +31,7 @@ class LessonPolicy
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
return $user->userable_type == Teacher::class;
|
||||
return $user->userable_type != Student::class;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -40,7 +39,7 @@ class LessonPolicy
|
||||
*/
|
||||
public function update(User $user, Lesson $lesson): bool
|
||||
{
|
||||
return $user->userable_type == Teacher::class;
|
||||
return $user->userable_type != Student::class;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -48,6 +47,6 @@ class LessonPolicy
|
||||
*/
|
||||
public function delete(User $user, Lesson $lesson): bool
|
||||
{
|
||||
return $user->userable_type == Teacher::class;
|
||||
return $user->userable_type != Student::class;
|
||||
}
|
||||
}
|
||||
|
@ -52,9 +52,4 @@ class StudentPolicy
|
||||
{
|
||||
return $user->userable_type == Student::class;
|
||||
}
|
||||
|
||||
public function avgScores(User $user): bool
|
||||
{
|
||||
return $user->userable_type == Student::class;
|
||||
}
|
||||
}
|
||||
|
@ -42,9 +42,4 @@ class SubjectPolicy
|
||||
{
|
||||
return $user->userable_type == Student::class;
|
||||
}
|
||||
|
||||
public function pdf(User $user): bool
|
||||
{
|
||||
return $user->userable_type == Student::class;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use App\Enums\ScoreEnum;
|
||||
use App\Models\Student;
|
||||
use App\Models\Subject;
|
||||
use App\Models\User;
|
||||
use Barryvdh\DomPDF\Facade\Pdf;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@ -83,18 +82,4 @@ class StudentService
|
||||
|
||||
return $student->lessons()->whereIn('score', ScoreEnum::getDebtScores())->get();
|
||||
}
|
||||
|
||||
public function exportAvgScores()
|
||||
{
|
||||
$subjects = Auth::user()->userable->grade->subjects;
|
||||
$avgScores = collect();
|
||||
|
||||
$subjects->each(function ($subject) use ($avgScores) {
|
||||
$avgScores->put($subject->name, $this->getAvgScore($subject));
|
||||
});
|
||||
|
||||
return Pdf::loadView('students.avg-scores', [
|
||||
'avgScores' => $avgScores,
|
||||
])->download('Успеваемость.pdf');
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ return [
|
||||
|
||||
'commands' => [
|
||||
App\Console\Commands\AddAdmin::class,
|
||||
App\Console\Commands\AddScores::class,
|
||||
],
|
||||
|
||||
/*
|
||||
|
@ -36,13 +36,11 @@
|
||||
class="btn btn-block col-8">{{ $grade->name }}</a>
|
||||
</div>
|
||||
</td>
|
||||
@can('viewAny', \App\Models\Lesson::class)
|
||||
<td>
|
||||
<div>
|
||||
<a href="{{ route('grades.lessons.index', $grade) }}" class="btn btn-primary">Занятия</a>
|
||||
</div>
|
||||
</td>
|
||||
@endcan
|
||||
<td>
|
||||
<div>
|
||||
<a href="{{ route('grades.lessons.index', $grade) }}" class="btn btn-primary">Занятия</a>
|
||||
</div>
|
||||
</td>
|
||||
@can('list', \App\Models\Grade::class)
|
||||
<td>
|
||||
<div>
|
||||
|
@ -1,43 +0,0 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<style>
|
||||
* { font-family: DejaVu Sans !important; }
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
table, th, td {
|
||||
border: 1px solid black;
|
||||
}
|
||||
th, td {
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
</style>
|
||||
<title>Успеваемость ученика</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Информация об успеваемости</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Предмет</th>
|
||||
<th>Средняя оценка</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($avgScores as $key => $item)
|
||||
<tr>
|
||||
<td>{{ $key }}</td>
|
||||
<td>{{ $item }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
@ -18,12 +18,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="card mt-4">
|
||||
<div class="card-header d-flex justify-content-between align-items-center">
|
||||
{{__('Предметы')}}
|
||||
@can('avgScores', \App\Models\Student::class)
|
||||
<a href="{{ route('export-avg-scores') }}" class="btn btn-primary">Успеваемость</a>
|
||||
@endcan
|
||||
</div>
|
||||
<div class="card-header">{{__('Предметы')}}</div>
|
||||
<div class="card-body">
|
||||
@if (count($subjects))
|
||||
<table class="table table-striped">
|
||||
@ -74,9 +69,7 @@
|
||||
@can('create', \App\Models\Subject::class)
|
||||
<a href="{{ route('subjects.create') }}" class="btn btn-success">Добавить</a>
|
||||
@endcan
|
||||
@can('pdf', \App\Models\Subject::class)
|
||||
<a href="{{ route('export-pdf') }}" class="btn btn-info">PDF</a>
|
||||
@endcan
|
||||
<a href="{{ route('export-pdf') }}" class="btn btn-info">PDF</a>
|
||||
</div>
|
||||
<div class="card-footer">{{ $subjects->links() }}</div>
|
||||
</div>
|
||||
|
@ -55,7 +55,6 @@ Route::middleware('auth')->group(function () {
|
||||
Route::get('subjects/{subject}/student-scores', [StudentController::class, 'scores'])->name('student-scores');
|
||||
Route::get('student-debts', [StudentController::class, 'debts'])->name('student-debts');
|
||||
Route::get('teachers/{teacher}/subjects', [SubjectTeacherController::class, 'index'])->name('teachers.subjects.index');
|
||||
Route::get('export-avg-scores', [StudentController::class, 'exportAvgScores'])->name('export-avg-scores');
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user