Files
BiveEngine/engine/Main/trait.alerts.php
2025-12-24 19:19:01 +03:00

50 lines
1.8 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
// Работа с уведомлениями
defined('ROOT_DIR') || exit;
trait Alerts {
// Получить список уведомлений
public function alerts_get_list($group = "main")
{
$session_name = $this->session_get_name();
$alerts = $this->db_query("SELECT * FROM `bive_alerts` WHERE `session` = ? AND `is_read` = 0 AND `group` = ?", array($session_name, $group), false);
if (!count($alerts)) return false;
$this->alerts_read_all($group);
return $alerts;
}
// Добавить уведомление
public function alerts_add($message, $type = "notice", $group = "main")
{
$session_name = $this->session_get_name();
$this->db_query("INSERT INTO `bive_alerts`(`session`, `message`, `type`, `group`) VALUES (?, ?, ?, ?)", array($session_name, $message, $type, $group), true);
}
// Пометить все уведомления как прочитанные
public function alerts_read_all($group = "main")
{
$session_name = $this->session_get_name();
$this->db_query("UPDATE `bive_alerts` SET `is_read` = 1 WHERE `session` = ? AND `is_read` = 0 AND `group` = ?", array($session_name, $group), true);
}
public function alerts_view($group = "main"): bool
{
$alerts = $this->alerts_get_list($group);
if(!$alerts) return false;
$alerts_dom = new DOM("div");
$alerts_dom->setAttribute("class", "b_alerts");
foreach ($alerts as $key => $alert) {
$alert_dom = new DOM("div");
$alert_dom->setAttribute("class", "b_alert " . $alert["type"]);
$alert_dom->prepend($alert["message"]);
$alerts_dom->prepend($alert_dom);
}
$alerts_dom->view();
return true;
}
}