Completed
Push — master ( 294889...618737 )
by Vojtěch
02:15
created

Panel::getIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SixtyEightPublishers\Application\Environment\Diagnostics;
6
7
use Nette\Utils\Html;
8
use SixtyEightPublishers\Application\Environment\Environment;
9
use SixtyEightPublishers\Application\Environment\Profile;
10
use SixtyEightPublishers\Application\Environment\ProfileContainer;
11
use Tracy\IBarPanel;
12
13
class Panel implements IBarPanel
14
{
15
	/** @var \SixtyEightPublishers\Application\Environment\ProfileContainer  */
16
	private $profiles;
17
18
	/** @var \SixtyEightPublishers\Application\Environment\Environment  */
19
	private $environment;
20
21
	/**
22
	 * @param \SixtyEightPublishers\Application\Environment\ProfileContainer    $profiles
23
	 * @param \SixtyEightPublishers\Application\Environment\Environment         $environment
24
	 */
25
	public function __construct(ProfileContainer $profiles, Environment $environment)
26
	{
27
		$this->profiles = $profiles;
28
		$this->environment = $environment;
29
	}
30
31
	/**
32
	 * @return string
33
	 */
34
	public function getTab()
35
	{
36
		return (string) Html::el('span title="Environment"')
37
			->addHtml($this->getIcon())
38
			->addHtml(Html::el('span class=tracy-label')->setText($this->environment->getProfile()->getName())
39
		);
40
	}
41
42
	/**
43
	 * @return string
44
	 */
45
	public function getPanel()
46
	{
47
		$panel = [];
48
		$panel[] = Html::el('h2')->setText('Configured profiles:');
49
50
		$table = Html::el('table');
51
		$table->addHtml(Html::el('thead')->addHtml(Html::el('tr')
52
			->addHtml(Html::el('th'))
53
			->addHtml(Html::el('th')->setText('name'))
54
			->addHtml(Html::el('th')->setText('country'))
55
			->addHtml(Html::el('th')->setText('language'))
56
			->addHtml(Html::el('th')->setText('currency'))
57
			->addHtml(Html::el('th')->setText('domain'))
58
		));
59
		$table->addHtml($tbody = Html::el('tbody'));
60
61
		/** @var Profile $profile */
62
		foreach ($this->profiles as $profile) {
63
			$tbody->addHtml($tr = Html::el('tr')
64
				->addHtml($firstCell = Html::el('td'))
65
				->addHtml(Html::el('td')->setText($profile->getName()))
66
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getCountries())))
67
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getLanguages())))
68
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getCurrencies())))
69
				->addHtml(Html::el('td')->setHtml(implode('<br>', $profile->getDomains())))
70
			);
71
72
			if ($profile->getName() === $this->environment->getProfile()->getName()) {
73
				$tr->class[] = 'yes';
74
				$firstCell->setText('✓');
75
			} elseif (!$profile->isEnabled()) {
76
				$tr->class[] = 'disabled';
77
				$firstCell->setText('✗');
78
			}
79
		}
80
81
		$panel[] = $table;
82
		$h1 = Html::el('h1')->setText('Environment');
83
84
		return $h1 . Html::el('div class="nette-inner tracy-inner sixtyEightPublishers-EnvironmentPanel"')->setHtml(implode(' ', $panel)) . $this->getStyles();
85
	}
86
87
	/**
88
	 * @return string
89
	 */
90
	private function getIcon()
