123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <?php
- /**
- * Define a Bloc de tableau de bord
- * @author Jean CARRUESCO
- * @category Plugin
- * @license copyright
- */
- class DashboardWidget extends Entity{
- public $id;
- public $model; //Modèle (Texte)
- public $type; //Type (Liste classique)
- public $meta = array(); //Meta (Texte Long)
- public $column = 0 ; //Colonne (Nombre Entier)
- public $row = 0 ; //Ligne (Nombre Entier)
- public $width = 1; //Largeur (Nombre Entier)
- public $height = 1; //Hauteur (Nombre Entier)
- public $dashboard; //Tableau de bord (Nombre Entier)
- public $refresh;
- public $icon;
- public $iconColor;
- public $titleColor;
- public $headerBackground;
- public $bodyBackground;
- public $bodyColor;
- public $description;
- public $label;
- public $content;
- public $uid;
- public const MODEL_NEW = 'new';
- protected $TABLE_NAME = 'dashboard_widget';
- public $entityLabel = 'Bloc de tableau de bord';
- public $fields = array(
- 'id' => array('type'=>'key', 'label' => 'Identifiant'),
- 'model' => array('type'=>'text','label' => 'Modèle'),
- 'type' => array('type'=>'list','label' => 'Type'),
- 'meta' => array('type'=>'textarea','label' => 'Meta'),
- 'column' => array('type'=>'integer','label' => 'Colonne'),
- 'row' => array('type'=>'integer','label' => 'Ligne'),
- 'width' => array('type'=>'integer','label' => 'Largeur'),
- 'height' => array('type'=>'integer','label' => 'Hauteur'),
- 'icon' => array('type'=>'icon','label' => 'Icône'),
- 'iconColor' => array('type'=>'color','label' => 'Couleur icône'),
- 'titleColor' => array('type'=>'color','label' => 'Couleur titre'),
- 'headerBackground' => array('type'=>'color','label' => 'Couleur de fond en-têtes'),
- 'bodyBackground' => array('type'=>'color','label' => 'Couleur de fond du corps'),
- 'bodyColor' => array('type'=>'color','label' => 'Couleur texte du corps'),
- 'dashboard' => array('type'=>'integer','label' => 'Tableau de bord','link'=>'plugin/dashboard/Dashboard.class.php')
- );
- //Colonnes indexées
- public $indexes = array();
- public function __construct(){
- $this->model = self::MODEL_NEW;
- parent::__construct();
- }
- public function save(){
- if(is_array($this->meta)) $this->meta = json_encode($this->meta);
- parent::save();
- }
- public function toArray($decoded=false){
- return array_merge(array(
- 'icon' => $this->icon,
- 'headerBackground' => $this->headerBackground,
- 'description' => $this->description,
- 'label' => $this->label,
- 'content' => $this->content
- ),parent::toArray($decoded));
- }
- function toData(){
- $row = $this->toArray();
- $model = DashboardWidget::model($this->model);
- $finalRow = $model->toArray();
- if(isset($model->css)){
- if(!isset($finalRow['cssUrl'])) $finalRow['cssUrl'] = array();
- foreach($model->css as $css){
- $finalRow['cssUrl'][] = ROOT_URL.'/'.str_replace(array('\\','/'),SLASH,str_replace(__ROOT__,'',$css));
- }
- }
- if(isset($model->js)){
- if(!isset($finalRow['jsUrl'])) $finalRow['jsUrl'] = array();
- foreach($model->js as $js){
- $finalRow['jsUrl'][] = ROOT_URL.'/'.str_replace(array('\\','/'),SLASH,str_replace(__ROOT__,'',$js));
- }
- }
- foreach($row as $attribute=>$value){
- if(isset($value)) $finalRow[$attribute] = $value;
- }
- return $finalRow;
- }
- //liste des Type possibles
- public static function types($key=null){
- $items = array(
- 'widget' => array('label'=>'Widget'),
- 'model' => array('label'=>'Modèle de widget'),
- );
- if(!isset($key)) return $items;
- return isset($items[$key]) ? $items[$key] : array('label'=>'Non définis');
- }
-
- public function getContent(&$widget){
-
- if(!isset($this->content) || is_string($this->content) ) return $this->content;
-
- $method = $this->content;
-
- $widget->meta = json_decode($widget->meta,true);
- if(!is_array($widget->meta)) $widget->meta = array();
- $method($widget);
-
- }
- public static function model($slug = null){
- $model = array();
- Plugin::callHook('widget',array(&$models));
- $newModel = new DashboardWidget();
- $newModel->icon = 'far fa-user';
- $newModel->headerBackground = 'rgb(0, 123, 255)';
- $newModel->description = 'Type de widget non défini';
- $newModel->label = 'Nouveau widget';
- $newModel->content = '<small class="text-center m-auto text-muted">Veuillez configurer votre widget</small>';
- $newModel->width = 3;
- $newModel->height = 2;
- $newModel->model = self::MODEL_NEW;
- $models[self::MODEL_NEW] = $newModel;
- foreach($models as $model){
- if(!isset($model->model)) continue;
- if(empty($model->label)) $model->label = 'Sans titre';
- $models[$model->model] = $model;
- }
- if(!isset($slug)) return $models;
- return isset($models[$slug]) ? $models[$slug] : $model;
- }
- }
|