action.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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($_['uid'])) throw new Exception('Scope non spécifié');
  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. $row = $widget->toArray();
  17. $model = DashboardWidget::model($widget->model);
  18. $row = array_merge($model,$row);
  19. $response['widgets'][] = $row ;
  20. }
  21. });
  22. Action::register('dashboard_widget_add',function(&$response){
  23. global $_,$myUser;
  24. User::check_access('dashboard','edit');
  25. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  26. require_once(__DIR__.SLASH.'Dashboard.class.php');
  27. if(empty($_['scope'])) throw new Exception('Scope non sépcifié');
  28. $filters = array('scope'=>$_['scope']);
  29. if(!empty($_['uid'])) $filters['uid'] = $_['uid'];
  30. // $dashboard = new Dashboard();
  31. // $dashboard->uid = $myUser->login;
  32. // $dashboard->scope = "home";
  33. // $dashboard->save();
  34. $dashboard = Dashboard::load($filters);
  35. if(!$dashboard) throw new Exception("Dashboard introuvable");
  36. $widget = new DashboardWidget();
  37. $widget->dashboard = $dashboard->id;
  38. $widget->save();
  39. $row = $widget->toArray();
  40. $model = DashboardWidget::model($widget->model);
  41. $row = array_merge($model,$row);
  42. $response = $row;
  43. });
  44. Action::register('dashboard_widget_move',function(&$response){
  45. global $_;
  46. User::check_access('dashboard','edit');
  47. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  48. require_once(__DIR__.SLASH.'Dashboard.class.php');
  49. if(empty($_['widget']['id'])) throw new Exception('Id non spécifié');
  50. if(!isset($_['widget']['column'])) throw new Exception('Colonne non spécifié');
  51. if(!isset($_['widget']['row'])) throw new Exception('Ligne non spécifié');
  52. $widget = DashboardWidget::getById($_['widget']['id'],1);
  53. if(!$widget) throw new Exception('Widget introuvable');
  54. $widget->column = $_['widget']['column'];
  55. $widget->row = $_['widget']['row'];
  56. $widget->save();
  57. });
  58. Action::register('dashboard_widget_resize',function(&$response){
  59. global $_;
  60. User::check_access('dashboard','edit');
  61. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  62. require_once(__DIR__.SLASH.'Dashboard.class.php');
  63. if(empty($_['widget']['id'])) throw new Exception('Id non spécifié');
  64. if(!isset($_['widget']['width'])) throw new Exception('Largeur non spécifiée');
  65. if(!isset($_['widget']['height'])) throw new Exception('Hauteur non spécifiée');
  66. $widget = DashboardWidget::getById($_['widget']['id'],1);
  67. if(!$widget) throw new Exception('Widget introuvable');
  68. $widget->width = $_['widget']['width'];
  69. $widget->height = $_['widget']['height'];
  70. $widget->save();
  71. });
  72. Action::register('dashboard_widget_delete',function(&$response){
  73. global $_;
  74. User::check_access('dashboard','delete');
  75. require_once(__DIR__.SLASH.'DashboardWidget.class.php');
  76. require_once(__DIR__.SLASH.'Dashboard.class.php');
  77. if(empty($_['widget']['id'])) throw new Exception('Id non spécifié');
  78. $widget = DashboardWidget::getById($_['widget']['id'],1);
  79. if(!$widget) throw new Exception('Widget introuvable');
  80. DashboardWidget::deleteById($widget->id);
  81. });
  82. ?>