1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22class CClock extends CDiv { 23 24 private $width; 25 private $height; 26 private $is_enabled = true; 27 28 public function __construct() { 29 parent::__construct(); 30 31 $this->addClass(ZBX_STYLE_CLOCK); 32 } 33 34 public function setWidth($value) { 35 $this->width = $value; 36 37 return $this; 38 } 39 40 public function setHeight($value) { 41 $this->height = $value; 42 43 return $this; 44 } 45 46 public function setEnabled($is_enabled) { 47 $this->is_enabled = $is_enabled; 48 49 return $this; 50 } 51 52 private function makeClockLine($width, $height, $x, $y, $deg) { 53 return (new CTag('rect', true)) 54 ->setAttribute('width', $width) 55 ->setAttribute('height', $height) 56 ->setAttribute('x', $x) 57 ->setAttribute('y', $y) 58 ->setAttribute('transform', 'rotate('.$deg.' 50 50)') 59 ->addClass(ZBX_STYLE_CLOCK_LINES); 60 } 61 62 private function makeClockFace() { 63 return [ 64 (new CTag('circle', true)) 65 ->setAttribute('cx', '50') 66 ->setAttribute('cy', '50') 67 ->setAttribute('r', '50') 68 ->addClass(ZBX_STYLE_CLOCK_FACE), 69 $this->makeClockLine('1.5', '5', '49.25', '5', '330'), 70 $this->makeClockLine('1.5', '5', '49.25', '5', '300'), 71 $this->makeClockLine('2.5', '7', '48.75', '5', '270'), 72 $this->makeClockLine('1.5', '5', '49.25', '5', '240'), 73 $this->makeClockLine('1.5', '5', '49.25', '5', '210'), 74 $this->makeClockLine('2.5', '7', '48.75', '5', '180'), 75 $this->makeClockLine('1.5', '5', '49.25', '5', '150'), 76 $this->makeClockLine('1.5', '5', '49.25', '5', '120'), 77 $this->makeClockLine('2.5', '7', '48.75', '5', '90'), 78 $this->makeClockLine('1.5', '5', '49.25', '5', '60'), 79 $this->makeClockLine('1.5', '5', '49.25', '5', '30'), 80 $this->makeClockLine('2.5', '7', '48.75', '5', '0') 81 ]; 82 } 83 84 private function makeClockHands() { 85 return [ 86 (new CTag('rect', true)) 87 ->setAttribute('width', '3.25') 88 ->setAttribute('height', '24') 89 ->setAttribute('x', '48.375') 90 ->setAttribute('y', '26') 91 ->setAttribute('rx', '1.5') 92 ->setAttribute('ry', '1.5') 93 ->addClass('clock-hand-h') 94 ->addClass(ZBX_STYLE_CLOCK_HAND), 95 (new CTag('rect', true)) 96 ->setAttribute('width', '3.25') 97 ->setAttribute('height', '35') 98 ->setAttribute('x', '48.375') 99 ->setAttribute('y', '15') 100 ->setAttribute('rx', '1.5') 101 ->setAttribute('ry', '1.5') 102 ->addClass('clock-hand-m') 103 ->addClass(ZBX_STYLE_CLOCK_HAND), 104 (new CTag('rect', true)) 105 ->setAttribute('width', '1.5') 106 ->setAttribute('height', '55') 107 ->setAttribute('x', '49.25') 108 ->setAttribute('y', '5') 109 ->addClass('clock-hand-s') 110 ->addClass(ZBX_STYLE_CLOCK_HAND_SEC), 111 (new CTag('circle', true)) 112 ->setAttribute('cx', '50') 113 ->setAttribute('cy', '50') 114 ->setAttribute('r', '3.5') 115 ->addClass(ZBX_STYLE_CLOCK_HAND_SEC) 116 ]; 117 } 118 119 private function build() { 120 $clock = (new CTag('svg', true)) 121 ->addItem($this->makeClockFace()) 122 ->addItem($this->makeClockHands()) 123 ->setAttribute('xmlns', 'http://www.w3.org/2000/svg') 124 ->setAttribute('viewBox', '0 0 100 100') 125 ->addClass(ZBX_STYLE_CLOCK_SVG); 126 127 if ($this->width !== null && $this->height !== null) { 128 $clock->setAttribute('style', 'width: '.$this->width.'px; height:'.$this->height.'px;'); 129 } 130 131 if (!$this->is_enabled) { 132 $clock->addClass(ZBX_STYLE_DISABLED); 133 } 134 135 $this->addItem($clock); 136 } 137 138 public function toString($destroy = true) { 139 $this->build(); 140 141 return parent::toString($destroy); 142 } 143} 144