123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229 |
- <?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){
- $model = DashboardWidget::model($widget->model);
- $model->refresh($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'] = array();
- foreach(DashboardWidget::model() as $model){
- $row = $model->toArray();
- $row["excerpt"] = truncate($row["description"], $length = 100, array('html'=>true)) ;
- if($row["description"] == $row["excerpt"]) $row["description"] = '';
- $row['created'] = date('d-m-Y',$row['created']);
- $response['rows'][] = $row;
- }
- unset($response['rows'][DashboardWidget::MODEL_NEW]);
- });
- Action::register('dashboard_widget_refresh',function(&$response){
- global $_;
- User::check_access('dashboard','read');
- require_once(__DIR__.SLASH.'Dashboard.class.php');
- require_once(__DIR__.SLASH.'DashboardWidget.class.php');
- $response['rows'] = array();
- $widgets = array();
- $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);
- foreach(DashboardWidget::loadAll(array('dashboard'=>$dashboard->id)) as $widget){
- if(!isset($widgets[$widget->model])) $widgets[$widget->model] = array();
- $widgets[$widget->model][] = $widget;
- }
- foreach(DashboardWidget::model() as $model){
- if(!isset($model->content) || !$model->live || is_string($model->content) || !isset($widgets[$model->model]) ) continue;
-
- foreach($widgets[$model->model] as $currentWidget){
- $oldWidget = clone $currentWidget;
- $model->refresh($currentWidget);
- $response['rows'][] = $currentWidget;
- }
- }
- });
- 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(is_string($widget->meta)) $widget->meta = json_decode($widget->meta,true);
- if(!is_array($widget->meta)) $widget->meta = array();
- if(!$widget) throw new Exception('Widget introuvable');
- switch($_['type']){
- case 'style':
- $widget->fromArray($_);
- break;
- case 'model':
- $widget->fromArray($_);
- break;
- case 'properties':
- $model = DashboardWidget::model($widget->model);
- if(isset($model->save)){
- $save = $model->save;
- if(!is_array($widget->meta)) $widget->meta = array();
- $save($widget,$_['meta']);
- }else{
- $widget->meta = $_['meta'];
- }
- break;
- }
-
- $widget->save();
- });
- Action::register('dashboard_widget_configure_form',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');
- $model = DashboardWidget::model($widget->model);
- if(!is_array($widget->meta)){
- $widget->meta = json_decode($widget->meta,true);
- if(!is_array($widget->meta)) $widget->meta = array();
- }
- if(!isset($model->configure)) $model->configure = function($widget){
- echo 'Aucune configuration disponible';
- return;
- };
- $configure = $model->configure;
- $configure($widget);
- exit();
- });
|