motorbike/app/Models/Notification.php
2025-10-13 09:59:40 +03:00

46 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Models;
use CodeIgniter\Model;
class Notification extends Model
{
protected $table = 'notification';
protected $primaryKey = 'id';
protected $allowedFields = ['message', 'is_read', 'forgroup', 'store_id', "link", 'created_at'];
public function getNotifications()
{
$session = session();
$users = $session->get('user');
$today = date('Y-m-d');
return $this->where('store_id', $users['store_id'])
->groupStart()
->where('forgroup', $users['group_name'])
->orWhere('forgroup', strtolower('TOUS'))
->groupEnd()
->groupStart()
->where('is_read', 0) // toutes les notifications non lues
->orGroupStart()
->where('is_read', 1) // notifications lues
->where('DATE(created_at)', $today) // mais seulement celles daujourdhui
->groupEnd()
->groupEnd()
->orderBy('created_at', 'DESC')
->findAll();
}
public function markAsRead(int $id)
{
return $this->update($id, ['is_read' => 1]);
}
public function insertNotification(array $data)
{
return $this->insert($data);
}
}