DashboardWidget.class.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 $iconColor;
  20. public $titleColor;
  21. public $headerBackground;
  22. public $bodyBackground;
  23. public $bodyColor;
  24. public $description;
  25. public $label;
  26. public $content;
  27. public $uid;
  28. public const MODEL_NEW = 'new';
  29. protected $TABLE_NAME = 'dashboard_widget';
  30. public $entityLabel = 'Bloc de tableau de bord';
  31. public $fields = array(
  32. 'id' => array('type'=>'key', 'label' => 'Identifiant'),
  33. 'model' => array('type'=>'text','label' => 'Modèle'),
  34. 'type' => array('type'=>'list','label' => 'Type'),
  35. 'meta' => array('type'=>'textarea','label' => 'Meta'),
  36. 'column' => array('type'=>'integer','label' => 'Colonne'),
  37. 'row' => array('type'=>'integer','label' => 'Ligne'),
  38. 'width' => array('type'=>'integer','label' => 'Largeur'),
  39. 'height' => array('type'=>'integer','label' => 'Hauteur'),
  40. 'icon' => array('type'=>'icon','label' => 'Icône'),
  41. 'iconColor' => array('type'=>'color','label' => 'Couleur icône'),
  42. 'titleColor' => array('type'=>'color','label' => 'Couleur titre'),
  43. 'headerBackground' => array('type'=>'color','label' => 'Couleur de fond en-têtes'),
  44. 'bodyBackground' => array('type'=>'color','label' => 'Couleur de fond du corps'),
  45. 'bodyColor' => array('type'=>'color','label' => 'Couleur texte du corps'),
  46. 'dashboard' => array('type'=>'integer','label' => 'Tableau de bord','link'=>'plugin/dashboard/Dashboard.class.php')
  47. );
  48. //Colonnes indexées
  49. public $indexes = array();
  50. public function __construct(){
  51. $this->model = self::MODEL_NEW;
  52. parent::__construct();
  53. }
  54. public function toArray($decoded=false){
  55. return array_merge(array(
  56. 'icon' => $this->icon,
  57. 'headerBackground' => $this->headerBackground,
  58. 'description' => $this->description,
  59. 'label' => $this->label,
  60. 'content' => $this->content
  61. ),parent::toArray($decoded));
  62. }
  63. function toData(){
  64. $row = $this->toArray();
  65. $model = DashboardWidget::model($this->model);
  66. $finalRow = $model->toArray();
  67. foreach($row as $attribute=>$value){
  68. if(isset($value)) $finalRow[$attribute] = $value;
  69. }
  70. return $finalRow;
  71. }
  72. //liste des Type possibles
  73. public static function types($key=null){
  74. $items = array(
  75. 'widget' => array('label'=>'Widget'),
  76. 'model' => array('label'=>'Modèle de widget'),
  77. );
  78. if(!isset($key)) return $items;
  79. return isset($items[$key]) ? $items[$key] : array('label'=>'Non définis');
  80. }
  81. public static function model($slug = null){
  82. $model = array();
  83. Plugin::callHook('widget',array(&$models));
  84. //@TODO: Placer en hook
  85. $clock = new DashboardWidget();
  86. $clock->icon = 'far fa-user';
  87. $clock->headerBackground = 'rgb(0, 123, 255)';
  88. $clock->description = 'Une Horloge toute couillone';
  89. $clock->label = 'Horloge';
  90. $clock->content = '<div class="text-center m-auto">13:37</div>';
  91. $clock->width = 3;
  92. $clock->height = 3;
  93. $clock->model = 'clock';
  94. $models['clock'] = $clock;
  95. $newModel = new DashboardWidget();
  96. $newModel->icon = 'far fa-user';
  97. $newModel->headerBackground = 'rgb(0, 123, 255)';
  98. $newModel->description = 'Type de widget non défini';
  99. $newModel->label = 'Nouveau widget';
  100. $newModel->content = '<small class="text-center m-auto text-muted">Veuillez configurer votre widget</small>';
  101. $newModel->width = 3;
  102. $newModel->height = 2;
  103. $newModel->model = self::MODEL_NEW;
  104. $models[self::MODEL_NEW] = $newModel;
  105. foreach($models as $model){
  106. if(!isset($model->model)) continue;
  107. if(empty($model->label)) $model->label = 'Sans titre';
  108. $models[$model->model] = $model;
  109. }
  110. if(!isset($slug)) return $models;
  111. return isset($models[$slug]) ? $models[$slug] : $model;
  112. }
  113. }