|
@@ -179,7 +179,7 @@ function notification_cron($time){
|
|
|
Plugin::need('notification/Notification');
|
|
|
Notification::clear();
|
|
|
}
|
|
|
-
|
|
|
+/*
|
|
|
function notification_widget(&$widgets){
|
|
|
Plugin::need('dashboard/DashboardWidget');
|
|
|
|
|
@@ -198,6 +198,130 @@ function notification_widget(&$widgets){
|
|
|
|
|
|
$widgets[] = $modelWidget;
|
|
|
}
|
|
|
+*/
|
|
|
+Plugin::addHook('widget',function(&$models){
|
|
|
+
|
|
|
+ $model = new DashboardWidget();
|
|
|
+ $model->icon = 'fas fa-bell';
|
|
|
+ $model->headerBackground = '#ffbe5c';
|
|
|
+ $model->description = 'Affiche un menu sélectionné';
|
|
|
+ $model->label = 'Notification';
|
|
|
+ $model->width = 3;
|
|
|
+ $model->height = 3;
|
|
|
+ $model->model = 'notification';
|
|
|
+ $model->css = array(__DIR__.'/css/widget.css?v='.time());
|
|
|
+ $model->js = array(__DIR__.'/js/widget.js?v='.time());
|
|
|
+
|
|
|
+
|
|
|
+ $model->content = function(&$widget){
|
|
|
+ global $myUser;
|
|
|
+ User::check_access('notification','read');
|
|
|
+ Plugin::need('dashboard/DashboardWidget');
|
|
|
+
|
|
|
+ $widget->title = 'Dernières alertes';
|
|
|
+
|
|
|
+
|
|
|
+ if(empty($widget->meta['label'])) $widget->meta['label'] = 'Bloc Menu';
|
|
|
+ if(empty($widget->meta['url'])) $widget->meta['url'] = '';
|
|
|
+ if(empty($widget->meta['color'])) $widget->meta['color'] = '#007bff';
|
|
|
+ ob_start();
|
|
|
+
|
|
|
+ require_once(__DIR__.SLASH.'Notification.class.php');
|
|
|
+ require_once(__DIR__.SLASH.'UserNotification.class.php');
|
|
|
+
|
|
|
+ $types = isset($widget->meta['types'])? $widget->meta['types'] :array('announcement');
|
|
|
+ $max = isset($widget->meta['notification-number'])?$widget->meta['notification-number']:5;
|
|
|
+ $maxlength = isset($widget->meta['notification-length'])?$widget->meta['notification-length']:250 ;
|
|
|
+ $userNotifications = UserNotification::byUser($myUser,array(
|
|
|
+ 'limit' => $max,
|
|
|
+ 'unread' => false,
|
|
|
+ 'types' => $types,
|
|
|
+ ));
|
|
|
+
|
|
|
+ ?>
|
|
|
+ <div class="notification-container">
|
|
|
+ <h5 class="text-uppercase w-100 text-center"><i class="far fa-bell"></i> Alertes</h5>
|
|
|
+ <ul class="notification-widget-list">
|
|
|
+ <?php foreach($userNotifications as $infos):
|
|
|
+ $infos['created-relative'] = isset($_['synthesis']) ? relative_time($infos['created'], null, 7) : relative_time($infos['created'], null, 7, true);
|
|
|
+ $meta = json_decode($infos['meta']);
|
|
|
+ $infos['link'] = 'index.php?module=notification#'.$infos['id'];
|
|
|
+ $type = Notification::types($infos['type']);
|
|
|
+ ?>
|
|
|
+ <li>
|
|
|
+ <h5 onclick="document.location.href='<?php echo $infos['link']; ?>';" class="pointer mb-0 mt-1" style="color: <?php echo $type['color']; ?>;">
|
|
|
+ <div><i title="<?php echo $type['label'] ?>" class="<?php echo $type['icon'] ?>"></i> <?php echo $infos['label']; ?></div>
|
|
|
+ <small class="text-muted d-block"><i class="far fa-clock"></i> <?php echo $infos['created-relative']; ?></small>
|
|
|
+ </h5>
|
|
|
+ <p class=""><?php echo truncate($infos['html'],$maxlength,array('html'=>true)); ?></p>
|
|
|
+ <a class="btn btn-link d-block w-100 text-center" href="<?php echo $infos['link']; ?>">+ d'informations</a>
|
|
|
+ </li>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </ul>
|
|
|
+ </div>
|
|
|
+ <?php
|
|
|
+
|
|
|
+ $widget->content = ob_get_clean();
|
|
|
+ };
|
|
|
+
|
|
|
+ $model->configure = function($widget){
|
|
|
+ global $myUser;
|
|
|
+ User::check_access('notification','read');
|
|
|
+ require_once(__DIR__.SLASH.'Notification.class.php');
|
|
|
+ ob_start();
|
|
|
+
|
|
|
+ $selectedTypes = isset($widget->meta['types'])? $widget->meta['types'] :array('announcement');
|
|
|
+ $max = isset($widget->meta['notification-number'])?$widget->meta['notification-number']:5;
|
|
|
+ $maxlength = isset($widget->meta['notification-length'])?$widget->meta['notification-length']:250 ;
|
|
|
+ ?>
|
|
|
+ <div id="navigation-widget-form">
|
|
|
+ <div id="notification-widget-form">
|
|
|
+ <div class="row">
|
|
|
+ <div class="col-md-6 col-sm-12">
|
|
|
+ <label for="notification-number">Nb de notifications affichées :</label>
|
|
|
+ <input type="number" class="form-control mb-2" value="<?php echo $max; ?>" id="notification-number">
|
|
|
+ </div>
|
|
|
+ <div class="col-md-6 col-sm-12">
|
|
|
+ <label for="notification-length">Nb de caractères affichés :</label>
|
|
|
+ <input type="number" class="form-control mb-2" value="<?php echo $maxlength; ?>" id="notification-length">
|
|
|
+ </div>
|
|
|
+ <div class="col-md-12 col-sm-12">
|
|
|
+ <label for="">Types de notifications à afficher :</label>
|
|
|
+ <ul class="list-group" id="widget-notification-list">
|
|
|
+ <?php foreach(Notification::types() as $slug=>$type): ?>
|
|
|
+ <li class="list-group-item p-0">
|
|
|
+ <label class="m-0 pointer p-2"><input type="checkbox" onchange="notification_widget_configure_save()"; <?php echo in_array($slug, $selectedTypes)?'checked="checked"':''; ?> value="<?php echo $slug; ?>" data-type="checkbox"><i class="<?php echo $type['icon']; ?>"></i> <?php echo $type['label']; ?> <small class="text-muted">- <?php echo $type['description']; ?></small></label>
|
|
|
+ </li>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </ul>
|
|
|
+ <input type="hidden" id="types" data-id="types" value="<?php echo implode(',',$selectedTypes);?>">
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <?php
|
|
|
+ };
|
|
|
+
|
|
|
+ $model->save = function($widget,$form){
|
|
|
+
|
|
|
+ global $myUser,$_;
|
|
|
+ User::check_access('notification','read');
|
|
|
+ require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
|
|
|
+
|
|
|
+ if(!isset($form['types'])) throw new Exception("Au moins un type de notification à afficher est requis");
|
|
|
+ if(!isset($form['notification-number'])) $form['notification-number'] = 5;
|
|
|
+ if(!isset($form['notification-length'])) $form['notification-length'] = 150;
|
|
|
+ $widget->meta['types'] = $form['types'];
|
|
|
+ $widget->meta['notification-number'] = $form['notification-number'];
|
|
|
+ $widget->meta['notification-length'] = $form['notification-length'];
|
|
|
+ $widget->save();
|
|
|
+
|
|
|
+ $widget->save();
|
|
|
+ };
|
|
|
+
|
|
|
+ $models[$model->model] = $model;
|
|
|
+});
|
|
|
+
|
|
|
|
|
|
//Déclaration des settings de base
|
|
|
//Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
|
|
@@ -215,7 +339,7 @@ Plugin::addCss("/css/main.css");
|
|
|
Plugin::addJs("/js/main.js");
|
|
|
|
|
|
//Mapping hook / fonctions
|
|
|
-Plugin::addHook("widget", "notification_widget");
|
|
|
+
|
|
|
Plugin::addHook("install", "notification_install");
|
|
|
Plugin::addHook("uninstall", "notification_uninstall");
|
|
|
|