reconstruction of the project

This commit is contained in:
root
2026-03-08 16:33:24 -04:00
parent 23b7db1107
commit c8de5f7edc
9157 changed files with 77877 additions and 1073823 deletions
+20 -67
View File
@@ -3,14 +3,14 @@
namespace App\Models;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class Quiz extends BaseModel
{
protected $table = 'quiz';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $protectFields = true;
public $timestamps = true;
protected $fillable = [
'student_id',
'school_id',
@@ -25,71 +25,24 @@ class Quiz extends BaseModel
'updated_at',
];
protected bool $allowEmptyInserts = false;
protected bool $updateOnlyChanged = true;
protected $casts = [
'student_id' => 'integer',
'school_id' => 'integer',
'class_section_id' => 'integer',
'updated_by' => 'integer',
'quiz_index' => 'integer',
'score' => 'decimal:2',
'created_at' => 'datetime',
'updated_at' => 'datetime',
];
protected $casts = [];
protected $castHandlers = [];
// Dates
public $timestamps = true;
protected $dateFormat = 'datetime';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $deletedField = 'deleted_at';
// Validation
protected $validationRules = [];
protected $validationMessages = [];
protected $skipValidation = false;
protected $cleanValidationRules = true;
// Callbacks
protected $allowCallbacks = true;
protected $beforeInsert = [];
protected $afterInsert = [];
protected $beforeUpdate = [];
protected $afterUpdate = [];
protected $beforeFind = [];
protected $afterFind = [];
protected $beforeDelete = [];
protected $afterDelete = [];
/**
* Calculate the average quiz score for a given student, semester, and school year.
*
* @param int $studentId The student's ID.
* @param string $semester The semester (e.g., 'Fall', 'Spring').
* @param string $schoolYear The school year (e.g., '2024-2025').
* @return float The average quiz score, or 0 if no scores are found.
*/
public function getAverageQuizScore(int $studentId, string $semester, string $schoolYear): float
public function student(): BelongsTo
{
// Fetch the quiz scores for the given student, semester, and school year
$builder = $this->builder();
$builder->select('score')
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear);
// Execute the query and get the results
$query = $builder->get();
$results = $query->getResultArray();
return $this->belongsTo(Student::class, 'student_id');
}
// If there are no scores, return 0
if (empty($results)) {
return 0.0;
}
// Calculate the average score
$totalScore = 0;
$scoreCount = count($results);
foreach ($results as $result) {
$totalScore += $result['score'];
}
return $totalScore / $scoreCount;
public function classSection(): BelongsTo
{
return $this->belongsTo(ClassSection::class, 'class_section_id');
}
}