DashboardWidget.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /**
  3. * Define a Bloc de tableau de bord
  4. * @author Jean CARRUESCO
  5. * @category Plugin
  6. * @license copyright
  7. */
  8. class DashboardWidget extends Entity{
  9. public $id;
  10. public $model; //Modèle (Texte)
  11. public $type; //Type (Liste classique)
  12. public $meta; //Meta (Texte Long)
  13. public $column = 0 ; //Colonne (Nombre Entier)
  14. public $row = 0 ; //Ligne (Nombre Entier)
  15. public $width = 1; //Largeur (Nombre Entier)
  16. public $height = 1; //Hauteur (Nombre Entier)
  17. public $dashboard; //Tableau de bord (Nombre Entier)
  18. public $icon;
  19. public $headerBackground;
  20. public $description;
  21. public $label;
  22. public $content;
  23. public const MODEL_NEW = 'new';
  24. protected $TABLE_NAME = 'dashboard_widget';
  25. public $entityLabel = 'Bloc de tableau de bord';
  26. public $fields = array(
  27. 'id' => array('type'=>'key', 'label' => 'Identifiant'),
  28. 'model' => array('type'=>'text','label' => 'Modèle'),
  29. 'type' => array('type'=>'list','label' => 'Type'),
  30. 'meta' => array('type'=>'textarea','label' => 'Meta'),
  31. 'column' => array('type'=>'integer','label' => 'Colonne'),
  32. 'row' => array('type'=>'integer','label' => 'Ligne'),
  33. 'width' => array('type'=>'integer','label' => 'Largeur'),
  34. 'height' => array('type'=>'integer','label' => 'Hauteur'),
  35. 'dashboard' => array('type'=>'integer','label' => 'Tableau de bord','link'=>'plugin/dashboard/Dashboard.class.php')
  36. );
  37. //Colonnes indexées
  38. public $indexes = array();
  39. public function __construct(){
  40. $this->model = self::MODEL_NEW;
  41. parent::__construct();
  42. }
  43. public function toArray($decoded=false){
  44. return array_merge(array(
  45. 'icon' => $this->icon,
  46. 'headerBackground' => $this->headerBackground,
  47. 'description' => $this->description,
  48. 'label' => $this->label,
  49. 'content' => $this->content
  50. ),parent::toArray($decoded));
  51. }
  52. function toData(){
  53. $row = $this->toArray();
  54. $model = DashboardWidget::model($this->model);
  55. $finalRow = $model->toArray();
  56. foreach($row as $attribute=>$value){
  57. if(isset($value)) $finalRow[$attribute] = $value;
  58. }
  59. return $finalRow;
  60. }
  61. //liste des Type possibles
  62. public static function types($key=null){
  63. $items = array(
  64. 'widget' => array('label'=>'Widget'),
  65. 'model' => array('label'=>'Modèle de widget'),
  66. );
  67. if(!isset($key)) return $items;
  68. return isset($items[$key]) ? $items[$key] : array('label'=>'Non définis');
  69. }
  70. public static function model($slug = null){
  71. $model = array();
  72. Plugin::callHook('widget',array(&$models));
  73. //todo placer en hook
  74. $clock = new DashboardWidget();
  75. $clock->icon = 'far fa-user';
  76. $clock->headerBackground = 'rgb(0, 123, 255)';
  77. $clock->description = 'Une Horloge toute couillone';
  78. $clock->label = 'Horloge';
  79. $clock->content = '<div class="text-center m-auto">13:37</div>';
  80. $clock->width = 3;
  81. $clock->height = 3;
  82. $models['clock'] = $clock;
  83. $newModel = new DashboardWidget();
  84. $newModel->icon = 'far fa-user';
  85. $newModel->headerBackground = 'rgb(0, 123, 255)';
  86. $newModel->description = 'Type de widget non définit';
  87. $newModel->label = 'Nouveau widget';
  88. $newModel->content = '<div class="text-center m-auto">Cliquez sur l\'icone <i class="fas fa-ellipsis-v text-muted mx-1"></i> en haut à droite pour configurer votre widget</div>';
  89. $newModel->width = 3;
  90. $newModel->height = 2;
  91. $models[self::MODEL_NEW] = $newModel;
  92. foreach($models as $model){
  93. if(!isset($model->model)) continue;
  94. $models[$model->model] = $model;
  95. }
  96. if(!isset($slug)) return $models;
  97. return isset($models[$slug]) ? $models[$slug] : $model;
  98. }
  99. }
  100. ?>