action.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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}}_search':
  8. Action::write(function(&$response){
  9. global $myUser,$_;
  10. if(!$myUser->can('{{plugin}}','read')) throw new Exception("Permissions insuffisantes",403);
  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(2,(!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. });
  39. break;
  40. //Ajout ou modification d'élément {{entity}}
  41. case '{{plugin}}_{{entity}}_save':
  42. Action::write(function(&$response){
  43. global $myUser,$_;
  44. if(!$myUser->can('{{plugin}}','edit')) throw new Exception("Permissions insuffisantes",403);
  45. require_once(__DIR__.SLASH.'{{Entity}}.class.php');
  46. $item = {{Entity}}::provide();{{:fields}}
  47. $item->{{value.key}} = $_['{{value.key}}'];{{/:fields}}
  48. $item->save();
  49. });
  50. break;
  51. {{~ Formulaire dans le tableau de liste }}//Récuperation ou edition d'élément {{entity}}
  52. case '{{plugin}}_{{entity}}_edit':
  53. Action::write(function(&$response){
  54. global $myUser,$_;
  55. if(!$myUser->can('{{plugin}}','edit')) throw new Exception("Permissions insuffisantes",403);
  56. require_once(__DIR__.SLASH.'{{Entity}}.class.php');{{:links}}
  57. require_once(__DIR__.SLASH.'{{value.entity}}.class.php');{{/:links}}
  58. $response = {{Entity}}::getById($_['id'],{{linksCount}});
  59. });
  60. break;{{/~}}
  61. //Suppression d'élement {{entity}}
  62. case '{{plugin}}_{{entity}}_delete':
  63. Action::write(function(&$response){
  64. global $myUser,$_;
  65. if(!$myUser->can('{{plugin}}','delete')) throw new Exception("Permissions insuffisantes",403);
  66. require_once(__DIR__.SLASH.'{{Entity}}.class.php');
  67. {{~! Suppression logique}}{{Entity}}::deleteById($_['id']);{{/~}}
  68. {{~ Suppression logique}}$item = {{Entity}}::getById($_['id']);
  69. $item->state = {{Entity}}::INACTIVE;
  70. $item->save();{{/~}}
  71. });
  72. break;
  73. {{~! Pas de page réglages }}
  74. //Sauvegarde des configurations de {{plugin}}
  75. case '{{plugin}}_setting_save':
  76. Action::write(function(&$response){
  77. global $myUser,$_,$conf;
  78. if(!$myUser->can('{{plugin}}','configure')) throw new Exception("Permissions insuffisantes",403);
  79. foreach(Configuration::setting('{{plugin}}') as $key=>$value){
  80. if(!is_array($value)) continue;
  81. $allowed[] = $key;
  82. }
  83. foreach ($_['fields'] as $key => $value) {
  84. if(in_array($key, $allowed))
  85. $conf->put($key,$value);
  86. }
  87. });
  88. break;
  89. {{/~}}
  90. {{~ Widget de dashboard }}
  91. case '{{plugin}}_widget_load':
  92. global $myUser;
  93. require_once(__DIR__.SLASH.'..'.SLASH.'dashboard'.SLASH.'DashboardWidget.class.php');
  94. $widget = DashboardWidget::current();
  95. $widget->title = 'Widget {{Plugin}}';
  96. ob_start();
  97. //Décommenter après avoir créé widget.php
  98. //require_once(__DIR__.SLASH.'widget.php');
  99. //$widget->content = ob_get_clean();
  100. $widget->content = 'Widget non développé';
  101. echo json_encode($widget);
  102. break;
  103. {{/~}}
  104. }
  105. ?>