DashboardWidget.class.php 3.7 KB

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