1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Widget view file. |
4
|
|
|
* |
5
|
|
|
* @package View |
6
|
|
|
* |
7
|
|
|
* @copyright YetiForce Sp. z o.o. |
8
|
|
|
* @license YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com) |
9
|
|
|
* @author Radosław Skrzypczak <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace YF\Modules\Base\View; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Widget view class. |
16
|
|
|
*/ |
17
|
|
|
class Widget extends \App\Controller\View |
18
|
|
|
{ |
19
|
|
|
use \App\Controller\ExposeMethodTrait; |
20
|
|
|
|
21
|
|
|
/** @var int Record ID */ |
22
|
|
|
protected $recordId; |
23
|
|
|
|
24
|
|
|
/** @var int Widget ID */ |
25
|
|
|
protected $widgetId; |
26
|
|
|
|
27
|
|
|
/** @var string Module name */ |
28
|
|
|
protected $moduleName; |
29
|
|
|
|
30
|
|
|
/** {@inheritdoc} */ |
31
|
|
|
public function __construct(\App\Request $request) |
32
|
|
|
{ |
33
|
|
|
parent::__construct($request); |
34
|
|
|
$this->exposeMethod('getContent'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** {@inheritdoc} */ |
38
|
|
|
public function checkPermission(): void |
39
|
|
|
{ |
40
|
|
|
parent::checkPermission(); |
41
|
|
|
$this->recordId = $this->request->getInteger('record'); |
42
|
|
|
$this->widgetId = $this->request->getInteger('widgetId'); |
43
|
|
|
$this->moduleName = $this->request->getModule(); |
44
|
|
|
if (!$this->recordId || !$this->widgetId || !isset(\App\Widgets::getInstance($this->moduleName)->getAll()[$this->widgetId])) { |
45
|
|
|
throw new \App\Exceptions\AppException('ERR_PERMISSION_DENIED'); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** {@inheritdoc} */ |
50
|
|
|
public function process() |
51
|
|
|
{ |
52
|
|
|
$mode = $this->request->getMode(); |
53
|
|
|
if ($mode && $this->isMethodExposed($mode)) { |
54
|
|
|
$this->invokeExposedMethod($mode); |
55
|
|
|
} else { |
56
|
|
|
$widget = \App\Widgets::getInstance($this->moduleName)->getAll()[$this->widgetId]; |
57
|
|
|
$widget->setRecordId($this->recordId); |
58
|
|
|
if ($scripts = $widget->getScripts()) { |
59
|
|
|
$widget->setScriptsObject($this->convertScripts($scripts, 'js')); |
60
|
|
|
} |
61
|
|
|
$this->viewer->assign('WIDGET', $widget); |
62
|
|
|
$this->viewer->view($widget->getTemplatePath(), $this->moduleName); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Gets widget content. |
68
|
|
|
* |
69
|
|
|
* @return void |
70
|
|
|
*/ |
71
|
|
|
public function getContent() |
72
|
|
|
{ |
73
|
|
|
$widget = \App\Widgets::getInstance($this->moduleName)->getAll()[$this->widgetId]; |
74
|
|
|
$widget->setRecordId($this->recordId); |
75
|
|
|
$this->viewer->assign('WIDGET', $widget); |
76
|
|
|
$this->viewer->view($widget->getTemplateContentPath(), $this->moduleName); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|