22
22
namespace Xibo\Widget;
24
24
use Respect\Validation\Validator as v;
25
use Xibo\Factory\MediaFactory;
26
use Xibo\Helper\Sanitize;
27
use Xibo\Helper\Theme;
25
28
use Xibo\Helper\Translate;
27
class Clock extends ModuleWidget
30
class Clock extends Module
29
32
public $codeSchemaVersion = 1;
31
34
public function installFiles()
33
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/vendor/jquery-1.11.1.min.js')->save();
34
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/vendor/jquery-cycle-2.1.6.min.js')->save();
35
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/vendor/moment.js')->save();
36
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/vendor/flipclock.min.js')->save();
37
$this->mediaFactory->createModuleSystemFile(PROJECT_ROOT . '/modules/xibo-layout-scaler.js')->save();
36
MediaFactory::createModuleFile('modules/vendor/jquery-1.11.1.min.js')->save();
37
MediaFactory::createModuleFile('modules/vendor/jquery-cycle-2.1.6.min.js')->save();
38
MediaFactory::createModuleFile('modules/vendor/moment.js')->save();
39
MediaFactory::createModuleFile('modules/vendor/flipclock.min.js')->save();
40
MediaFactory::createModuleFile('modules/xibo-layout-scaler.js')->save();
43
46
public function validate()
46
if ($this->getUseDuration() == 1 && !v::intType()->min(1)->validate($this->getDuration()))
47
throw new \InvalidArgumentException(__('Please enter a duration.'));
49
if (!v::int()->min(1)->validate($this->getDuration()))
50
throw new \InvalidArgumentException(__('You must enter a duration.'));
53
* path="/playlist/widget/clock/{playlistId}",
54
* operationId="WidgetClockAdd",
56
* summary="Add a Clock Widget",
57
* description="Add a new Clock Widget to the specified playlist",
61
* description="The playlist ID to add a Clock widget to",
68
* description="Optional Widget Name",
75
* description="The Widget Duration",
82
* description="(0, 1) Select 1 only if you will provide duration parameter as well",
89
* description="Flag (0 , 1) for Analogue clock the light and dark theme",
96
* description="Type of a clock widget 1-Analogue, 2-Digital, 3-Flip clock",
103
* description="The offset in minutes that should be applied to the current time, if a counter is selected then date/time to run from in the format Y-m-d H:i:s",
110
* description="For digital clock, format in which the time should be displayed example [HH:mm]",
115
* name="showSeconds",
117
* description="For Flip Clock, should the clock show seconds or not",
124
* description="For Flip Clock, supported options: TwelveHourClock TwentyFourHourClock HourlyCounter MinuteCounter DailyCounter",
130
* description="successful operation",
131
* @SWG\Schema(ref="#/definitions/Widget"),
134
* description="Location of the new widget",
54
* Add Media to the Database
140
56
public function add()
142
58
// You must also provide a duration (all media items must provide this field)
143
$this->setOption('name', $this->getSanitizer()->getString('name'));
144
$this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
145
$this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
146
$this->setOption('theme', $this->getSanitizer()->getInt('themeId', 0));
147
$this->setOption('clockTypeId', $this->getSanitizer()->getInt('clockTypeId', 1));
148
$this->setOption('offset', $this->getSanitizer()->getString('offset', 0));
149
$this->setRawNode('format', $this->getSanitizer()->getParam('ta_text', $this->getSanitizer()->getParam('format', '')));
150
$this->setOption('showSeconds', $this->getSanitizer()->getCheckbox('showSeconds', 1));
151
$this->setOption('clockFace', $this->getSanitizer()->getString('clockFace', 'TwentyFourHourClock'));
59
$this->setDuration(Sanitize::getInt('duration'));
60
$this->setOption('theme', Sanitize::getInt('themeId', 0));
61
$this->setOption('clockTypeId', Sanitize::getInt('clockTypeId', 1));
62
$this->setOption('offset', Sanitize::getInt('offset', 0));
63
$this->setRawNode('format', Sanitize::getParam('ta_text', ''));
153
65
$this->validate();
156
68
$this->saveWidget();
72
* Edit Media in the Database
162
74
public function edit()
164
76
// You must also provide a duration (all media items must provide this field)
165
$this->setOption('name', $this->getSanitizer()->getString('name'));
166
$this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
167
$this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
168
$this->setOption('theme', $this->getSanitizer()->getInt('themeId', 0));
169
$this->setOption('clockTypeId', $this->getSanitizer()->getInt('clockTypeId', 1));
170
$this->setOption('offset', $this->getSanitizer()->getString('offset', 0));
171
$this->setRawNode('format', $this->getSanitizer()->getParam('ta_text', $this->getSanitizer()->getParam('format', '')));
172
$this->setOption('showSeconds', $this->getSanitizer()->getCheckbox('showSeconds'));
173
$this->setOption('clockFace', $this->getSanitizer()->getString('clockFace'));
77
$this->setDuration(Sanitize::getInt('duration'));
78
$this->setOption('theme', Sanitize::getInt('themeId', 0));
79
$this->setOption('clockTypeId', Sanitize::getInt('clockTypeId', 1));
80
$this->setOption('offset', Sanitize::getInt('offset', 0));
81
$this->setRawNode('format', Sanitize::getParam('ta_text', ''));
175
83
$this->validate();
182
* Supported Clock Faces
185
public function clockFaces()
188
['id' => 'TwelveHourClock', 'value' => __('12h Clock')],
189
['id' => 'TwentyFourHourClock', 'value' => __('24h Clock')],
190
['id' => 'HourlyCounter', 'value' => __('Hourly Counter')],
191
['id' => 'MinuteCounter', 'value' => __('Minute Counter')],
192
['id' => 'DailyCounter', 'value' => __('Daily Counter')]
198
91
* Return the rendered resource to be used by the client (or a preview) for displaying this content.
199
92
* @param integer $displayId If this comes from a real client, this will be the display id.
252
145
// After body content
253
146
$options = array(
254
'previewWidth' => $this->getSanitizer()->getDouble('width', 0),
255
'previewHeight' => $this->getSanitizer()->getDouble('height', 0),
147
'previewWidth' => Sanitize::getDouble('width', 0),
148
'previewHeight' => Sanitize::getDouble('height', 0),
256
149
'originalWidth' => $this->region->width,
257
150
'originalHeight' => $this->region->height,
258
'scaleOverride' => $this->getSanitizer()->getDouble('scale_override', 0)
151
'scaleOverride' => Sanitize::getDouble('scale_override', 0)
261
154
$javaScriptContent = '<script type="text/javascript" src="' . $this->getResourceUrl('vendor/jquery-1.11.1.min.js') . '"></script>';
295
188
$template = 'clock-get-resource-flip';
297
190
// Head Content (CSS for flip clock)
298
$data['head'] = '<style type="text/css">' . file_get_contents(PROJECT_ROOT . '/modules/vendor/flipclock.css') . '</style>';
299
$data['offset'] = $this->getOption('offset', '0');
300
$data['duration'] = $this->getDuration();
301
$data['clockFace'] = $this->getOption('clockFace', 'TwentyFourHourClock');
302
$data['showSeconds'] = $this->getOption('showSeconds', 1);
191
$data['head'] = '<style type="text/css">' . file_get_contents('modules/vendor/flipclock.css') . ' </style>';
192
$data['offset'] = $this->GetOption('offset', 0);
304
194
// After body content
305
195
$javaScriptContent = '<script type = "text/javascript" src = "' . $this->getResourceUrl('vendor/jquery-1.11.1.min.js') . '" ></script > ';