91
	{
92
		return '<svg xmlns="http://www.w3.org/2000/svg" viewBox="2 2 28 28">
93
			<path fill="#007CFF" d="M16 4c-6.627 0-12 5.373-12 12s5.373 12 12 12c0.811 0 1.603-0.081 2.369-0.234-0.309-0.148-0.342-1.255-0.037-1.887 0.34-0.703 1.406-2.484 0.352-3.082s-0.762-0.867-1.406-1.559-0.381-0.795-0.422-0.973c-0.141-0.609 0.621-1.523 0.656-1.617s0.035-0.445 0.023-0.551-0.48-0.387-0.598-0.398-0.176 0.188-0.34 0.199-0.879-0.434-1.031-0.551-0.223-0.398-0.434-0.609-0.234-0.047-0.563-0.176-1.383-0.516-2.191-0.844-0.879-0.788-0.891-1.113-0.492-0.797-0.718-1.137c-0.225-0.34-0.267-0.809-0.349-0.703s0.422 1.336 0.34 1.371-0.258-0.34-0.492-0.645 0.246-0.141-0.504-1.617 0.234-2.229 0.281-3 0.633 0.281 0.328-0.211 0.023-1.523-0.211-1.898-1.57 0.422-1.57 0.422c0.035-0.363 1.172-0.984 1.992-1.559s1.321-0.129 1.98 0.082 0.703 0.141 0.48-0.070 0.094-0.316 0.609-0.234 0.656 0.703 1.441 0.645 0.082 0.152 0.188 0.352-0.117 0.176-0.633 0.527 0.012 0.352 0.926 1.020 0.633-0.445 0.539-0.938 0.668-0.105 0.668-0.105c0.563 0.375 0.459 0.021 0.869 0.15s1.522 1.069 1.522 1.069c-1.395 0.762-0.516 0.844-0.281 1.020s-0.48 0.516-0.48 0.516c-0.293-0.293-0.34 0.012-0.527 0.117s-0.012 0.375-0.012 0.375c-0.97 0.152-0.75 1.172-0.738 1.418s-0.621 0.621-0.785 0.973 0.422 1.113 0.117 1.16-0.609-1.148-2.25-0.703c-0.495 0.134-1.594 0.703-1.008 1.863s1.559-0.328 1.887-0.164-0.094 0.902-0.023 0.914 0.926 0.032 0.973 1.031 1.301 0.914 1.57 0.938 1.172-0.738 1.301-0.773 0.645-0.469 1.77 0.176 1.699 0.551 2.086 0.82 0.117 0.809 0.48 0.984 1.816-0.059 2.18 0.539-1.5 3.598-2.086 3.926-0.855 1.078-1.441 1.559-1.406 1.075-2.18 1.535c-0.685 0.407-0.808 1.136-1.113 1.367 5.37-1.193 9.386-5.985 9.386-11.714 0-6.627-5.373-12-12-12zM18.813 15.262c-0.164 0.047-0.504 0.352-1.336-0.141s-1.406-0.398-1.477-0.48c0 0-0.070-0.199 0.293-0.234 0.746-0.072 1.688 0.691 1.898 0.703s0.316-0.211 0.691-0.090c0.375 0.121 0.094 0.196-0.070 0.242zM14.887 5.195c-0.082-0.059 0.068-0.128 0.157-0.246 0.051-0.068 0.013-0.182 0.078-0.246 0.176-0.176 1.043-0.422 0.873 0.059s-0.979 0.527-1.108 0.434zM16.984 6.719c-0.293-0.012-0.983-0.085-0.855-0.211 0.495-0.492-0.188-0.633-0.609-0.668s-0.598-0.27-0.387-0.293 1.055 0.012 1.195 0.129 0.902 0.422 0.949 0.645 0 0.41-0.293 0.398zM19.527 6.637c-0.234 0.188-1.414-0.673-1.641-0.867-0.984-0.844-1.512-0.563-1.718-0.703s-0.133-0.328 0.183-0.609 1.207 0.094 1.723 0.152 1.113 0.457 1.125 0.931c0.012 0.474 0.563 0.909 0.328 1.097z"></path>
94
		</svg>';
95
	}
96
97
	/**
98
	 * @return string
99
	 */
100
	private function getStyles()
101
	{
102
		return "<style>
103
			#nette-debug .sixtyEightPublishers-EnvironmentPanel h2, #tracy-debug .sixtyEightPublishers-EnvironmentPanel h2 {
104
				font-size: 14px;
105
			}
106
			#nette-debug .sixtyEightPublishers-EnvironmentPanel tr.yes td, #tracy-debug .sixtyEightPublishers-EnvironmentPanel tr.yes td {
107
				background: #BDE678;
108
			}
109
			#nette-debug .sixtyEightPublishers-EnvironmentPanel tr.disabled td, #tracy-debug .sixtyEightPublishers-EnvironmentPanel tr.disabled td {
110
				background: #DDD;
111
				color: #888;
112
			}
113
		</style>";
114
	}
115
}
116