DashboardWidget.class.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 = array(); //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 save(){
  56. if(is_array($this->meta)) $this->meta = json_encode($this->meta);
  57. parent::save();
  58. }
  59. public static function loadAll($columns = array(), $order = null, $limit = null, $selColumn = array('*'), $joins = 0,$alterator = null){
  60. return parent::loadAll($columns, $order, $limit, $selColumn, $joins,function(&$item){
  61. $item->meta = json_decode($item->meta,true);
  62. if(!is_array($item->meta)) $item->meta = array();
  63. });
  64. }
  65. public function toArray($decoded=false){
  66. return array_merge(array(
  67. 'icon' => $this->icon,
  68. 'headerBackground' => $this->headerBackground,
  69. 'description' => $this->description,
  70. 'label' => $this->label,
  71. 'content' => $this->content
  72. ),parent::toArray($decoded));
  73. }
  74. function toData(){
  75. $row = $this->toArray();
  76. $model = DashboardWidget::model($this->model);
  77. $finalRow = $model->toArray();
  78. if(isset($model->css)){
  79. if(!isset($finalRow['cssUrl'])) $finalRow['cssUrl'] = array();
  80. foreach($model->css as $css){
  81. $finalRow['cssUrl'][] = ROOT_URL.'/'.str_replace(array('\\','/'),SLASH,str_replace(__ROOT__,'',$css));
  82. }
  83. }
  84. if(isset($model->js)){
  85. if(!isset($finalRow['jsUrl'])) $finalRow['jsUrl'] = array();
  86. foreach($model->js as $js){
  87. $finalRow['jsUrl'][] = ROOT_URL.'/'.str_replace(array('\\','/'),SLASH,str_replace(__ROOT__,'',$js));
  88. }
  89. }
  90. foreach($row as $attribute=>$value){
  91. if(isset($value)) $finalRow[$attribute] = $value;
  92. }
  93. return $finalRow;
  94. }
  95. //liste des Type possibles
  96. public static function types($key=null){
  97. $items = array(
  98. 'widget' => array('label'=>'Widget'),
  99. 'model' => array('label'=>'Modèle de widget'),
  100. );
  101. if(!isset($key)) return $items;
  102. return isset($items[$key]) ? $items[$key] : array('label'=>'Non définis');
  103. }
  104. public static function model($slug = null){
  105. $model = array();
  106. Plugin::callHook('widget',array(&$models));
  107. $newModel = new DashboardWidget();
  108. $newModel->icon = 'far fa-user';
  109. $newModel->headerBackground = 'rgb(0, 123, 255)';
  110. $newModel->description = 'Type de widget non défini';
  111. $newModel->label = 'Nouveau widget';
  112. $newModel->content = '<small class="text-center m-auto text-muted">Veuillez configurer votre widget</small>';
  113. $newModel->width = 3;
  114. $newModel->height = 2;
  115. $newModel->model = self::MODEL_NEW;
  116. $models[self::MODEL_NEW] = $newModel;
  117. foreach($models as $model){
  118. if(!isset($model->model)) continue;
  119. if(empty($model->label)) $model->label = 'Sans titre';
  120. $models[$model->model] = $model;
  121. }
  122. if(!isset($slug)) return $models;
  123. return isset($models[$slug]) ? $models[$slug] : $model;
  124. }
  125. }