Files
alrahma_sunday_school_api/app/Models/ContactUs.php
T
2026-03-05 12:29:37 -05:00

92 lines
2.1 KiB
PHP
Executable File

<?php
namespace App\Models;
use App\Models\BaseModel;
class ContactUs extends BaseModel
{
protected $table = 'contactus';
protected $primaryKey = 'id';
protected $useAutoIncrement = true;
protected $useSoftDeletes = false;
protected $fillable = [
'sender_id',
'reciever_id',
'subject',
'message',
'created_at',
'updated_at',
'semester',
'school_year',
];
// Timestamps (set manually or use auto timestamps below)
public $timestamps = true;
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
protected $validationRules = [
'sender_id' => 'required|integer',
'reciever_id' => 'required|integer',
'subject' => 'required|string|max_length[255]',
'message' => 'required|string',
'semester' => 'required|string|max_length[255]',
'school_year' => 'permit_empty|string|max_length[9]'
];
protected $validationMessages = [];
protected $skipValidation = false;
/**
* Retrieve messages by semester and school year.
*
* @param string $semester
* @param string $school_year
* @return array
*/
public function getMessagesBySemesterAndYear($semester, $school_year)
{
return $this->where([
'semester' => $semester,
'school_year' => $school_year
])->findAll();
}
/**
* Retrieve messages for a specific sender or receiver.
*
* @param int $userId
* @return array
*/
public function getMessagesForUser($userId)
{
return $this->where('sender_id', $userId)
->orWhere('reciever_id', $userId)
->findAll();
}
/**
* Retrieve a message by ID.
*
* @param int $id
* @return array|null
*/
public function getMessageById($id)
{
return $this->find($id);
}
/**
* Update a message by ID.
*
* @param int $id
* @param array $data
* @return bool
*/
public function updateMessage($id, $data)
{
return $this->update($id, $data);
}
}