123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- {"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} }}
- <?php
- //Déclaration d'un item de menu dans le menu principal
- function {{plugin}}_menu(&$menuItems){
- global $myUser;
- if(!$myUser->can('{{plugin}}','read')) return;
- $menuItems[] = array(
- 'sort'=>3,
- 'url'=>'index.php?module={{plugin}}',
- 'label'=>'{{Plugin.label}}',
- 'icon'=> '{{plugin.icon}}',
- 'color'=> '{{plugin.color}}'
- );
- }
- //Cette fonction va generer une page quand on clique sur {{plugin.label}} dans menu
- function {{plugin}}_page(){
- global $_;
- if(!isset($_['module']) || $_['module'] !='{{plugin}}') return;
- $page = !isset($_['page']) ? 'list.{{entity.readable}}' : $_['page'];
- $page = str_replace('..','',$page);
- $file = __DIR__.SLASH.'page.'.$page.'.php';
- if(!file_exists($file)) throw new Exception("Page ".$page." inexistante");
-
- require_once($file);
- }
- //Fonction executée lors de l'activation du plugin
- function {{plugin}}_install($id){
- if($id != 'fr.core.{{plugin}}') return;
- Entity::install(__DIR__);
- {{#fields}}{{#isDictionary}}$dictionary = new Dictionary();
- $dictionary->slug = '{{plugin}}_{{entity}}_{{key}}';
- if(Dictionary::rowCount(array('slug'=>$dictionary->slug)) ==0){
- $dictionary->label = '{{EntityLabel}} : {{label}}';
- $dictionary->parent = 0;
- $dictionary->state = Dictionary::ACTIVE;
- $dictionary->save();
- foreach(array(
- 'none'=>'Aucun(e)',
- ) as $key=>$value){
- $item = new Dictionary();
- $item->slug = '{{plugin}}_{{entity}}_{{key}}_'.$key;
- $item->label = $value;
- $item->parent = $dictionary->id;
- $item->state = Dictionary::ACTIVE;
- $item->save();
- }
- }
- {{/isDictionary}}{{/fields}}
- }
- //Fonction executée lors de la désactivation du plugin
- function {{plugin}}_uninstall($id){
- if($id != 'fr.core.{{plugin}}') return;
- Entity::uninstall(__DIR__);
- {{#fields}}{{#isDictionary}}$dictionary = Dictionary::bySlug('{{plugin}}_{{entity}}_{{key}}');
- if($dictionary!= false && $dictionary->id!=0){
- Dictionary::delete(array('parent'=>$dictionary->id));
- Dictionary::delete(array('id'=>$dictionary->id));
- }
- {{/isDictionary}}{{/fields}}
- }
- //Déclaration des sections de droits du plugin
- Right::register('{{plugin}}',array('label'=>'Gestion des droits sur le plugin {{plugin.label}}'));
- //cette fonction comprends toutes les actions du plugin qui ne nécessitent pas de vue html
- function {{plugin}}_action(){
- require_once(__DIR__.SLASH.'action.php');
- }
- {{#setting}}//Déclaration du menu de réglages
- function {{plugin}}_menu_setting(&$settingMenu){
- global $myUser;
-
- if(!$myUser->can('{{plugin}}','configure')) return;
- $settingMenu[]= array(
- 'sort' =>1,
- 'url' => 'setting.php?section=global.{{plugin}}',
- 'icon' => 'fas fa-angle-right',
- 'label' => '{{Plugin.label}}'
- );
- }
- //Déclaration des pages de réglages
- function {{plugin}}_content_setting(){
- global $_;
- if(file_exists(__DIR__.SLASH.'setting.'.$_['section'].'.php'))
- require_once(__DIR__.SLASH.'setting.'.$_['section'].'.php');
- }
- require_once(__DIR__.SLASH.'action.php');
- //Déclaration des settings de base
- //Types possibles : voir FieldType.class.php. Un simple string définit une catégorie.
- Configuration::setting('{{plugin}}',array(
- "Général",
- //'{{plugin}}_enable' => array("label"=>"Activer","type"=>"boolean"),
- ));
- {{/setting}}{{#widget}}
- //Affichage du/des widget(s)
- function {{plugin}}_widget(&$widgets){
-
- require_once(PLUGIN_PATH.'dashboard'.SLASH.'DashboardWidget.class.php');
- $modelWidget = new DashboardWidget();
- $modelWidget->model = '{{plugin}}';
- $modelWidget->title = '{{Plugin.label}}';
- $modelWidget->icon = '{{plugin.icon}}';
- $modelWidget->background = '{{plugin.color}}';
- $modelWidget->load = 'action.php?action={{plugin}}_widget_load';
- $modelWidget->js = [Plugin::url().'/js/widget.js'];
- $modelWidget->css = [Plugin::url().'/css/widget.css'];
- $modelWidget->description = "{{description}}";
- $widgets[] = $modelWidget;
- }
- {{/widget}}
- /*
- */
- //Déclation des assets
- Plugin::addCss("/css/main.css");
- Plugin::addJs("/js/main.js");
- {{#component}}Plugin::addCss("/css/component.css");
- Plugin::addJs("/js/component.js");
- {{/component}}
- //Mapping hook / fonctions
- Plugin::addHook("install", "{{plugin}}_install");
- Plugin::addHook("uninstall", "{{plugin}}_uninstall");
- Plugin::addHook("menu_main", "{{plugin}}_menu");
- Plugin::addHook("page", "{{plugin}}_page"); {{#setting}}
- Plugin::addHook("menu_setting", "{{plugin}}_menu_setting");{{/setting}}{{#setting}}
- Plugin::addHook("content_setting", "{{plugin}}_content_setting");{{/setting}}{{#widget}}
- Plugin::addHook("widget", "{{plugin}}_widget");{{/widget}}
- ?>
|