Skip to content

Commit

Permalink
UPD: Notifications updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Itskiprotich committed Aug 7, 2024
1 parent b105578 commit a529c16
Show file tree
Hide file tree
Showing 8 changed files with 358 additions and 192 deletions.
28 changes: 28 additions & 0 deletions config/clear_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
// in config/app_form.php
return [
'formStart' => '<form class="form-inline" {{attrs}}>',
'formGroup' => ' {{label}}{{input}} ',
'label' => '<label {{attrs}}>{{text}}</label>',
// Generic input element.
'input' => '<input class="form-control" type="{{type}}" name="{{name}}"{{attrs}}/>
<a onclick="$(\'input[name={{name}}]\').val(\'\');" class="tiptip" data-original-title="clear!!">
<em class="accordion-toggle"><i class="fa fa-window-close-o" aria-hidden="true"></i></em></a>
',
// Select element,
'select' => '<select class="form-control" name="{{name}}"{{attrs}}>{{content}}</select>',
// Used for button elements in button().
'button' => '<div class="form-group">
<button class="btn btn-default"{{attrs}}>{{text}}</button>
</div>',
// Radio input element,
'radio' => '<input type="radio" class="radio-inline" name="{{name}}" value="{{value}}"{{attrs}}>',
//'radioWrapper' => '<div class="col-sm-8"><div class="radio">{{label}}</div></div>',
'textarea' => '<textarea rows="1" class="form-control" name="{{name}}"{{attrs}}>{{value}}</textarea>',
'checkboxWrapper' => '{{label}}',
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
'dateWidget' => '{{day}}{{month}}{{year}}',
//'select' => '<select name="{{name}}"{{attrs}}>{{content}}</select>',
'inputContainer' => '<div class="form-group {{required}}">{{content}}</div>',
'submitContainer' => '{{content}}',
];
2 changes: 1 addition & 1 deletion src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function initialize(): void

$this->loadComponent('RequestHandler', ['viewClassMap' => ['csv' => 'CsvView.Csv']]);
// $this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Flash');
$this->Notifications = $this->loadModel('Notifications');

// $this->loadHelper('Tools.Captcha', [
Expand Down
69 changes: 64 additions & 5 deletions src/Controller/Manager/NotificationsController.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace App\Controller\Manager;
Expand All @@ -20,14 +21,72 @@ class NotificationsController extends AppController
*/
public function index()
{
$this->paginate = [
'contain' => ['Users'],
];
$notifications = $this->paginate($this->Notifications);

$this->set(compact('notifications'));
$page_options = ['20' => '20', '25' => '25'];

$passedArgs = $this->request->getQuery();
// if (!empty($passedArgs['start_date']) || !empty($passedArgs['end_date'])) {
// $passedArgs['range'] = true;
// }
$queryParams = $this->request->getQuery();

// Example criteria handling
$criteria = [];
if (!empty($queryParams['start_date'])) {
$startDate = \DateTime::createFromFormat('d-m-Y', $queryParams['start_date']);
if ($startDate) {
$queryParams['start_date'] = $startDate->format('Y-m-d');
}
}
if (!empty($queryParams['end_date'])) {
$endDate = \DateTime::createFromFormat('d-m-Y', $queryParams['end_date']);
if ($endDate) {
$queryParams['end_date'] = $endDate->format('Y-m-d');
}
// debug($endDate);
}
$limit = $page_options['20']; // Default limit
if (!empty($passedArgs['pages']) && isset($page_options[$passedArgs['pages']])) {
$limit = $page_options[$passedArgs['pages']];
}
if (!empty($queryParams['start_date'])) {
$criteria['Notifications.created >='] = $queryParams['start_date'];
}
if (!empty($queryParams['end_date'])) {
$criteria['Notifications.created <='] = $queryParams['end_date'];
}
// debug($criteria);
// exit;
// Authentication: Get current user ID
$userId = $this->Auth->User('id');

// $criteria = $this->Notifications->parseCriteria($passedArgs);
$criteria['user_id'] = $userId;

$query = $this->Notifications->find()
->where($criteria)
->contain(['Users'])
->order(['Notifications.created' => 'desc']);

// CSV Export
$ext = $this->request->getParam('_ext');
if ($ext && $ext == 'csv') {
$this->csvExport($query);
return;
}

$notifications = $this->Paginator->paginate($query, [
'limit' => $limit
]);

$this->set(compact('page_options', 'notifications'));
}

