Issues (350)

app/Http/Controllers/CourseSkillController.php (2 issues)

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\Course;
6
use PhpOffice\PhpWord\IOFactory;
7
use PhpOffice\PhpWord\PhpWord;
8
9
class CourseSkillController extends Controller
10
{
11
    public function __construct()
12
    {
13
        parent::__construct();
14
        $this->middleware(['permission:evaluation.edit']);
15
    }
16
17
    public function exportCourseSyllabus(Course $course)
18
    {
19
        $phpWord = new PhpWord();
20
21
        // Course general info
22
        $section = $phpWord->addSection();
23
24
        $section->addText('Cours : '.$course->name);
25
26
        $section->addText('Session : '.$course->period->name);
27
28
        $section->addText('Enseignant(e) : '.$course->teacher->name);
29
30
        $section->addText('Dates du cours : '.$course->start_date->format('d/m').' - '.$course->end_date->format('d/m'));
31
32
        $section->addTextBreak();
33
34
        // Course skills
35
        $level = '';
36
        $type = '';
37
38
        foreach ($course->skills->sortBy('skill_type_id') as $skill) {
0 ignored issues
show
The property skills does not seem to exist on App\Models\Course. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
39
            if ($skill->level->name != $level) {
40
                $level = $skill->level->name;
41
42
                $section->addText('Niveau '.$level);
43
            }
44
45
            if ($skill->skill_type->name != $type) {
46
                $type = $skill->skill_type->name;
47
48
                $section->addText($type);
49
            }
50
51
            $section->addListItem($skill->name);
52
        }
53
54
        // Saving the document as OOXML file...
55
        $objWriter = IOFactory::createWriter($phpWord, 'Word2007');
56
        header('Content-type: application/msword');
57
        header('Cache-Control: no-store, no-cache');
58
        header('Content-Disposition: attachment; filename="document.docx"');
59
60
        $objWriter->save('php://output');
61
        exit;
0 ignored issues
show
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
62
    }
63
}
64