DashboardWidget.class.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. if(isset($model->css)){
  69. if(!isset($finalRow['cssUrl'])) $finalRow['cssUrl'] = array();
  70. foreach($model->css as $css){
  71. $finalRow['cssUrl'][] = ROOT_URL.'/'.str_replace(array('\\','/'),SLASH,str_replace(__ROOT__,'',$css));
  72. }
  73. }
  74. if(isset($model->js)){
  75. if(!isset($finalRow['jsUrl'])) $finalRow['jsUrl'] = array();
  76. foreach($model->js as $js){
  77. $finalRow['jsUrl'][] = ROOT_URL.'/'.str_replace(array('\\','/'),SLASH,str_replace(__ROOT__,'',$js));
  78. }
  79. }
  80. foreach($row as $attribute=>$value){
  81. if(isset($value)) $finalRow[$attribute] = $value;
  82. }
  83. return $finalRow;
  84. }
  85. //liste des Type possibles
  86. public static function types($key=null){
  87. $items = array(
  88. 'widget' => array('label'=>'Widget'),
  89. 'model' => array('label'=>'Modèle de widget'),
  90. );
  91. if(!isset($key)) return $items;
  92. return isset($items[$key]) ? $items[$key] : array('label'=>'Non définis');
  93. }
  94. public static function model($slug = null){
  95. $model = array();
  96. Plugin::callHook('widget',array(&$models));
  97. $newModel = new DashboardWidget();
  98. $newModel->icon = 'far fa-user';
  99. $newModel->headerBackground = 'rgb(0, 123, 255)';
  100. $newModel->description = 'Type de widget non défini';
  101. $newModel->label = 'Nouveau widget';
  102. $newModel->content = '<small class="text-center m-auto text-muted">Veuillez configurer votre widget</small>';
  103. $newModel->width = 3;
  104. $newModel->height = 2;
  105. $newModel->model = self::MODEL_NEW;
  106. $models[self::MODEL_NEW] = $newModel;
  107. foreach($models as $model){
  108. if(!isset($model->model)) continue;
  109. if(empty($model->label)) $model->label = 'Sans titre';
  110. $models[$model->model] = $model;
  111. }
  112. if(!isset($slug)) return $models;
  113. return isset($models[$slug]) ? $models[$slug] : $model;
  114. }
  115. }