// CSV export method placeholder
protected function csvExport($query)
{
// Implement CSV export logic here
}
/**
* View method
*
Expand Down
48 changes: 42 additions & 6 deletions src/Controller/Reporter/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,49 @@ class NotificationsController extends AppController
* @return \Cake\Http\Response|null|void Renders view
*/
public function index()
{
$this->paginate = [
'contain' => ['Users'],
];
$notifications = $this->paginate($this->Notifications);
{

$page_options = ['20' => '20', '25' => '25'];

$passedArgs = $this->request->getQuery();
if (!empty($passedArgs['start_date']) || !empty($passedArgs['end_date'])) {
$passedArgs['range'] = true;
}

$limit = $page_options['20']; // Default limit
if (!empty($passedArgs['pages']) && isset($page_options[$passedArgs['pages']])) {
$limit = $page_options[$passedArgs['pages']];
}

// Authentication: Get current user ID
$userId = $this->Auth->User('id');

// $criteria = $this->Notifications->parseCriteria($passedArgs);
$criteria['user_id'] = $userId;

$query = $this->Notifications->find()
->where($criteria)
->contain(['Users'])
->order(['Notifications.created' => 'desc']);

$this->set(compact('notifications'));
// CSV Export
$ext = $this->request->getParam('_ext');
if ($ext && $ext == 'csv') {
$this->csvExport($query);
return;
}

$notifications = $this->Paginator->paginate($query, [
'limit' => $limit
]);

$this->set(compact('page_options', 'notifications'));
}

// CSV export method placeholder
protected function csvExport($query)
{
// Implement CSV export logic here
}

/**
Expand Down
62 changes: 2 additions & 60 deletions templates/Manager/Notifications/index.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\App\Model\Entity\Notification> $notifications
*/
$this->assign('NT', 'active');
echo $this->element('notification/index');
?>
<div class="notifications index content">
<?= $this->Html->link(__('New Notification'), ['action' => 'add'], ['class' => 'button float-right']) ?>
<h3><?= __('Notifications') ?></h3>
<div class="table-responsive">
<table>
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('user_id') ?></th>
<th><?= $this->Paginator->sort('type') ?></th>
<th><?= $this->Paginator->sort('model') ?></th>
<th><?= $this->Paginator->sort('foreign_key') ?></th>
<th><?= $this->Paginator->sort('title') ?></th>
<th><?= $this->Paginator->sort('url') ?></th>
<th><?= $this->Paginator->sort('deleted') ?></th>
<th><?= $this->Paginator->sort('deleted_date') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th><?= $this->Paginator->sort('modified') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($notifications as $notification): ?>
<tr>
<td><?= $this->Number->format($notification->id) ?></td>
<td><?= $notification->has('user') ? $this->Html->link($notification->user->name, ['controller' => 'Users', 'action' => 'view', $notification->user->id]) : '' ?></td>
<td><?= h($notification->type) ?></td>
<td><?= h($notification->model) ?></td>
<td><?= $notification->foreign_key === null ? '' : $this->Number->format($notification->foreign_key) ?></td>
<td><?= h($notification->title) ?></td>
<td><?= h($notification->url) ?></td>
<td><?= h($notification->deleted) ?></td>
<td><?= h($notification->deleted_date) ?></td>
<td><?= h($notification->created) ?></td>
<td><?= h($notification->modified) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $notification->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $notification->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $notification->id], ['confirm' => __('Are you sure you want to delete # {0}?', $notification->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
</div>
</div>
62 changes: 2 additions & 60 deletions templates/Notifications/index.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\App\Model\Entity\Notification> $notifications
*/
$this->assign('NT', 'active');
echo $this->element('notification/index');
?>
<div class="notifications index content">
<?= $this->Html->link(__('New Notification'), ['action' => 'add'], ['class' => 'button float-right']) ?>
<h3><?= __('Notifications') ?></h3>
<div class="table-responsive">
<table>
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('user_id') ?></th>
<th><?= $this->Paginator->sort('type') ?></th>
<th><?= $this->Paginator->sort('model') ?></th>
<th><?= $this->Paginator->sort('foreign_key') ?></th>
<th><?= $this->Paginator->sort('title') ?></th>
<th><?= $this->Paginator->sort('url') ?></th>
<th><?= $this->Paginator->sort('deleted') ?></th>
<th><?= $this->Paginator->sort('deleted_date') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th><?= $this->Paginator->sort('modified') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($notifications as $notification): ?>
<tr>
<td><?= $this->Number->format($notification->id) ?></td>
<td><?= $notification->has('user') ? $this->Html->link($notification->user->name, ['controller' => 'Users', 'action' => 'view', $notification->user->id]) : '' ?></td>
<td><?= h($notification->type) ?></td>
<td><?= h($notification->model) ?></td>
<td><?= $notification->foreign_key === null ? '' : $this->Number->format($notification->foreign_key) ?></td>
<td><?= h($notification->title) ?></td>
<td><?= h($notification->url) ?></td>
<td><?= h($notification->deleted) ?></td>
<td><?= h($notification->deleted_date) ?></td>
<td><?= h($notification->created) ?></td>
<td><?= h($notification->modified) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $notification->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $notification->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $notification->id], ['confirm' => __('Are you sure you want to delete # {0}?', $notification->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
</div>
</div>
62 changes: 2 additions & 60 deletions templates/Reporter/Notifications/index.php
Original file line number Diff line number Diff line change
@@ -1,62 +1,4 @@
<?php
/**
* @var \App\View\AppView $this
* @var iterable<\App\Model\Entity\Notification> $notifications
*/
$this->assign('NT', 'active');
echo $this->element('notification/index');
?>
<div class="notifications index content">
<?= $this->Html->link(__('New Notification'), ['action' => 'add'], ['class' => 'button float-right']) ?>
<h3><?= __('Notifications') ?></h3>
<div class="table-responsive">
<table>
<thead>
<tr>
<th><?= $this->Paginator->sort('id') ?></th>
<th><?= $this->Paginator->sort('user_id') ?></th>
<th><?= $this->Paginator->sort('type') ?></th>
<th><?= $this->Paginator->sort('model') ?></th>
<th><?= $this->Paginator->sort('foreign_key') ?></th>
<th><?= $this->Paginator->sort('title') ?></th>
<th><?= $this->Paginator->sort('url') ?></th>
<th><?= $this->Paginator->sort('deleted') ?></th>
<th><?= $this->Paginator->sort('deleted_date') ?></th>
<th><?= $this->Paginator->sort('created') ?></th>
<th><?= $this->Paginator->sort('modified') ?></th>
<th class="actions"><?= __('Actions') ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($notifications as $notification): ?>
<tr>
<td><?= $this->Number->format($notification->id) ?></td>
<td><?= $notification->has('user') ? $this->Html->link($notification->user->name, ['controller' => 'Users', 'action' => 'view', $notification->user->id]) : '' ?></td>
<td><?= h($notification->type) ?></td>
<td><?= h($notification->model) ?></td>
<td><?= $notification->foreign_key === null ? '' : $this->Number->format($notification->foreign_key) ?></td>
<td><?= h($notification->title) ?></td>
<td><?= h($notification->url) ?></td>
<td><?= h($notification->deleted) ?></td>
<td><?= h($notification->deleted_date) ?></td>
<td><?= h($notification->created) ?></td>
<td><?= h($notification->modified) ?></td>
<td class="actions">
<?= $this->Html->link(__('View'), ['action' => 'view', $notification->id]) ?>
<?= $this->Html->link(__('Edit'), ['action' => 'edit', $notification->id]) ?>
<?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $notification->id], ['confirm' => __('Are you sure you want to delete # {0}?', $notification->id)]) ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<div class="paginator">
<ul class="pagination">
<?= $this->Paginator->first('<< ' . __('first')) ?>
<?= $this->Paginator->prev('< ' . __('previous')) ?>
<?= $this->Paginator->numbers() ?>
<?= $this->Paginator->next(__('next') . ' >') ?>
<?= $this->Paginator->last(__('last') . ' >>') ?>
</ul>
<p><?= $this->Paginator->counter(__('Page {{page}} of {{pages}}, showing {{current}} record(s) out of {{count}} total')) ?></p>
</div>
</div>
Loading

0 comments on commit a529c16

Please sign in to comment.