DashboardWidget.class.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Define a dashboardwidget.
  4. * @author Administrateur
  5. * @category Plugin
  6. * @license copyright
  7. */
  8. class DashboardWidget extends Entity{
  9. public $id,$minified,$position,$model,$dashboard,$title,$icon,$background,$width,$load,$configure,$configure_callback,$configure_init,$move,$delete,$options,$js,$css,$content,$data,$description,$defaultWidth;
  10. protected $TABLE_NAME = 'dashboard_dashboard_widget';
  11. public $fields =
  12. array(
  13. 'id' => 'key',
  14. 'model' => 'string',
  15. 'data' => 'longstring',
  16. 'position' => 'int',
  17. 'minified' => 'boolean',
  18. 'width' => 'int',
  19. 'dashboard' => 'int'
  20. );
  21. function __construct(){
  22. parent::__construct();
  23. $this->options = array();
  24. $this->icon = 'fa-caret-right';
  25. $this->title = 'Sans titre';
  26. $this->defaultWidth = 4;
  27. $this->width = 0;
  28. }
  29. public function toArray($decoded= false){
  30. $fields = parent::toArray($decoded);
  31. $fields['options'] = $this->options;
  32. $fields['icon'] = $this->icon;
  33. $fields['background'] = $this->background;
  34. $fields['load'] = $this->load;
  35. $fields['configure'] = $this->configure;
  36. $fields['configure_callback'] = $this->configure_callback;
  37. $fields['configure_init'] = $this->configure_init;
  38. $fields['js'] = $this->js;
  39. $fields['css'] = $this->css;
  40. $fields['description'] = $this->description;
  41. $fields['content'] = $this->content;
  42. $fields['title'] = $this->title;
  43. return $fields;
  44. }
  45. function data($key=null,$value=null){
  46. $data = json_decode($this->data,true);
  47. if($key==null) return $data;
  48. if(is_array($key) && $value==null){
  49. foreach ($key as $k => $v) {
  50. $data[$k] = $v;
  51. $this->data = json_encode($data);
  52. }
  53. return true;
  54. }
  55. if($value===null) return isset($data[$key])?$data[$key]:'';
  56. $data[$key] = $value;
  57. $this->data = json_encode($data);
  58. return true;
  59. }
  60. public static function current(){
  61. global $_;
  62. $dbWidget = self::getById($_['id']);
  63. $widget = DashboardWidget::models($dbWidget->model);
  64. $widget->id = $dbWidget->id;
  65. $widget->position = $dbWidget->position;
  66. $widget->minified = $dbWidget->minified;
  67. $widget->width = $dbWidget->width;
  68. $widget->dashboard = $dbWidget->dashboard;
  69. $widget->data = $dbWidget->data;
  70. return $widget;
  71. }
  72. public static function models($modelUid = null){
  73. Plugin::callHook('widget',array(&$models));
  74. foreach($models as $model)
  75. $models[$model->model] = $model;
  76. if(!isset($modelUid)) return $models;
  77. return isset($models[$modelUid]) ? $models[$modelUid] : array();
  78. }
  79. }
  80. ?>