NotificationEffect.class.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. Effet de workflow
  4. Envois une notification à un ou plusieurs utilisateurs interne
  5. */
  6. class NotificationEffect{
  7. //Descriptif du type d'effet
  8. public static function manifest($key = null){
  9. $manifest = array(
  10. 'slug' => 'notification',
  11. 'label' => 'Envoyer une notification',
  12. 'class' => get_called_class(),
  13. 'path' => __FILE__,
  14. 'icon' => 'far fa-bell',
  15. 'color' => '#ff9f43',
  16. );
  17. if(!isset($key)) return $manifest;
  18. return isset($manifest[$key]) ? $manifest[$key] : '' ;
  19. }
  20. //méthode d'affichage de l'effet
  21. public static function form($item){
  22. $html = '';
  23. $class = get_called_class();
  24. //$class::manifest('icon')
  25. ob_start();
  26. ?>
  27. <div class="input-group">
  28. <div class="input-group-text input-group-prepend">
  29. Notifier :
  30. </div>
  31. <input type="text" data-id="recipient" data-type="user" class="form-control" value="<?php echo isset($item['recipient']) ? $item['recipient'] : '' ?>" placeholder="utilisateur" required>
  32. <div class="input-group mt-1">
  33. <div class="input-group-text input-group-prepend">
  34. Titre :
  35. </div>
  36. <input type="text" data-id="title" class="form-control" value="<?php echo isset($item['title']) ? $item['title'] : '' ?>" placeholder="Bonjour,...">
  37. </div>
  38. <textarea data-id="message" data-type="wysiwyg"><?php echo isset($item['message']) ? $item['message'] : '' ?></textarea>
  39. </div>
  40. <?php
  41. $html = ob_get_clean();
  42. return $html;
  43. }
  44. public static function run($effect,$parameters = array()){
  45. global $conf;
  46. $logs = '';
  47. if( in_array($parameters['workflow']['type'] , array( Workflow::TYPE_ENTITY, Workflow::TYPE_LIST)) ){
  48. if(isset($parameters['current'])) $parameters['current'] = $parameters['current']->toArray();
  49. if(isset($parameters['old'])) $parameters['old'] = $parameters['old']->toArray();
  50. }
  51. $effect->values['title'] = isset($effect->values['title']) ? template($effect->values['title'],$parameters,true) : '';
  52. $effect->values['message'] =isset($effect->values['message']) ? template($effect->values['message'],$parameters,true): '';
  53. try{
  54. $logs = 'Pour '.$effect->values['recipient'].': '.$effect->values['title'];
  55. Plugin::callHook('emit_notification',array(array(
  56. 'label' => $effect->values['title'],
  57. 'html' => wysiwyg_filter(html_entity_decode($effect->values['message'])),
  58. 'pinned' => 0,
  59. 'type' => 'notice',
  60. 'recipients' => array($effect->values['recipient'])
  61. )));
  62. }catch(Exception $e){
  63. $logs .= '<span class="text-danger"><br>Erreur : '.$e->getMessage().'</span>';
  64. }
  65. return $logs;
  66. }
  67. }
  68. ?>