Passed
Push — master ( 0a0799...708775 )
by Georgi
03:43
created

Applet::addAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Epesi\Base\Dashboard\View;
4
5
use atk4\ui\View;
6
7
class Applet extends View
8
{
9
	public $ui = 'applet segment raised';
10
	public $defaultTemplate = 'applet.html';
11
	
12
	protected $appletId;
13
	protected $jointClass;
14
	protected $options;
15
	protected $admin = false;
16
	protected $locked = false;
17
	
18
	public function renderView()
19
	{		
20
		/**
21
		 * @var \Epesi\Base\Dashboard\Integration\Joints\AppletJoint $joint
22
		 */
23
		$joint = new $this->jointClass();
24
25
		$this->set('Name', $joint->caption())->setAttr('applet-id', $this->appletId);
26
		
27
		if ($this->admin) {
28
			$this->set($joint->info())->setAttr('searchkey', strtolower($joint->caption() . ';' . $joint->info()));
29
		}
30
		else {
31
			if (! $this->locked) {
32
				$this->addControl('close', 'applet-close')->setAttr('title', __('Close applet'));
0 ignored issues
show
Bug introduced by
It seems like __('Close applet') can also be of type array; however, parameter $value of atk4\ui\View::setAttr() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
				$this->addControl('close', 'applet-close')->setAttr('title', /** @scrutinizer ignore-type */ __('Close applet'));
Loading history...
33
			}
34
			
35
			$this->addControl('ellipsis vertical')->setAttr('title', __('Applet settings'))->link($this->app->moduleLink('dashboard', 'showSettings', [$this->appletId]));
36
			
37
			if ($link = $joint->go()) {
38
				$this->addControl('expand')->setAttr('title', __('Full screen'))->link($link);
39
			}			
40
41
			ob_start();
42
			$joint->body($this, $this->options?? $joint->defaultOptions());
43
44
			if ($content = ob_get_clean()) {
45
				$this->set($content);
46
			}
47
		}
48
		
49
		parent::renderView();
50
	}
51
	
52
	public function addControl($icon, $ui = null)
53
	{
54
		return $this->addAction($icon, 'applet-control ' . $ui);
55
	}
56
	
57
	public function addAction($icon, $ui = null)
58
	{
59
		$control = $this->add(['View', 'ui' => $ui], 'Controls')->link('#');
60
		$control->add(['Icon', $icon]);
61
		
62
		return $control;
63
	}
64
}
65