-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudentController.php
More file actions
executable file
·74 lines (61 loc) · 1.97 KB
/
StudentController.php
File metadata and controls
executable file
·74 lines (61 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace humhub\modules\note\controllers;
use humhub\components\behaviors\AccessControl;
use humhub\components\Controller;
use humhub\modules\note\helpers\PdfHelper;
use humhub\modules\note\models\Student;
use humhub\modules\note\utils\FPDF\FPDF;
use humhub\modules\note\permissions\ViewNote;
use yii\web\HttpException;
use Yii;
use yii\web\NotFoundHttpException;
class StudentController extends Controller
{
public function behaviors()
{
return [
'acl' => [
'class' => AccessControl::className(),
]
];
}
public function actionIndex($schoolYear = null)
{
if(\Yii::$app->user->getPermissionManager()->can(new ViewNote())){
if (!isset($schoolYear)) {
$schoolYear = date('Y');
}
$student = $this->findStudent();
return $this->render(
'index',
['student' => $student, 'schoolYear' => $schoolYear]
);
}
else{
throw new HttpException(404, "Page non trouvée.");
}
}
public function actionPrint($schoolYear = null)
{
if(\Yii::$app->user->getPermissionManager()->can(new ViewNote())){
if (!isset($schoolYear)) {
$schoolYear = date('Y');
}
$student = $this->findStudent();
Yii::$app->response->headers->add('Content-Type', 'application/pdf');
$pdf = PdfHelper::generateGradeReport($student, $schoolYear);
$pdf->Output(date('U') . '_' . $student->user->username . '_' . $schoolYear . '.pdf', 'd');
}
else{
throw new HttpException(404, "Page non trouvée.");
}
}
private function findStudent()
{
$student = Student::findOne(['user_id' => Yii::$app->user->id]);
if ($student == null) {
throw new NotFoundHttpException();
}
return $student;
}
}