feat: add campaign alerts feature with alerts management and UI integration

- Introduced a new `CampaignAlerts` class for handling alerts logic.
- Added database migration for `campaign_alerts` table creation.
- Implemented methods for fetching, marking, and deleting alerts in the `CampaignAlerts` factory class.
- Created a new view for displaying campaign alerts with filtering options.
- Updated the main client view to include a badge for the number of alerts.
- Enhanced sync functionality to support campaigns and products separately.
- Adjusted styles for alert badges in the UI.
This commit is contained in:
2026-02-20 01:33:53 +01:00
parent 2c331fda07
commit 0024a25bfb
17 changed files with 1394 additions and 31 deletions

View File

@@ -0,0 +1,113 @@
<div class="campaigns-page">
<div class="campaigns-header">
<h2><i class="fa-solid fa-triangle-exclamation"></i> Alerty</h2>
</div>
<form method="get" action="/campaign_alerts" class="campaigns-filters" style="margin-bottom:16px;">
<div class="filter-group">
<label for="client_id"><i class="fa-solid fa-building"></i> Klient</label>
<select id="client_id" name="client_id" class="form-control" onchange="this.form.submit()">
<option value="">- wszyscy klienci -</option>
<?php foreach ( $this -> clients as $client ): ?>
<option value="<?= (int) $client['id']; ?>" <?= (int) $this -> selected_client_id === (int) $client['id'] ? 'selected' : ''; ?>>
<?= htmlspecialchars( (string) $client['name'] ); ?>
</option>
<?php endforeach; ?>
</select>
</div>
</form>
<div class="campaigns-table-wrap">
<table class="table" id="campaign_alerts_table">
<thead>
<tr>
<th>Data</th>
<th>Klient</th>
<th>Kampania</th>
<th>Grupa reklam</th>
<th>Komunikat</th>
</tr>
</thead>
<tbody>
<?php if ( empty( $this -> alerts ) ): ?>
<tr>
<td colspan="5" class="text-center">Brak alertów.</td>
</tr>
<?php else: ?>
<?php foreach ( $this -> alerts as $row ): ?>
<?php
$campaign_name = trim( (string) ( $row['campaign_name'] ?? '' ) );
if ( $campaign_name === '' )
{
$campaign_name = 'Kampania #' . (int) ( $row['campaign_external_id'] ?? 0 );
}
$ad_group_name = trim( (string) ( $row['ad_group_name'] ?? '' ) );
if ( $ad_group_name === '' )
{
$ad_group_name = 'Grupa reklam #' . (int) ( $row['ad_group_external_id'] ?? 0 );
}
$client_name = trim( (string) ( $row['client_name'] ?? '' ) );
if ( $client_name === '' )
{
$client_name = 'Klient #' . (int) ( $row['client_id'] ?? 0 );
}
?>
<tr>
<td style="white-space:nowrap"><?= htmlspecialchars( (string) ( $row['date_detected'] ?? '' ) ); ?></td>
<td><?= htmlspecialchars( $client_name ); ?></td>
<td><?= htmlspecialchars( $campaign_name ); ?></td>
<td><?= htmlspecialchars( $ad_group_name ); ?></td>
<td><?= htmlspecialchars( (string) ( $row['message'] ?? '' ) ); ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
<?php if ( (int) $this -> total_pages > 1 ): ?>
<div class="dt-layout-row" style="display:flex !important;justify-content:flex-end;">
<div class="dt-paging">
<nav>
<ul class="pagination">
<?php
$page = (int) $this -> page;
$total_pages = (int) $this -> total_pages;
$client_id = (int) $this -> selected_client_id;
$qs = $client_id > 0 ? '&client_id=' . $client_id : '';
?>
<li class="page-item <?= $page <= 1 ? 'disabled' : ''; ?>">
<a class="page-link" href="/campaign_alerts?page=<?= $page - 1; ?><?= $qs; ?>">&laquo;</a>
</li>
<?php
$start_p = max( 1, $page - 2 );
$end_p = min( $total_pages, $page + 2 );
if ( $start_p > 1 ):
?>
<li class="page-item"><a class="page-link" href="/campaign_alerts?page=1<?= $qs; ?>">1</a></li>
<?php if ( $start_p > 2 ): ?>
<li class="page-item disabled"><span class="page-link">...</span></li>
<?php endif; ?>
<?php endif; ?>
<?php for ( $i = $start_p; $i <= $end_p; $i++ ): ?>
<li class="page-item <?= $i === $page ? 'active' : ''; ?>">
<a class="page-link" href="/campaign_alerts?page=<?= $i; ?><?= $qs; ?>"><?= $i; ?></a>
</li>
<?php endfor; ?>
<?php if ( $end_p < $total_pages ): ?>
<?php if ( $end_p < $total_pages - 1 ): ?>
<li class="page-item disabled"><span class="page-link">...</span></li>
<?php endif; ?>
<li class="page-item"><a class="page-link" href="/campaign_alerts?page=<?= $total_pages; ?><?= $qs; ?>"><?= $total_pages; ?></a></li>
<?php endif; ?>
<li class="page-item <?= $page >= $total_pages ? 'disabled' : ''; ?>">
<a class="page-link" href="/campaign_alerts?page=<?= $page + 1; ?><?= $qs; ?>">&raquo;</a>
</li>
</ul>
</nav>
</div>
</div>
<?php endif; ?>
</div>
</div>