DashboardWidget.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 $uid;
  24. public const MODEL_NEW = 'new';
  25. protected $TABLE_NAME = 'dashboard_widget';
  26. public $entityLabel = 'Bloc de tableau de bord';
  27. public $fields = array(
  28. 'id' => array('type'=>'key', 'label' => 'Identifiant'),
  29. 'model' => array('type'=>'text','label' => 'Modèle'),
  30. 'type' => array('type'=>'list','label' => 'Type'),
  31. 'meta' => array('type'=>'textarea','label' => 'Meta'),
  32. 'column' => array('type'=>'integer','label' => 'Colonne'),
  33. 'row' => array('type'=>'integer','label' => 'Ligne'),
  34. 'width' => array('type'=>'integer','label' => 'Largeur'),
  35. 'height' => array('type'=>'integer','label' => 'Hauteur'),
  36. 'dashboard' => array('type'=>'integer','label' => 'Tableau de bord','link'=>'plugin/dashboard/Dashboard.class.php')
  37. );
  38. //Colonnes indexées
  39. public $indexes = array();
  40. public function __construct(){
  41. $this->model = self::MODEL_NEW;
  42. parent::__construct();
  43. }
  44. public function toArray($decoded=false){
  45. return array_merge(array(
  46. 'icon' => $this->icon,
  47. 'headerBackground' => $this->headerBackground,
  48. 'description' => $this->description,
  49. 'label' => $this->label,
  50. 'content' => $this->content
  51. ),parent::toArray($decoded));
  52. }
  53. function toData(){
  54. $row = $this->toArray();
  55. $model = DashboardWidget::model($this->model);
  56. $finalRow = $model->toArray();
  57. foreach($row as $attribute=>$value){
  58. if(isset($value)) $finalRow[$attribute] = $value;
  59. }
  60. return $finalRow;
  61. }
  62. //liste des Type possibles
  63. public static function types($key=null){
  64. $items = array(
  65. 'widget' => array('label'=>'Widget'),
  66. 'model' => array('label'=>'Modèle de widget'),
  67. );
  68. if(!isset($key)) return $items;
  69. return isset($items[$key]) ? $items[$key] : array('label'=>'Non définis');
  70. }
  71. public static function model($slug = null){
  72. $model = array();
  73. Plugin::callHook('widget',array(&$models));
  74. //@TODO: Placer en hook
  75. $clock = new DashboardWidget();
  76. $clock->icon = 'far fa-user';
  77. $clock->headerBackground = 'rgb(0, 123, 255)';
  78. $clock->description = 'Une Horloge toute couillone';
  79. $clock->label = 'Horloge';
  80. $clock->content = '<div class="text-center m-auto">13:37</div>';
  81. $clock->width = 3;
  82. $clock->height = 3;
  83. $clock->model = 'clock';
  84. $models['clock'] = $clock;
  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. }