workflow.plugin.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <?php
  2. //Déclaration d'un item de menu dans le menu principal
  3. function workflow_menu(&$menuItems){
  4. global $myUser;
  5. if(!$myUser->can('workflow','read')) return;
  6. $menuItems[] = array(
  7. 'sort'=>3,
  8. 'url'=>'index.php?module=workflow',
  9. 'label'=>'Workflow',
  10. 'icon'=> 'fas fa-network-wired',
  11. 'color'=> '#3498db'
  12. );
  13. }
  14. //Cette fonction va generer une page quand on clique sur workflow dans menu
  15. function workflow_page(){
  16. global $_;
  17. if(!isset($_['module']) || $_['module'] !='workflow') return;
  18. $page = !isset($_['page']) ? 'list.workflow' : $_['page'];
  19. $page = str_replace('..','',$page);
  20. $file = __DIR__.SLASH.'page.'.$page.'.php';
  21. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  22. require_once($file);
  23. }
  24. //Fonction executée lors de l'activation du plugin
  25. function workflow_install($id){
  26. if($id != 'fr.core.workflow') return;
  27. Entity::install(__DIR__);
  28. }
  29. //Fonction executée lors de la désactivation du plugin
  30. function workflow_uninstall($id){
  31. if($id != 'fr.core.workflow') return;
  32. Entity::uninstall(__DIR__);
  33. }
  34. //Déclaration des sections de droits du plugin
  35. Right::register("workflow",array('label'=>"Gestion des droits sur le plugin workflow"));
  36. //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
  37. function workflow_action(){
  38. require_once(__DIR__.SLASH.'action.php');
  39. }
  40. //Déclaration du menu de réglages
  41. function workflow_menu_setting(&$settingMenu){
  42. global $myUser;
  43. if(!$myUser->can('workflow','configure')) return;
  44. $settingMenu[]= array(
  45. 'sort' =>1,
  46. 'url' => 'setting.php?section=global.workflow',
  47. 'icon' => 'fas fa-angle-right',
  48. 'label' => 'Workflow'
  49. );
  50. }
  51. //Déclaration des pages de réglages
  52. function workflow_content_setting(){
  53. global $_;
  54. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  55. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  56. }
  57. //Cron executant les workflow globaux ayant pour évenement "Toutes les minutes"
  58. function workflow_cron(){
  59. require_once(__DIR__.SLASH.'WorkflowEvent.class.php');
  60. WorkflowEvent::trigger(WorkflowEvent::EVENT_CRON);
  61. }
  62. //Déclaration des settings de base
  63. //Types possibles : text,select ( + "values"=> array('1'=>'Val 1'),password,checkbox. Un simple string définit une catégorie.
  64. Configuration::setting('workflow',array(
  65. "Général",
  66. 'workflow_mail_from' => array("label"=>"Envoyeur des e-mails","type"=>"text"),
  67. 'workflow_mail_reply' => array("label"=>"Envoyeur des e-mails : mail de réponse","type"=>"text"),
  68. ));
  69. Plugin::addHook("workflow_event", function(&$events){
  70. //Déclaration de l'évenement global "Toutes les minutes" pour utilisation sur les workflow globaux
  71. $events[] = array(
  72. 'type' => Workflow::TYPE_GLOBAL,
  73. 'events' => array(
  74. WorkflowEvent::EVENT_CRON => 'Toutes les minutes'
  75. )
  76. );
  77. });
  78. //Déclation des assets
  79. Plugin::addCss("/css/main.css");
  80. Plugin::addJs("/js/main.js");
  81. //Mapping hook / fonctions
  82. Plugin::addHook("install", "workflow_install");
  83. Plugin::addHook("uninstall", "workflow_uninstall");
  84. Plugin::addHook("menu_main", "workflow_menu");
  85. Plugin::addHook("page", "workflow_page");
  86. Plugin::addHook("action", "workflow_action");
  87. Plugin::addHook("menu_setting", "workflow_menu_setting");
  88. Plugin::addHook("content_setting", "workflow_content_setting");
  89. Plugin::addHook("cron", "workflow_cron");
  90. ?>