23
23
use Xibo\Entity\Permission;
24
24
use Xibo\Exception\AccessDeniedException;
25
use Xibo\Exception\ConfigurationException;
26
use Xibo\Exception\InvalidArgumentException;
27
use Xibo\Exception\NotFoundException;
28
use Xibo\Exception\XiboException;
29
use Xibo\Factory\DisplayFactory;
30
use Xibo\Factory\DisplayGroupFactory;
31
use Xibo\Factory\LayoutFactory;
32
25
use Xibo\Factory\MediaFactory;
33
26
use Xibo\Factory\ModuleFactory;
34
27
use Xibo\Factory\PermissionFactory;
35
28
use Xibo\Factory\PlaylistFactory;
36
29
use Xibo\Factory\RegionFactory;
37
use Xibo\Factory\ScheduleFactory;
38
30
use Xibo\Factory\TransitionFactory;
39
use Xibo\Factory\UserGroupFactory;
40
use Xibo\Factory\WidgetAudioFactory;
41
31
use Xibo\Factory\WidgetFactory;
42
use Xibo\Service\ConfigServiceInterface;
43
use Xibo\Service\DateServiceInterface;
44
use Xibo\Service\LogServiceInterface;
45
use Xibo\Service\SanitizerServiceInterface;
46
use Xibo\Storage\StorageServiceInterface;
50
* @package Xibo\Controller
32
use Xibo\Helper\Config;
35
use Xibo\Helper\Sanitize;
36
use Xibo\Storage\PDOConnect;
52
39
class Module extends Base
55
* @var StorageServiceInterface
62
private $moduleFactory;
65
* @var PlaylistFactory
67
private $playlistFactory;
72
private $mediaFactory;
75
* @var PermissionFactory
77
private $permissionFactory;
80
* @var UserGroupFactory
82
private $userGroupFactory;
87
private $widgetFactory;
90
* @var TransitionFactory
92
private $transitionFactory;
97
private $regionFactory;
99
/** @var LayoutFactory */
100
protected $layoutFactory;
102
/** @var DisplayGroupFactory */
103
protected $displayGroupFactory;
105
/** @var WidgetAudioFactory */
106
protected $widgetAudioFactory;
108
/** @var DisplayFactory */
109
private $displayFactory;
111
/** @var ScheduleFactory */
112
private $scheduleFactory;
115
* Set common dependencies.
116
* @param LogServiceInterface $log
117
* @param SanitizerServiceInterface $sanitizerService
118
* @param \Xibo\Helper\ApplicationState $state
119
* @param \Xibo\Entity\User $user
120
* @param \Xibo\Service\HelpServiceInterface $help
121
* @param DateServiceInterface $date
122
* @param ConfigServiceInterface $config
123
* @param StorageServiceInterface $store
124
* @param ModuleFactory $moduleFactory
125
* @param PlaylistFactory $playlistFactory
126
* @param MediaFactory $mediaFactory
127
* @param PermissionFactory $permissionFactory
128
* @param UserGroupFactory $userGroupFactory
129
* @param WidgetFactory $widgetFactory
130
* @param TransitionFactory $transitionFactory
131
* @param RegionFactory $regionFactory
132
* @param LayoutFactory $layoutFactory
133
* @param DisplayGroupFactory $displayGroupFactory
134
* @param WidgetAudioFactory $widgetAudioFactory
135
* @param DisplayFactory $displayFactory
136
* @param ScheduleFactory $scheduleFactory
138
public function __construct($log, $sanitizerService, $state, $user, $help, $date, $config, $store, $moduleFactory, $playlistFactory, $mediaFactory, $permissionFactory, $userGroupFactory, $widgetFactory, $transitionFactory, $regionFactory, $layoutFactory, $displayGroupFactory, $widgetAudioFactory, $displayFactory, $scheduleFactory)
140
$this->setCommonDependencies($log, $sanitizerService, $state, $user, $help, $date, $config);
142
$this->store = $store;
143
$this->moduleFactory = $moduleFactory;
144
$this->playlistFactory = $playlistFactory;
145
$this->mediaFactory = $mediaFactory;
146
$this->permissionFactory = $permissionFactory;
147
$this->userGroupFactory = $userGroupFactory;
148
$this->widgetFactory = $widgetFactory;
149
$this->transitionFactory = $transitionFactory;
150
$this->regionFactory = $regionFactory;
151
$this->layoutFactory = $layoutFactory;
152
$this->displayGroupFactory = $displayGroupFactory;
153
$this->widgetAudioFactory = $widgetAudioFactory;
154
$this->displayFactory = $displayFactory;
155
$this->scheduleFactory = $scheduleFactory;
159
42
* Display the module page
161
44
function displayPage()
48
// Do we have any modules to install?!
49
if (Config::GetSetting('MODULE_CONFIG_LOCKED_CHECKB') != 'Checked') {
50
// Get a list of matching files in the modules folder
51
$files = glob(PROJECT_ROOT . '/modules/*.json');
53
// Get a list of all currently installed modules
55
$data['modulesToInstall'] = [];
57
foreach (ModuleFactory::query() as $row) {
58
/* @var \Xibo\Entity\Module $row */
59
$installed[] = $row->type;
63
foreach ($files as $file) {
64
// Check to see if the module has already been installed
65
$fileName = explode('.', basename($file));
67
if (in_array($fileName[0], $installed))
70
// If not, open it up and get some information about it
71
$data['modulesToInstall'][] = json_decode(file_get_contents($file));
163
75
$this->getState()->template = 'module-page';
164
$this->getState()->setData([
165
'modulesToInstall' => $this->getInstallableModules()
76
$this->getState()->setData($data);
170
80
* A grid of modules
171
* @throws XiboException
173
82
public function grid()
175
$modules = $this->moduleFactory->query($this->gridRenderSort(), $this->gridRenderFilter());
84
$modules = ModuleFactory::query($this->gridRenderSort(), $this->gridRenderFilter());
177
86
foreach ($modules as $module) {
178
87
/* @var \Xibo\Entity\Module $module */
183
92
$module->includeProperty('buttons');
186
$module->buttons[] = array(
187
'id' => 'module_button_edit',
188
'url' => $this->urlFor('module.settings.form', ['id' => $module->moduleId]),
94
// If the module config is not locked, present some buttons
95
if (Config::GetSetting('MODULE_CONFIG_LOCKED_CHECKB') != 'Checked') {
193
if ($module->regionSpecific == 1) {
194
98
$module->buttons[] = array(
195
'id' => 'module_button_clear_cache',
196
'url' => $this->urlFor('module.clear.cache.form', ['id' => $module->moduleId]),
197
'text' => __('Clear Cache')
99
'id' => 'module_button_edit',
100
'url' => $this->urlFor('module.settings.form', ['id' => $module->moduleId]),
201
// Create a module object and return any buttons it may require
202
$moduleObject = $this->moduleFactory->create($module->type);
204
105
// Are there any buttons we need to provide as part of the module?
205
foreach ($moduleObject->settingsButtons() as $button) {
206
$button['text'] = __($button['text']);
207
$module->buttons[] = $button;
106
if (isset($module->settings['buttons'])) {
107
foreach ($module->settings['buttons'] as $button) {
108
$button['text'] = __($button['text']);
109
$module->buttons[] = $button;
211
114
$this->getState()->template = 'grid';
212
$this->getState()->recordsTotal = $this->moduleFactory->countLast();
115
$this->getState()->recordsTotal = ModuleFactory::countLast();
213
116
$this->getState()->setData($modules);
218
121
* @param int $moduleId
219
* @throws XiboException
221
123
public function settingsForm($moduleId)
224
$moduleConfigLocked = ($this->getConfig()->GetSetting('MODULE_CONFIG_LOCKED_CHECKB') == 'Checked');
126
if (Config::GetSetting('MODULE_CONFIG_LOCKED_CHECKB') == 'Checked')
127
throw new \InvalidArgumentException(__('Module Config Locked'));
226
129
if (!$this->getUser()->userTypeId == 1)
227
130
throw new AccessDeniedException();
229
$module = $this->moduleFactory->createById($moduleId);
132
$module = ModuleFactory::createById($moduleId);
231
134
$moduleFields = $module->settingsForm();
234
137
$this->getState()->template = ($moduleFields == null) ? 'module-form-settings' : $moduleFields;
235
138
$this->getState()->setData([
236
'moduleConfigLocked' => $moduleConfigLocked,
237
139
'module' => $module,
238
'help' => $this->getHelp()->link('Module', 'Edit')
140
'help' => Help::Link('Module', 'Edit')
244
146
* @param int $moduleId
245
* @throws XiboException
247
148
public function settings($moduleId)
250
$moduleConfigLocked = ($this->getConfig()->GetSetting('MODULE_CONFIG_LOCKED_CHECKB') == 'Checked');
151
if (Config::GetSetting('MODULE_CONFIG_LOCKED_CHECKB') == 'Checked')
152
throw new \InvalidArgumentException(__('Module Config Locked'));
252
154
if (!$this->getUser()->userTypeId == 1)
253
155
throw new AccessDeniedException();
255
$module = $this->moduleFactory->createById($moduleId);
256
$module->getModule()->defaultDuration = $this->getSanitizer()->getInt('defaultDuration');
257
$module->getModule()->validExtensions = $this->getSanitizer()->getString('validExtensions');
258
$module->getModule()->enabled = $this->getSanitizer()->getCheckbox('enabled');
259
$module->getModule()->previewEnabled = $this->getSanitizer()->getCheckbox('previewEnabled');
261
if (!$moduleConfigLocked)
262
$module->getModule()->imageUri = $this->getSanitizer()->getString('imageUri');
265
if (strpbrk($module->getModule()->validExtensions, '*.{}[]|') !== false)
266
throw new InvalidArgumentException('Comma separated file extensions only please, without the .', 'validExtensions');
157
$module = ModuleFactory::createById($moduleId);
158
$module->getModule()->validExtensions = Sanitize::getString('validExtensions');
159
$module->getModule()->imageUri = Sanitize::getString('imageUri');
160
$module->getModule()->enabled = Sanitize::getString('enabled');
161
$module->getModule()->previewEnabled = Sanitize::getString('previewEnabled');
268
163
// Install Files for this module
269
164
$module->installFiles();
316
* Form for the install list
317
* @throws XiboException
319
public function installListForm()
321
// Use the name to get details about this module.
322
$modules = $this->getInstallableModules();
324
if (count($modules) <= 0)
325
throw new InvalidArgumentException(__('Sorry, no modules available to install'), 'modules');
327
$this->getState()->template = 'module-form-install-list';
328
$this->getState()->setData([
329
'modulesToInstall' => $modules,
330
'help' => $this->getHelp()->link('Module', 'Install')
335
210
* @param string $name
336
* @throws InvalidArgumentException
338
212
public function installForm($name)
340
// Check the module hasn't already been installed
341
if ($this->checkModuleInstalled($name))
342
throw new InvalidArgumentException(__('Module already installed'), 'install');
214
if (!file_exists('../modules/' . $name . '.json'))
215
throw new \InvalidArgumentException(__('Invalid module'));
344
217
// Use the name to get details about this module.
345
if (file_exists(PROJECT_ROOT . '/modules/' . $name . '.json'))
346
$module = json_decode(file_get_contents(PROJECT_ROOT . '/modules/' . $name . '.json'));
347
else if (file_exists(PROJECT_ROOT . '/custom/' . $name . '.json'))
348
$module = json_decode(file_get_contents(PROJECT_ROOT . '/custom/' . $name . '.json'));
350
throw new \InvalidArgumentException(__('Invalid module'));
218
$module = json_decode(file_get_contents('../modules/' . $name . '.json'));
353
220
$this->getState()->template = 'module-form-install';
354
221
$this->getState()->setData([
355
222
'module' => $module,
356
'help' => $this->getHelp()->link('Module', 'Install')
223
'help' => Help::Link('Module', 'Install')
362
229
* @param string $name
363
* @throws XiboException
365
231
public function install($name)
367
$this->getLog()->notice('Request to install Module: ' . $name);
369
// Check the module hasn't already been installed
370
if ($this->checkModuleInstalled($name))
371
throw new InvalidArgumentException(__('Module already installed'), 'install');
373
if (file_exists(PROJECT_ROOT . '/modules/' . $name . '.json'))
374
$moduleDetails = json_decode(file_get_contents(PROJECT_ROOT . '/modules/' . $name . '.json'));
375
else if (file_exists(PROJECT_ROOT . '/custom/' . $name . '.json'))
376
$moduleDetails = json_decode(file_get_contents(PROJECT_ROOT . '/custom/' . $name . '.json'));
233
Log::notice('Request to install Module: ' . $name);
235
if (!file_exists('../modules/' . $name . '.json'))
378
236
throw new \InvalidArgumentException(__('Invalid module'));
238
// Use the name to get details about this module.
239
$moduleDetails = json_decode(file_get_contents('../modules/' . $name . '.json'));
380
241
// All modules should be capable of autoload
381
$module = $this->moduleFactory->createForInstall($moduleDetails->class);
382
$module->setUser($this->getUser());
383
$module->installOrUpdate($this->moduleFactory);
242
$module = ModuleFactory::createForInstall($moduleDetails->class);
243
$module->installOrUpdate();
385
$this->getLog()->notice('Module Installed: ' . $module->getModuleType());
245
Log::notice('Module Installed: ' . $module->getModuleType());
387
247
// Excellent... capital... success
388
248
$this->getState()->hydrate([
395
255
* Add Widget Form
396
256
* @param string $type
397
257
* @param int $playlistId
398
* @throws XiboException
400
259
public function addWidgetForm($type, $playlistId)
402
$playlist = $this->playlistFactory->getById($playlistId);
261
$playlist = PlaylistFactory::getById($playlistId);
404
263
if (!$this->getUser()->checkEditable($playlist))
405
264
throw new AccessDeniedException();
407
266
// Create a module to use
408
$module = $this->moduleFactory->createForWidget($type, null, $this->getUser()->userId, $playlistId);
267
$module = ModuleFactory::createForWidget($type, null, $this->getUser()->userId, $playlistId);
411
$this->getState()->template = $module->addForm();
412
$this->getState()->setData($module->setTemplateData([
270
$this->getState()->template = $module->getModuleType() . '-form-add';
271
$this->getState()->setData([
413
272
'playlist' => $playlist,
414
'media' => $this->mediaFactory->query(),
273
'media' => MediaFactory::query(),
415
274
'module' => $module
421
280
* @param string $type
422
281
* @param int $playlistId
423
* @throws XiboException
425
283
public function addWidget($type, $playlistId)
427
$playlist = $this->playlistFactory->getById($playlistId);
285
$playlist = PlaylistFactory::getById($playlistId);
429
287
if (!$this->getUser()->checkEditable($playlist))
430
288
throw new AccessDeniedException();
432
// Check we have a permission factory
433
if ($this->permissionFactory == null)
434
throw new ConfigurationException(__('Sorry there is an error with this request, cannot set inherited permissions'));
436
290
// Load some information about this playlist
437
$playlist->setChildObjectDependencies($this->regionFactory);
438
291
$playlist->load([
439
292
'playlistIncludeRegionAssignments' => false,
440
293
'loadWidgets' => false
443
296
// Create a module to use
444
$module = $this->moduleFactory->createForWidget($type, null, $this->getUser()->userId, $playlistId);
297
$module = ModuleFactory::createForWidget($type, null, $this->getUser()->userId, $playlistId);
446
299
// Inject the Current User
447
300
$module->setUser($this->getUser());
468
321
$this->getState()->hydrate([
470
322
'message' => sprintf(__('Added %s'), $module->getName()),
471
323
'id' => $module->widget->widgetId,
472
'data' => $module->widget
477
329
* Edit Widget Form
478
330
* @param int $widgetId
479
* @throws XiboException
481
332
public function editWidgetForm($widgetId)
483
$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($widgetId));
334
$module = ModuleFactory::createWithWidget(WidgetFactory::loadByWidgetId($widgetId));
485
336
if (!$this->getUser()->checkEditable($module->widget))
486
337
throw new AccessDeniedException();
489
$this->getState()->template = $module->editForm();
490
$this->getState()->setData($module->setTemplateData([
340
$this->getState()->template = $module->getModuleType() . '-form-edit';
341
$this->getState()->setData([
491
342
'module' => $module,
492
'media' => $this->mediaFactory->query(),
343
'media' => MediaFactory::query(),
493
344
'validExtensions' => str_replace(',', '|', $module->getModule()->validExtensions)
500
* path="/playlist/widget/{widgetId}",
501
* operationId="WidgetEdit",
503
* summary="Edit a Widget",
504
* description="Edit a Widget, please refer to individual widget Add documentation for module specific parameters",
508
* description="The widget ID to edit",
514
* description="successful operation",
515
* @SWG\Schema(ref="#/definitions/Widget"),
518
* description="Location of the edited widget",
524
350
* @param int $widgetId
525
* @throws XiboException
527
352
public function editWidget($widgetId)
529
$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($widgetId));
354
$module = ModuleFactory::createWithWidget(WidgetFactory::loadByWidgetId($widgetId));
531
356
if (!$this->getUser()->checkEditable($module->widget))
532
357
throw new AccessDeniedException();
541
366
$this->getState()->hydrate([
542
367
'message' => sprintf(__('Edited %s'), $module->getName()),
543
368
'id' => $module->widget->widgetId,
544
'data' => $module->widget
549
374
* Delete Widget Form
550
375
* @param int $widgetId
551
* @throws XiboException
553
377
public function deleteWidgetForm($widgetId)
555
$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($widgetId));
379
$module = ModuleFactory::createWithWidget(WidgetFactory::loadByWidgetId($widgetId));
557
381
if (!$this->getUser()->checkDeleteable($module->widget))
558
382
throw new AccessDeniedException();
560
// Set some dependencies that are used in the delete
561
$module->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory);
564
385
$this->getState()->template = 'module-form-delete';
565
386
$this->getState()->setData([
566
387
'module' => $module,
567
'help' => $this->getHelp()->link('Media', 'Delete')
388
'help' => Help::Link('Media', 'Delete')
574
* path="/playlist/widget/{widgetId}",
575
* operationId="WidgetDelete",
577
* summary="Delete a Widget",
578
* description="Deleted a specified widget",
582
* description="The widget ID to delete",
588
* description="successful operation",
592
394
* @param int $widgetId
593
* @throws XiboException
595
396
public function deleteWidget($widgetId)
597
$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($widgetId));
398
$module = ModuleFactory::createWithWidget(WidgetFactory::loadByWidgetId($widgetId));
599
400
if (!$this->getUser()->checkDeleteable($module->widget))
600
401
throw new AccessDeniedException();
602
// Set some dependencies that are used in the delete
603
$module->setChildObjectDependencies($this->layoutFactory, $this->widgetFactory, $this->displayGroupFactory);
605
403
$moduleName = $module->getName();
606
404
$widgetMedia = $module->widget->mediaIds;
667
462
array('id' => 'NW', 'name' => __('North West'))
670
'help' => $this->getHelp()->link('Transition', 'Edit')
465
'help' => Help::Link('Transition', 'Edit')
675
* Edit Widget transition
677
* path="/playlist/widget/transition/{type}/{widgetId}",
678
* operationId="WidgetEditTransition",
680
* summary="Adds In/Out transition",
681
* description="Adds In/Out transition to a specified widget",
685
* description="Transition type, available options: in, out",
692
* description="The widget ID to add the transition to",
697
* name="transitionType",
699
* description="Type of a transition, available Options: fly, fadeIn, fadeOut",
704
* name="transitionDuration",
706
* description="Duration of this transition in milliseconds",
711
* name="transitionDirection",
713
* description="The direction for this transition, only appropriate for transitions that move, such as fly. Available options: N, NE, E, SE, S, SW, W, NW",
719
* description="successful operation",
720
* @SWG\Schema(ref="#/definitions/Widget"),
723
* description="Location of the new widget",
470
* Edit Widget Transition
729
471
* @param string $type
730
472
* @param int $widgetId
732
474
public function editWidgetTransition($type, $widgetId)
734
$widget = $this->widgetFactory->getById($widgetId);
476
$widget = WidgetFactory::getById($widgetId);
736
478
if (!$this->getUser()->checkEditable($widget))
737
479
throw new AccessDeniedException();
743
$widget->setOptionValue('transIn', 'attrib', $this->getSanitizer()->getString('transitionType'));
744
$widget->setOptionValue('transInDuration', 'attrib', $this->getSanitizer()->getInt('transitionDuration'));
745
$widget->setOptionValue('transInDirection', 'attrib', $this->getSanitizer()->getString('transitionDirection'));
485
$widget->setOptionValue('transIn', 'attrib', Sanitize::getString('transitionType'));
486
$widget->setOptionValue('transInDuration', 'attrib', Sanitize::getInt('transitionDuration'));
487
$widget->setOptionValue('transInDirection', 'attrib', Sanitize::getString('transitionDirection'));
750
$widget->setOptionValue('transOut', 'attrib', $this->getSanitizer()->getString('transitionType'));
751
$widget->setOptionValue('transOutDuration', 'attrib', $this->getSanitizer()->getInt('transitionDuration'));
752
$widget->setOptionValue('transOutDirection', 'attrib', $this->getSanitizer()->getString('transitionDirection'));
492
$widget->setOptionValue('transOut', 'attrib', Sanitize::getString('transitionType'));
493
$widget->setOptionValue('transOutDuration', 'attrib', Sanitize::getInt('transitionDuration'));
494
$widget->setOptionValue('transOutDirection', 'attrib', Sanitize::getString('transitionDirection'));
772
* @param int $widgetId
773
* @throws XiboException
775
public function widgetAudioForm($widgetId)
777
$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($widgetId));
779
if (!$this->getUser()->checkEditable($module->widget))
780
throw new AccessDeniedException();
782
$audioAvailable = true;
783
if ($module->widget->countAudio() > 0) {
784
$audio = $this->mediaFactory->getById($module->widget->getAudioIds()[0]);
786
$this->getLog()->debug('Found audio: ' . $audio->mediaId . ', isEdited = ' . $audio->isEdited . ', retired = ' . $audio->retired);
787
$audioAvailable = ($audio->isEdited == 0 && $audio->retired == 0);
791
$this->getState()->template = 'module-form-audio';
792
$this->getState()->setData([
794
'media' => $this->mediaFactory->getByMediaType('audio'),
795
'isAudioAvailable' => $audioAvailable
800
* Edit an Audio Widget
802
* path="/playlist/widget/{widgetId}/audio",
803
* operationId="WidgetAssignedAudioEdit",
805
* summary="Parameters for edting/adding audio file to a specific widget",
806
* description="Parameters for edting/adding audio file to a specific widget",
810
* description="Id of a widget to which you want to add audio or edit existing audio",
817
* description="Id of a audio file in CMS library you wish to add to a widget",
824
* description="Volume percentage(0-100) for this audio to play at",
831
* description="Flag (0, 1) Should the audio loop if it finishes before the widget has finished?",
837
* description="successful operation",
838
* @SWG\Schema(ref="#/definitions/Widget"),
841
* description="Location of the new widget",
847
* @param int $widgetId
849
public function widgetAudio($widgetId)
851
$widget = $this->widgetFactory->getById($widgetId);
853
if (!$this->getUser()->checkEditable($widget))
854
throw new AccessDeniedException();
858
// Pull in the parameters we are expecting from the form.
859
$mediaId = $this->getSanitizer()->getInt('mediaId');
860
$volume = $this->getSanitizer()->getInt('volume', 100);
861
$loop = $this->getSanitizer()->getCheckbox('loop');
863
// Remove existing audio records.
864
foreach ($widget->audio as $audio) {
865
$widget->unassignAudio($audio);
869
$widgetAudio = $this->widgetAudioFactory->createEmpty();
870
$widgetAudio->mediaId = $mediaId;
871
$widgetAudio->volume = $volume;
872
$widgetAudio->loop = $loop;
874
$widget->assignAudio($widgetAudio);
880
$this->getState()->hydrate([
881
'message' => sprintf(__('Edited Audio')),
882
'id' => $widget->widgetId,
888
* Delete an Assigned Audio Widget
890
* path="/playlist/widget/{widgetId}/audio",
891
* operationId="WidgetAudioDelete",
893
* summary="Delete assigned audio widget",
894
* description="Delete assigned audio widget from specified widget ID",
898
* description="Id of a widget from which you want to delete the audio from",
904
* description="successful operation",
908
* @param int $widgetId
910
public function widgetAudioDelete($widgetId)
912
$widget = $this->widgetFactory->getById($widgetId);
914
if (!$this->getUser()->checkEditable($widget))
915
throw new AccessDeniedException();
919
foreach ($widget->audio as $audio) {
920
$widget->unassignAudio($audio);
926
$this->getState()->hydrate([
927
'message' => sprintf(__('Removed Audio')),
928
'id' => $widget->widgetId,
935
514
* @param string $tab
936
515
* @param int $widgetId
937
* @throws XiboException
516
* @throws \Xibo\Exception\NotFoundException
939
518
public function getTab($tab, $widgetId)
941
$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($widgetId));
520
$module = ModuleFactory::createWithWidget(WidgetFactory::loadByWidgetId($widgetId));
943
522
if (!$this->getUser()->checkViewable($module->widget))
944
523
throw new AccessDeniedException();
954
* @throws XiboException
956
public function getTemplateImage($type, $templateId)
958
$module = $this->moduleFactory->create($type);
959
$module->getTemplateImage($templateId);
960
$this->setNoOutput(true);
965
532
* @param $regionId
966
533
* @param $widgetId
967
* @throws XiboException
534
* @throws \Xibo\Exception\NotFoundException
969
536
public function getResource($regionId, $widgetId)
971
$module = $this->moduleFactory->createWithWidget($this->widgetFactory->loadByWidgetId($widgetId), $this->regionFactory->getById($regionId));
538
$module = ModuleFactory::createWithWidget(WidgetFactory::loadByWidgetId($widgetId), RegionFactory::getById($regionId));
973
540
if (!$this->getUser()->checkViewable($module->widget))
974
541
throw new AccessDeniedException();
976
543
// Call module GetResource
977
$module->setUser($this->getUser());
978
544
echo $module->getResource();
979
545
$this->setNoOutput(true);
985
* @throws XiboException
987
public function customFormRender($moduleId, $formName)
989
$module = $this->moduleFactory->createById($moduleId);
991
if (!method_exists($module, $formName))
992
throw new ConfigurationException(__('Method does not exist'));
994
$formDetails = $module->$formName();
996
$this->getState()->template = $formDetails['template'];
997
$this->getState()->setData($formDetails['data']);
1003
* @throws XiboException
1005
public function customFormExecute($moduleId, $formName)
1007
$module = $this->moduleFactory->createById($moduleId);
1009
if (!method_exists($module, $formName))
1010
throw new ConfigurationException(__('Method does not exist'));
1012
$module->$formName();
1013
$this->setNoOutput(true);
1017
* Get installable modules
1020
private function getInstallableModules()
1024
// Do we have any modules to install?!
1025
if ($this->getConfig()->GetSetting('MODULE_CONFIG_LOCKED_CHECKB') != 'Checked') {
1026
// Get a list of matching files in the modules folder
1027
$files = array_merge(glob(PROJECT_ROOT . '/modules/*.json'), glob(PROJECT_ROOT . '/custom/*.json'));
1029
// Get a list of all currently installed modules
1032
foreach ($this->moduleFactory->query() as $row) {
1033
/* @var \Xibo\Entity\Module $row */
1034
$installed[] = $row->installName;
1038
foreach ($files as $file) {
1039
// Check to see if the module has already been installed
1040
$fileName = explode('.', basename($file));
1042
if (in_array($fileName[0], $installed))
1045
// If not, open it up and get some information about it
1046
$modules[] = json_decode(file_get_contents($file));
1054
* Check whether a module is installed or not.
1055
* @param string $name
1058
private function checkModuleInstalled($name)
1061
$this->moduleFactory->getByInstallName($name);
1063
} catch (NotFoundException $notFoundException) {
1071
* @throws XiboException
1073
public function clearCacheForm($moduleId)
1075
$module = $this->moduleFactory->getById($moduleId);
1077
$this->getState()->template = 'module-form-clear-cache';
1078
$this->getState()->setData([
1079
'module' => $module,
1080
'help' => $this->getHelp()->link('Module', 'General')
1087
* @throws XiboException
1089
public function clearCache($moduleId)
1091
$module = $this->moduleFactory->createById($moduleId);
1092
$module->dumpCacheForModule();
1094
$this->getState()->hydrate([
1095
'message' => sprintf(__('Cleared the Cache'))