Skip to main content

Overview

The BulletinController generates and displays student grade reports (bulletins), calculating averages and validation status. Supports both admin and student access. File Location: app/controllers/BulletinController.php Dependencies:
  • Grade model
  • User model
  • Auth helper

Methods

index()

Displays list of all students for bulletin selection. Authorization: Admin only Behavior:
  • Retrieves all student records
  • Renders student selection view for bulletin access
Code Example:
public function index()
{
    Auth::admin();

    $students = $this->userModel->getAllStudents();
    require __DIR__ . '/../views/bulletin/index.php';
}
View Location: app/views/bulletin/index.php

show()

Generates and displays a student’s bulletin with all grades, average, and validation status. Authorization: Any authenticated user
student_id
integer
Student ID (required for admin/teacher, ignored for students)
Access Control:
  • Students: View their own bulletin (uses session user ID)
  • Admin/Teachers: Can view any student’s bulletin (requires student_id parameter)
Behavior:
  1. Determines target student ID based on user role
  2. Retrieves student information and all grades
  3. Calculates total, average, and validation status
  4. Renders bulletin view with calculations
Code Example:
// ONE entry point
public function show()
{
    Auth::check();

    if ($_SESSION['user']['role'] === 'student') {
        $student_id = $_SESSION['user']['id'];
    } else {
        if (!isset($_GET['student_id'])) {
            die("Student ID is required");
        }
        $student_id = $_GET['student_id'];
    }

    $student = $this->userModel->findById($student_id);
    $grades = $this->gradeModel->getBulletinData($student_id);

    $total = 0;
    $count = count($grades);

    foreach ($grades as $g) {
        $total += $g['grade'];
    }

    $average = $count > 0 ? round($total / $count, 2) : 0;
    $status = $average >= 10 ? 'VALIDÉ' : 'NON VALIDÉ';

    require __DIR__ . '/../views/bulletin/show.php';
}
View Location: app/views/bulletin/show.php Calculations:
  • Total: Sum of all grades
  • Average: total / count (rounded to 2 decimals)
  • Status: VALIDÉ if average ≥ 10, otherwise NON VALIDÉ

Usage Examples

Student Viewing Their Own Bulletin

// GET /bulletin/show
// Session:
$_SESSION['user'] = [
    'id' => 25,
    'role' => 'student'
];
// Uses student's own ID automatically

Admin Viewing a Student’s Bulletin

// GET /bulletin/show?student_id=25
// Session:
$_SESSION['user'] = [
    'id' => 1,
    'role' => 'admin'
];

Bulletin Data Structure

The bulletin displays:
[
    'student' => [
        'id' => 25,
        'name' => 'Alice Johnson',
        'email' => '[email protected]'
    ],
    'grades' => [
        [
            'subject' => 'Mathematics',
            'teacher' => 'Dr. Smith',
            'grade' => 15.5
        ],
        [
            'subject' => 'Physics',
            'teacher' => 'Prof. Brown',
            'grade' => 12.0
        ]
    ],
    'total' => 27.5,
    'count' => 2,
    'average' => 13.75,
    'status' => 'VALIDÉ'
]

Validation Logic

Pass/Fail Determination

$status = $average >= 10 ? 'VALIDÉ' : 'NON VALIDÉ';
  • VALIDÉ (Validated): Average grade ≥ 10/20
  • NON VALIDÉ (Not Validated): Average grade < 10/20

Edge Cases

  • No grades: Average = 0, Status = NON VALIDÉ
  • Division by zero: Protected by $count > 0 check

Security Features

  • Auth::check() - Ensures user is authenticated
  • Role-based access: Students see only their own bulletin
  • Admin/teachers require explicit student_id parameter
  • Dies with error if admin doesn’t provide student_id

Build docs developers (and LLMs) love