43 lines
1.2 KiB
PHP
43 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Api\Controllers;
|
|
|
|
use Api\Core\Controller;
|
|
use Api\Core\Response;
|
|
use Api\Models\Assessment;
|
|
|
|
class AssessmentController extends Controller {
|
|
public function index() {
|
|
$user = $this->auth();
|
|
$model = new Assessment();
|
|
|
|
if ($user['role'] === 'Super Admin') {
|
|
$data = $model->all();
|
|
} else {
|
|
$data = $model->getBySchool($user['school_id']);
|
|
}
|
|
|
|
Response::json($data);
|
|
}
|
|
|
|
public function store() {
|
|
$user = $this->auth();
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
|
|
if ($user['role'] !== 'Admin' && $user['role'] !== 'Teacher' && $user['role'] !== 'Super Admin') {
|
|
Response::error('Unauthorized', 403);
|
|
}
|
|
|
|
$db = db();
|
|
$stmt = $db->prepare("INSERT INTO assessments (title, subject, type, school_id) VALUES (:title, :subject, :type, :school_id)");
|
|
$stmt->execute([
|
|
'title' => $data['title'],
|
|
'subject' => $data['subject'],
|
|
'type' => $data['type'],
|
|
'school_id' => $user['school_id']
|
|
]);
|
|
|
|
Response::json(['id' => $db->lastInsertId(), 'message' => 'Assessment created'], 201);
|
|
}
|
|
}
|