action.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <?php
  2. /** DASHBOARDWIDGET / BLOC DE TABLEAU DE BORD **/
  3. Action::register('dashboard_widget_search',function(&$response){
  4. global $_;
  5. User::check_access('dashboard','read');
  6. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  7. require_once(__DIR__.SLASH.'Dashboard.class.php');
  8. $filters = array();
  9. if(empty($_['scope'])) throw new Exception('Portée non spécifiée');
  10. $filters['scope'] = $_['scope'];
  11. if(empty($_['uid'])) $filters['uid'] = $_['uid'];
  12. $dashboard = Dashboard::load($filters);
  13. $widgets = DashboardWidget::loadAll(array('dashboard'=>$dashboard->id));
  14. $response['widgets'] = array();
  15. foreach($widgets as $widget){
  16. $response['widgets'][] = $widget->toData();
  17. }
  18. });
  19. Action::register('dashboard_widget_by_id',function(&$response){
  20. global $_;
  21. User::check_access('dashboard','read');
  22. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  23. require_once(__DIR__.SLASH.'Dashboard.class.php');
  24. if(empty($_['id'])) throw new Exception('Id non spécifiée');
  25. $response['item'] = DashboardWidget::getById($_['id'])->toArray();
  26. });
  27. Action::register('dashboard_widget_add',function(&$response){
  28. global $_,$myUser;
  29. User::check_access('dashboard','edit');
  30. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  31. require_once(__DIR__.SLASH.'Dashboard.class.php');
  32. $filters = array();
  33. if(empty($_['scope'])) throw new Exception('Portée non sépcifiée');
  34. $filters = array('scope'=>$_['scope']);
  35. if(!empty($_['uid'])) $filters['uid'] = $_['uid'];
  36. $dashboard = Dashboard::load($filters);
  37. if(!$dashboard) throw new Exception("Tableau de bord introuvable");
  38. $widget = new DashboardWidget();
  39. $widget->dashboard = $dashboard->id;
  40. if(isset($_['row'])) $widget->row = $_['row'];
  41. if(isset($_['column'])) $widget->column = $_['column'];
  42. $widget->save();
  43. $response = $widget->toData();
  44. });
  45. Action::register('dashboard_widget_move',function(&$response){
  46. global $_;
  47. User::check_access('dashboard','edit');
  48. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  49. require_once(__DIR__.SLASH.'Dashboard.class.php');
  50. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  51. if(!isset($_['widget']['column'])) throw new Exception('Colonne non spécifiée');
  52. if(!isset($_['widget']['row'])) throw new Exception('Ligne non spécifiée');
  53. $widget = DashboardWidget::getById($_['widget']['id'],1);
  54. if(!$widget) throw new Exception('Widget introuvable');
  55. $widget->column = $_['widget']['column'];
  56. $widget->row = $_['widget']['row'];
  57. $widget->save();
  58. });
  59. Action::register('dashboard_widget_resize',function(&$response){
  60. global $_;
  61. User::check_access('dashboard','edit');
  62. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  63. require_once(__DIR__.SLASH.'Dashboard.class.php');
  64. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  65. if(!isset($_['widget']['width'])) throw new Exception('Largeur non spécifiée');
  66. if(!isset($_['widget']['height'])) throw new Exception('Hauteur non spécifiée');
  67. $widget = DashboardWidget::getById($_['widget']['id'],1);
  68. if(!$widget) throw new Exception('Widget introuvable');
  69. $widget->width = $_['widget']['width'];
  70. $widget->height = $_['widget']['height'];
  71. $widget->save();
  72. });
  73. Action::register('dashboard_widget_delete',function(&$response){
  74. global $_;
  75. User::check_access('dashboard','delete');
  76. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  77. require_once(__DIR__.SLASH.'Dashboard.class.php');
  78. if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
  79. $widget = DashboardWidget::getById($_['widget']['id'],1);
  80. if(!$widget) throw new Exception('Widget introuvable');
  81. DashboardWidget::deleteById($widget->id);
  82. });
  83. Action::register('dashboard_model_search',function(&$response){
  84. global $_;
  85. User::check_access('dashboard','read');
  86. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  87. require_once(__DIR__.SLASH.'Dashboard.class.php');
  88. $response['rows'] = DashboardWidget::model();
  89. unset($response['rows'][DashboardWidget::MODEL_NEW]);
  90. });
  91. Action::register('dashboard_widget_configure',function(&$response){
  92. global $_;
  93. User::check_access('dashboard','edit');
  94. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  95. require_once(__DIR__.SLASH.'Dashboard.class.php');
  96. if(empty($_['id'])) throw new Exception('Aucun identifiant renseigné');
  97. $widget = DashboardWidget::getById($_['id'],1);
  98. if(!$widget) throw new Exception('Widget introuvable');
  99. $widget->fromArray($_);
  100. $widget->save();
  101. });