{{plugin}}.plugin.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. {"label":"Plugin","syntax":"php","sort":1,"options":{"search-export":{"label":"Export de la recherche","default":true},"widget":{"label" : "Widget de dashboard","default":false},"logic-remove":{"label": "Suppression logique","default":false},"advanced-search":{"label" : "Recherche avancée", "default":true},"setting":{"label" : "Page réglages","default":true},"edit-form":{"label" : "Formulaire dans le tableau de liste","default":false},"list-search":{"label" : "Recherche en forme de liste (non tableau)","default":false},"history-save":{"label" : "Sauvegarder l'historique des modifications (save, delete)","default":false},"component":{"label" : "Générer un composant js autocomplete","default":false} }}
  2. <?php
  3. //Déclaration d'un item de menu dans le menu principal
  4. function {{plugin}}_menu(&$menuItems){
  5. global $myUser;
  6. if(!$myUser->can('{{plugin}}','read')) return;
  7. $menuItems[] = array(
  8. 'sort'=>3,
  9. 'url'=>'index.php?module={{plugin}}',
  10. 'label'=>'{{Plugin.label}}',
  11. 'icon'=> '{{plugin.icon}}',
  12. 'color'=> '{{plugin.color}}'
  13. );
  14. }
  15. //Cette fonction va generer une page quand on clique sur {{plugin.label}} dans menu
  16. function {{plugin}}_page(){
  17. global $_;
  18. if(!isset($_['module']) || $_['module'] !='{{plugin}}') return;
  19. $page = !isset($_['page']) ? 'list.{{entity.readable}}' : $_['page'];
  20. $page = str_replace('..','',$page);
  21. $file = __DIR__.SLASH.'page.'.$page.'.php';
  22. if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
  23. require_once($file);
  24. }
  25. //Fonction executée lors de l'activation du plugin
  26. function {{plugin}}_install($id){
  27. if($id != 'fr.core.{{plugin}}') return;
  28. Entity::install(__DIR__);
  29. {{#fields}}{{#isDictionary}}$dictionary = new Dictionary();
  30. $dictionary->slug = '{{plugin}}_{{entity}}_{{key}}';
  31. if(Dictionary::rowCount(array('slug'=>$dictionary->slug)) ==0){
  32. $dictionary->label = '{{EntityLabel}} : {{label}}';
  33. $dictionary->parent = 0;
  34. $dictionary->state = Dictionary::ACTIVE;
  35. $dictionary->save();
  36. foreach(array(
  37. 'none'=>'Aucun(e)',
  38. ) as $key=>$value){
  39. $item = new Dictionary();
  40. $item->slug = '{{plugin}}_{{entity}}_{{key}}_'.$key;
  41. $item->label = $value;
  42. $item->parent = $dictionary->id;
  43. $item->state = Dictionary::ACTIVE;
  44. $item->save();
  45. }
  46. }
  47. {{/isDictionary}}{{/fields}}
  48. }
  49. //Fonction executée lors de la désactivation du plugin
  50. function {{plugin}}_uninstall($id){
  51. if($id != 'fr.core.{{plugin}}') return;
  52. Entity::uninstall(__DIR__);
  53. {{#fields}}{{#isDictionary}}$dictionary = Dictionary::bySlug('{{plugin}}_{{entity}}_{{key}}');
  54. if($dictionary!= false && $dictionary->id!=0){
  55. Dictionary::delete(array('parent'=>$dictionary->id));
  56. Dictionary::delete(array('id'=>$dictionary->id));
  57. }
  58. {{/isDictionary}}{{/fields}}
  59. }
  60. //Déclaration des sections de droits du plugin
  61. Right::register('{{plugin}}',array('label'=>'Gestion des droits sur le plugin {{plugin.label}}'));
  62. //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
  63. function {{plugin}}_action(){
  64. require_once(__DIR__.SLASH.'action.php');
  65. }
  66. {{#setting}}//Déclaration du menu de réglages
  67. function {{plugin}}_menu_setting(&$settingMenu){
  68. global $myUser;
  69. if(!$myUser->can('{{plugin}}','configure')) return;
  70. $settingMenu[]= array(
  71. 'sort' =>1,
  72. 'url' => 'setting.php?section=global.{{plugin}}',
  73. 'icon' => 'fas fa-angle-right',
  74. 'label' => '{{Plugin.label}}'
  75. );
  76. }
  77. //Déclaration des pages de réglages
  78. function {{plugin}}_content_setting(){
  79. global $_;
  80. if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
  81. require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
  82. }
  83. require_once(__DIR__.SLASH.'action.php');
  84. //Déclaration des settings de base
  85. //Types possibles : voir FieldType.class.php. Un simple string définit une catégorie.
  86. Configuration::setting('{{plugin}}',array(
  87. "Général",
  88. //'{{plugin}}_enable' => array("label"=>"Activer","type"=>"boolean"),
  89. ));
  90. {{/setting}}{{#widget}}
  91. //Affichage du/des widget(s)
  92. function {{plugin}}_widget(&$widgets){
  93. require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
  94. $modelWidget = new DashboardWidget();
  95. $modelWidget->model = '{{plugin}}';
  96. $modelWidget->title = '{{Plugin.label}}';
  97. $modelWidget->icon = '{{plugin.icon}}';
  98. $modelWidget->background = '{{plugin.color}}';
  99. $modelWidget->load = 'action.php?action={{plugin}}_widget_load';
  100. $modelWidget->js = [Plugin::url().'/js/widget.js'];
  101. $modelWidget->css = [Plugin::url().'/css/widget.css'];
  102. $modelWidget->description = "{{description}}";
  103. $widgets[] = $modelWidget;
  104. }
  105. {{/widget}}
  106. /*
  107. */
  108. //Déclation des assets
  109. Plugin::addCss("/css/main.css");
  110. Plugin::addJs("/js/main.js");
  111. {{#component}}Plugin::addCss("/css/component.css");
  112. Plugin::addJs("/js/component.js");
  113. {{/component}}
  114. //Mapping hook / fonctions
  115. Plugin::addHook("install", "{{plugin}}_install");
  116. Plugin::addHook("uninstall", "{{plugin}}_uninstall");
  117. Plugin::addHook("menu_main", "{{plugin}}_menu");
  118. Plugin::addHook("page", "{{plugin}}_page"); {{#setting}}
  119. Plugin::addHook("menu_setting", "{{plugin}}_menu_setting");{{/setting}}{{#setting}}
  120. Plugin::addHook("content_setting", "{{plugin}}_content_setting");{{/setting}}{{#widget}}
  121. Plugin::addHook("widget", "{{plugin}}_widget");{{/widget}}
  122. ?>