~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to lib/Widget/VideoIn.php

  • Committer: Dan Garner
  • Date: 2015-08-11 09:29:02 UTC
  • mto: This revision was merged to the branch mainline in revision 453.
  • Revision ID: git-v1:a86fb4369b7395c13367577d23b14c0ab4528c1a
Transitions fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/*
3
 
 * Xibo - Digital Signage - http://www.xibo.org.uk
4
 
 * Copyright (C) 2017 Spring Signage Ltd.
5
 
 *
6
 
 * This file is part of Xibo.
7
 
 *
8
 
 * Xibo is free software: you can redistribute it and/or modify
9
 
 * it under the terms of the GNU Affero General Public License as published by
10
 
 * the Free Software Foundation, either version 3 of the License, or
11
 
 * any later version. 
12
 
 *
13
 
 * Xibo is distributed in the hope that it will be useful,
14
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
 * GNU Affero General Public License for more details.
17
 
 *
18
 
 * You should have received a copy of the GNU Affero General Public License
19
 
 * along with Xibo.  If not, see <http://www.gnu.org/licenses/>.
20
 
 */
21
 
namespace Xibo\Widget;
22
 
 
23
 
use InvalidArgumentException;
24
 
use Respect\Validation\Validator as v;
25
 
 
26
 
class VideoIn extends ModuleWidget
27
 
{
28
 
    /**
29
 
     * Install or Update this module
30
 
     * @param ModuleFactory $moduleFactory
31
 
     */
32
 
    public function installOrUpdate($moduleFactory)
33
 
    {
34
 
        if ($this->module == null) {
35
 
            // Install
36
 
            $module = $moduleFactory->createEmpty();
37
 
            $module->name = 'Video In';
38
 
            $module->type = 'videoin';
39
 
            $module->class = 'Xibo\Widget\VideoIn';
40
 
            $module->description = 'A module for displaying Video and Audio from an external source';
41
 
            $module->imageUri = 'forms/video.gif';
42
 
            $module->enabled = 1;
43
 
            $module->previewEnabled = 0;
44
 
            $module->assignable = 1;
45
 
            $module->regionSpecific = 1;
46
 
            $module->renderAs = 'native';
47
 
            $module->schemaVersion = $this->codeSchemaVersion;
48
 
            $module->defaultDuration = 60;
49
 
            $module->settings = [];
50
 
 
51
 
            $this->setModule($module);
52
 
            $this->installModule();
53
 
        }
54
 
 
55
 
        // Check we are all installed
56
 
        $this->installFiles();
57
 
    }
58
 
 
59
 
 
60
 
    /**
61
 
     * Validate
62
 
     */
63
 
    public function validate()
64
 
    {
65
 
        // Validate
66
 
        if (!v::stringType()->notEmpty()->validate($this->getOption('sourceId')))
67
 
            throw new InvalidArgumentException(__('Please Select the sourceId'));
68
 
 
69
 
        if ($this->getUseDuration() == 1 && !v::intType()->min(1)->validate($this->getDuration()))
70
 
            throw new InvalidArgumentException(__('You must enter a duration.'));
71
 
    }
72
 
 
73
 
    public function add()
74
 
    {
75
 
        // Set some options
76
 
        $this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
77
 
        $this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
78
 
        $this->setOption('sourceId', $this->getSanitizer()->getString('sourceId' , 'hdmi'));
79
 
        $this->validate();
80
 
 
81
 
        // Save the widget
82
 
        $this->saveWidget();
83
 
    }
84
 
 
85
 
    /**
86
 
     */
87
 
    public function edit()
88
 
    {
89
 
        // Set some options
90
 
        $this->setDuration($this->getSanitizer()->getInt('duration', $this->getDuration()));
91
 
        $this->setUseDuration($this->getSanitizer()->getCheckbox('useDuration'));
92
 
        $this->setOption('sourceId', $this->getSanitizer()->getString('sourceId' ,'hdmi'));
93
 
 
94
 
        $this->validate();
95
 
 
96
 
        // Save the widget
97
 
        $this->saveWidget();
98
 
    }
99
 
 
100
 
    public function isValid()
101
 
    {
102
 
        // Client dependant
103
 
        return 2;
104
 
    }
105
 
 
106
 
    /**
107
 
     * Default code for the hover preview
108
 
     * @return string
109
 
     */
110
 
    public function hoverPreview()
111
 
    {
112
 
        // Default Hover window contains a thumbnail, media type and duration
113
 
        $output = '<div class="well">';
114
 
        $output .= '<div class="preview-module-image"><img alt="' . __($this->module->name) . ' thumbnail" src="' . $this->getConfig()->uri('img/' . $this->module->imageUri) . '" /></div>';
115
 
        $output .= '<div class="info">';
116
 
        $output .= '    <ul>';
117
 
        $output .= '    <li>' . __('Type') . ': ' . $this->module->name . '</li>';
118
 
        $output .= '    <li>' . __('Name') . ': ' . $this->getName() . '</li>';
119
 
        $output .= '    <li>' . __('Input') . ': ' . $this->getOption('sourceId') . '</li>';
120
 
        if ($this->getUseDuration() == 1)
121
 
            $output .= '    <li>' . __('Duration') . ': ' . $this->widget->duration . ' ' . __('seconds') . '</li>';
122
 
        $output .= '    </ul>';
123
 
        $output .= '</div>';
124
 
        $output .= '</div>';
125
 
 
126
 
        return $output;
127
 
 
128
 
    }
129
 
}