2017-11-06 14:23:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace view\history\details;
|
|
|
|
|
|
|
|
use \generic\core\i_view;
|
|
|
|
use \api\core\Request;
|
|
|
|
use \error\core\Err;
|
|
|
|
|
|
|
|
|
|
|
|
class main extends i_view{
|
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
public $id_history;
|
|
|
|
public $timeline = [];
|
|
|
|
public $entry = [];
|
2017-11-06 14:23:49 +00:00
|
|
|
|
|
|
|
|
2017-11-11 17:46:43 +00:00
|
|
|
/* (1) Constructor
|
|
|
|
*
|
|
|
|
* @id_history<id> UID of the history entry
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
2017-11-06 14:23:49 +00:00
|
|
|
public function __construct($id_history){
|
2017-11-11 17:46:43 +00:00
|
|
|
/* (1) Set attributes
|
|
|
|
---------------------------------------------------------*/
|
2017-11-06 14:23:49 +00:00
|
|
|
$this->id_history = $id_history;
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 12:01:29 +00:00
|
|
|
|
|
|
|
/* (3) Get entry data
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Request */
|
|
|
|
$entry_req = new Request('historyDefault/getById', [ 'id_entry' => $this->id_history ]);
|
|
|
|
|
|
|
|
/* (2) Get response */
|
|
|
|
$entry_res = $entry_req->dispatch();
|
|
|
|
|
|
|
|
/* (3) On success, store entry data */
|
|
|
|
if( $entry_res->error->get() == Err::Success )
|
|
|
|
$this->entry = $entry_res->get('entry');
|
|
|
|
|
|
|
|
|
|
|
|
/* (3) Get machine timeline
|
2017-11-11 17:46:43 +00:00
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Request */
|
|
|
|
$mac_req = new Request('historyDefault/get_timeline', [ 'id_entry' => $this->id_history ]);
|
|
|
|
|
|
|
|
/* (2) Get response */
|
|
|
|
$mac_res = $mac_req->dispatch();
|
|
|
|
|
|
|
|
/* (3) On success, store timeline data */
|
|
|
|
if( $mac_res->error->get() == Err::Success )
|
|
|
|
$this->timeline = $mac_res->get('timeline');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (2) Format timeline data to svg render
|
|
|
|
*
|
|
|
|
* @return svg<String> SVG raw render
|
|
|
|
*
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
public function svg(){
|
|
|
|
|
|
|
|
/* (1) Initialize variables
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Set date() timezone */
|
|
|
|
date_default_timezone_set('Europe/Paris');
|
|
|
|
|
|
|
|
/* (2) Init. result raw svg */
|
|
|
|
$RAW = '';
|
|
|
|
|
|
|
|
/* (3) Set global range */
|
|
|
|
$c = 0;
|
|
|
|
$cl = count($this->timeline);
|
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (4) Useful variables */
|
|
|
|
$y_pad = 80; // padding between each node
|
|
|
|
$line_pad = 50; // padding on each LINE end
|
|
|
|
$line_height = ( $cl + 1 ) * $y_pad; // line height (each node * @y_pad + @y_pad)
|
|
|
|
$height = $line_height + 2*$line_pad; // svg height
|
|
|
|
$width = 100; // svg width
|
|
|
|
$x = $width/2; // center width
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 12:01:29 +00:00
|
|
|
/* (5) Svg tag */
|
2017-11-12 16:22:35 +00:00
|
|
|
$RAW .= "<svg width='$width' height='$height' viewBox='0 0 $width $height' class='timeline'>";
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 12:01:29 +00:00
|
|
|
/* (6) Start CIRCLE */
|
2017-11-12 16:22:35 +00:00
|
|
|
$RAW .= "<circle cx='$x' cy='$line_pad' r='7' fill='#edf0f5' class='tstart'/>";
|
|
|
|
$RAW .= "<circle cx='$x' cy='$line_pad' r='4' fill='#555' class='tstart'/>";
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 12:01:29 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (2) Build barebone
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Default TIMELINE */
|
|
|
|
$line_end_y = $line_height + $line_pad;
|
|
|
|
$RAW .= "<path d='m$x $line_pad L$x $line_end_y' style='stroke-dasharray: 3px;' stroke='#444' class='timeline line'/>";
|
2017-11-11 17:46:43 +00:00
|
|
|
|
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (3) Build each action
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
for( $c = 0 ; $c < $cl ; $c++ ){
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (1) Calculate X */
|
|
|
|
$y = $line_pad + $y_pad + $c*$y_pad;
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (2) Get entry data */
|
|
|
|
$entry = $this->timeline[$c];
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (3) Get useful data */
|
|
|
|
$action_class = strtolower($entry['action_name']);
|
|
|
|
$icon_uri = '/src/static/timeline/'.$action_class.'@'.$this->get_action_color($action_class).'.svg';
|
|
|
|
$data_user = "data-user='".$entry['user_name']."'";
|
|
|
|
$data_machine = " data-machine='".$entry['machine_name']."'";
|
|
|
|
$data_action = " data-action='".$entry['action_name']."'";
|
|
|
|
$data_time = " data-time='".date('H:i:s d/m/Y', $entry['timestamp'])."'";
|
|
|
|
$data_tags = $data_user.$data_machine.$data_action.$data_time;
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
$y_img = $y - 5.5;
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (4) Draw entry circles */
|
|
|
|
$RAW .= "<circle cx='$x' cy='$y' r='15' class='timeline around $action_class' $data_tags />";
|
|
|
|
$RAW .= "<circle cx='$x' cy='$y' r='12' class='timeline center $action_class' />";
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (5) Draw entry icon (action) */
|
|
|
|
$x_decal = $x - 5.5;
|
|
|
|
$RAW .= "\t<image x='$x_decal' y='$y_img' width='12' height='12' xlink:href='$icon_uri' class='icon' />";
|
2017-11-12 13:53:33 +00:00
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (6) Draw circle below if current user */
|
|
|
|
if( $this->entry['id_user'] == $entry['id_user'] ){
|
|
|
|
$x_decal = $x - 21;
|
|
|
|
$RAW .= "<circle cx='$x_decal' cy='$y' r='2' class='timeline below $action_class' />";
|
|
|
|
}
|
2017-11-12 13:53:33 +00:00
|
|
|
|
|
|
|
|
2017-11-11 17:46:43 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-11-12 12:01:29 +00:00
|
|
|
/* (4) Close SVG
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
/* (1) Stop CIRCLE */
|
2017-11-12 16:22:35 +00:00
|
|
|
$y = $line_height + $line_pad;
|
|
|
|
$RAW .= "<circle cx='$x' cy='$y' r='6' fill='#edf0f5' class='tstop' />";
|
|
|
|
$RAW .= "<circle cx='$x' cy='$y' r='4' fill='#555' class='tstop' />";
|
2017-11-11 17:46:43 +00:00
|
|
|
|
2017-11-12 12:01:29 +00:00
|
|
|
/* (2) Close SVG tag */
|
2017-11-11 17:46:43 +00:00
|
|
|
$RAW .= "</svg>";
|
|
|
|
|
|
|
|
|
2017-11-12 16:22:35 +00:00
|
|
|
/* (5) Create invisible infobox (for now)
|
|
|
|
---------------------------------------------------------*/
|
|
|
|
$RAW .= "<div class='timeline infobox'></div>";
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-11-11 17:46:43 +00:00
|
|
|
return $RAW;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private function get_action_color($action_name){
|
|
|
|
|
|
|
|
return 'ffffff';
|
|
|
|
|
|
|
|
switch($action_name){
|
|
|
|
case 'start': return '2cde8b'; break;
|
|
|
|
case 'stop': return '3a3a3a'; break;
|
|
|
|
case 'lock': return 'e04343'; break;
|
|
|
|
case 'unlock': return 'af1c1c'; break;
|
|
|
|
case 'signal': return '3258d8'; break;
|
|
|
|
case 'unsignal': return '2041ab'; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return '000000';
|
2017-11-06 14:23:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|