<?php

namespace App\Models;

use CodeIgniter\Model;

class ClassDiaryModel extends Model
{
    protected $table = 'class_diary';

    protected $primaryKey = 'id';

    protected $allowedFields = [
        'comment',
        'date',
        'started_time',
        'ended_time',
        'status',
        'payment_status',
        'class_id',
        'lesson_id',
        'class_status_id'
    ];

    public function getByStudentId($studentId)
    {
        return $this->select('
                class_diary.*,
                class.name AS class_name,
                class.code AS class_code,
                class_student.fee
            ')
            ->join('class', 'class.id = class_diary.class_id')
            ->join('class_student', 'class_student.class_id = class.id')
            ->where('class_student.student_id', $studentId)
            ->where('class_diary.status', 1)
            ->where('class.status', 1)
            ->where('class_student.status', 1)
            ->orderBy('class_diary.date', 'DESC')
            ->findAll();
    }

    //protected $useTimestamps = true;
}