action.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. {"label":"Action","syntax":"php"}
  2. <?php
  3. global $_,$conf;
  4. switch($_['action']){
  5. /** {{ENTITY}} **/
  6. //Récuperation d'une liste de {{entity}}
  7. case '{{plugin}}_{{entity_readable}}_search':
  8. Action::write(function(&$response){
  9. global $myUser,$_;
  10. User::check_access('{{plugin}}','read');
  11. require_once(__DIR__.SLASH.'{{Entity}}.class.php');{{:links}}
  12. require_once(__DIR__.SLASH.'{{value.entity}}.class.php');{{/:links}}
  13. {{~! Recherche non avancée}}
  14. // OPTIONS DE RECHERCHE, A ACTIVER POUR UNE RECHERCHE AVANCEE
  15. $query = 'SELECT * FROM '.{{Entity}}::tableName().' WHERE 1';
  16. $data = array();
  17. //Recherche simple
  18. if(!empty($_['filters']['keyword'])){
  19. $query .= ' AND label LIKE ?';
  20. $data[] = '%'.$_['filters']['keyword'].'%';
  21. }
  22. //Recherche avancée
  23. if(isset($_['filters']['advanced'])) filter_secure_query($_['filters']['advanced'],array('label'),$query,$data);
  24. //Tri des colonnes
  25. if(isset($_['sort'])) sort_secure_query($_['sort'],array('label'),$query,$data);
  26. //Pagination
  27. $response['pagination'] = {{Entity}}::paginate(20,(!empty($_['page'])?$_['page']:0),$query,$data);
  28. ${{entity}}s = {{Entity}}::staticQuery($query,$data,true,{{linksCount}});
  29. {{/~}}
  30. {{~ Recherche non avancée}}
  31. ${{entity}}s = {{Entity}}::loadAll();
  32. {{/~}}
  33. foreach(${{entity}}s as ${{entity}}){
  34. $row = ${{entity}}->toArray();{{:links}}
  35. $row['{{value.key}}'] = ${{entity}}->join('{{value.key}}')->toArray();{{/:links}}
  36. $response['rows'][] = $row;
  37. }
  38. {{~ Export de la recherche}}
  39. /* Mode export */
  40. if($_['export'] == 'true'){
  41. $stream = Excel::exportArray($response['rows'],null,'Export');
  42. File::downloadStream($stream,'export-demandes-'.date('d-m-Y').'.xlsx');
  43. exit();
  44. }
  45. {{/~}}
  46. });
  47. break;
  48. //Ajout ou modification d'élément {{entity}}
  49. case '{{plugin}}_{{entity_readable}}_save':
  50. Action::write(function(&$response){
  51. global $myUser,$_;
  52. User::check_access('{{plugin}}','edit');
  53. require_once(__DIR__.SLASH.'{{Entity}}.class.php');
  54. $item = {{Entity}}::provide();{{:fields}}
  55. $item->{{value.key}} = $_['{{value.key}}'];{{/:fields}}
  56. $item->save();
  57. });
  58. break;
  59. {{~ Formulaire dans le tableau de liste }}//Récuperation ou edition d'élément {{entity}}
  60. case '{{plugin}}_{{entity_readable}}_edit':
  61. Action::write(function(&$response){
  62. global $myUser,$_;
  63. User::check_access('{{plugin}}','edit');
  64. require_once(__DIR__.SLASH.'{{Entity}}.class.php');{{:links}}
  65. require_once(__DIR__.SLASH.'{{value.entity}}.class.php');{{/:links}}
  66. $response = {{Entity}}::getById($_['id'],{{linksCount}});
  67. });
  68. break;{{/~}}
  69. //Suppression d'élement {{entity}}
  70. case '{{plugin}}_{{entity_readable}}_delete':
  71. Action::write(function(&$response){
  72. global $myUser,$_;
  73. User::check_access('{{plugin}}','delete');
  74. require_once(__DIR__.SLASH.'{{Entity}}.class.php');
  75. {{~! Suppression logique}}{{Entity}}::deleteById($_['id']);{{/~}}
  76. {{~ Suppression logique}}$item = {{Entity}}::getById($_['id']);
  77. $item->state = {{Entity}}::INACTIVE;
  78. $item->save();{{/~}}
  79. });
  80. break;
  81. {{~! Pas de page réglages }}
  82. //Sauvegarde des configurations de {{plugin}}
  83. case '{{plugin}}_setting_save':
  84. Action::write(function(&$response){
  85. global $myUser,$_,$conf;
  86. User::check_access('{{plugin}}','configure');
  87. foreach(Configuration::setting('{{plugin}}') as $key=>$value){
  88. if(!is_array($value)) continue;
  89. $allowed[] = $key;
  90. }
  91. foreach ($_['fields'] as $key => $value) {
  92. if(in_array($key, $allowed))
  93. $conf->put($key,$value);
  94. }
  95. });
  96. break;
  97. {{/~}}
  98. {{~ Widget de dashboard }}
  99. case '{{plugin}}_widget_load':
  100. global $myUser;
  101. require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
  102. $widget = DashboardWidget::current();
  103. $widget->title = 'Widget {{Plugin}}';
  104. ob_start();
  105. //Décommenter après avoir créé widget.php
  106. //require_once(__DIR__.SLASH.'widget.php');
  107. //$widget->content = ob_get_clean();
  108. $widget->content = 'Widget non développé';
  109. echo json_encode($widget);
  110. break;
  111. {{/~}}
  112. }
  113. ?>