123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
- /** DASHBOARDWIDGET / BLOC DE TABLEAU DE BORD **/
- Action::register('dashboard_widget_search',function(&$response){
- global $_;
- User::check_access('dashboard','read');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- $filters = array();
- if(empty($_['scope'])) throw new Exception('Portée non spécifiée');
- $filters['scope'] = $_['scope'];
- if(empty($_['uid'])) $filters['uid'] = $_['uid'];
- $dashboard = Dashboard::load($filters);
- $widgets = DashboardWidget::loadAll(array('dashboard'=>$dashboard->id));
- $response['widgets'] = array();
- foreach($widgets as $widget){
- $response['widgets'][] = $widget->toData();
- }
- });
- Action::register('dashboard_widget_by_id',function(&$response){
- global $_;
- User::check_access('dashboard','read');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- if(empty($_['id'])) throw new Exception('Id non spécifiée');
- $response['item'] = DashboardWidget::getById($_['id'])->toArray();
- });
- Action::register('dashboard_widget_add',function(&$response){
- global $_,$myUser;
- User::check_access('dashboard','edit');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- $filters = array();
- if(empty($_['scope'])) throw new Exception('Portée non sépcifiée');
- $filters = array('scope'=>$_['scope']);
- if(!empty($_['uid'])) $filters['uid'] = $_['uid'];
- $dashboard = Dashboard::load($filters);
- if(!$dashboard) throw new Exception("Tableau de bord introuvable");
- $widget = new DashboardWidget();
- $widget->dashboard = $dashboard->id;
- if(isset($_['row'])) $widget->row = $_['row'];
- if(isset($_['column'])) $widget->column = $_['column'];
- $widget->save();
- $response = $widget->toData();
- });
- Action::register('dashboard_widget_move',function(&$response){
- global $_;
- User::check_access('dashboard','edit');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
- if(!isset($_['widget']['column'])) throw new Exception('Colonne non spécifiée');
- if(!isset($_['widget']['row'])) throw new Exception('Ligne non spécifiée');
- $widget = DashboardWidget::getById($_['widget']['id'],1);
- if(!$widget) throw new Exception('Widget introuvable');
- $widget->column = $_['widget']['column'];
- $widget->row = $_['widget']['row'];
- $widget->save();
- });
- Action::register('dashboard_widget_resize',function(&$response){
- global $_;
- User::check_access('dashboard','edit');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
- if(!isset($_['widget']['width'])) throw new Exception('Largeur non spécifiée');
- if(!isset($_['widget']['height'])) throw new Exception('Hauteur non spécifiée');
- $widget = DashboardWidget::getById($_['widget']['id'],1);
- if(!$widget) throw new Exception('Widget introuvable');
- $widget->width = $_['widget']['width'];
- $widget->height = $_['widget']['height'];
- $widget->save();
- });
- Action::register('dashboard_widget_delete',function(&$response){
- global $_;
- User::check_access('dashboard','delete');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- if(empty($_['widget']['id'])) throw new Exception('Aucun identifiant renseigné');
- $widget = DashboardWidget::getById($_['widget']['id'],1);
- if(!$widget) throw new Exception('Widget introuvable');
- DashboardWidget::deleteById($widget->id);
- });
- Action::register('dashboard_model_search',function(&$response){
- global $_;
- User::check_access('dashboard','read');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- $response['rows'] = DashboardWidget::model();
- unset($response['rows'][DashboardWidget::MODEL_NEW]);
- });
- Action::register('dashboard_widget_configure',function(&$response){
- global $_;
- User::check_access('dashboard','edit');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- if(empty($_['id'])) throw new Exception('Aucun identifiant renseigné');
- $widget = DashboardWidget::getById($_['id'],1);
- if(!$widget) throw new Exception('Widget introuvable');
- $widget->fromArray($_);
- $widget->save();
- });
|