PresenterSlides::getForm()   B
last analyzed

Complexity

Conditions 7
Paths 64

Size

Total Lines 99

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 64
nop 1
dl 0
loc 99
rs 7.0884
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
/**
12
 * presenter module for xoops
13
 *
14
 * @copyright       XOOPS Project (https://xoops.org)
15
 * @license         GPL 2.0 or later
16
 * @package         presenter
17
 * @since           2.5.5
18
 * @author          XOOPS Development Team <[email protected]> - <https://xoops.org>
19
 */
20
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
21
22
class PresenterSlides extends XoopsObject
23
{
24
    //Constructor
25
    /**
26
     * PresenterSlides constructor.
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
        $this->initVar('slides_id', XOBJ_DTYPE_INT);
32
        $this->initVar('slides_cid', XOBJ_DTYPE_INT);
33
        $this->initVar('slides_uid', XOBJ_DTYPE_INT);
34
        $this->initVar('slides_title', XOBJ_DTYPE_TXTBOX);
35
        $this->initVar('slides_content', XOBJ_DTYPE_TXTAREA);
36
37
        $this->initVar('css_id', XOBJ_DTYPE_TXTBOX);
38
        $this->initVar('css_class', XOBJ_DTYPE_TXTBOX);
39
40
        $this->initVar('slides_transition_x', XOBJ_DTYPE_TXTBOX);
41
        $this->initVar('slides_transition_y', XOBJ_DTYPE_TXTBOX);
42
        $this->initVar('slides_transition_z', XOBJ_DTYPE_TXTBOX);
43
        $this->initVar('slides_rotation_x', XOBJ_DTYPE_TXTBOX);
44
        $this->initVar('slides_rotation_y', XOBJ_DTYPE_TXTBOX);
45
        $this->initVar('slides_rotation_z', XOBJ_DTYPE_TXTBOX);
46
        $this->initVar('slides_scale_x', XOBJ_DTYPE_TXTBOX);
47
        $this->initVar('slides_scale_y', XOBJ_DTYPE_TXTBOX);
48
        $this->initVar('slides_scale_z', XOBJ_DTYPE_TXTBOX);
49
        $this->initVar('slides_created', XOBJ_DTYPE_LTIME);
50
        $this->initVar('slides_published', XOBJ_DTYPE_LTIME);
51
        $this->initVar('slides_position', XOBJ_DTYPE_INT);
52
        $this->initVar('slides_online', XOBJ_DTYPE_INT);
53
        $this->initVar('slides_type', XOBJ_DTYPE_INT);
54
        $this->initVar('slides_notes', XOBJ_DTYPE_TXTAREA);
55
        $this->initVar('slides_mp3', XOBJ_DTYPE_TXTBOX);
56
        $this->initVar('slides_time', XOBJ_DTYPE_INT);
57
        $this->initVar('slides_status', XOBJ_DTYPE_INT);
58
        $this->initVar('slides_waiting', XOBJ_DTYPE_INT);
59
        $this->initVar('slides_online', XOBJ_DTYPE_INT);
60
61
        $this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false);
62
        $this->initVar('dosmiley', XOBJ_DTYPE_INT, 1, false);
63
        $this->initVar('doxcode', XOBJ_DTYPE_INT, 1, false);
64
        $this->initVar('doimage', XOBJ_DTYPE_INT, 1, false);
65
        $this->initVar('dobr', XOBJ_DTYPE_INT, 1, false);
66
    }
67
68
    /**
69
     * @param bool $action
70
     * @return XoopsThemeForm
71
     */
72
    public function getForm($action = false)
73
    {
74
        global $xoopsDB, $xoopsModuleConfig;
75
76
        if (false === $action) {
77
            $action = $_SERVER['REQUEST_URI'];
78
        }
79
80
        $title = $this->isNew() ? sprintf(_AM_PRESENTER_SLIDES_ADD) : sprintf(_AM_PRESENTER_SLIDES_EDIT);
81
82
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
83
84
        $form = new XoopsThemeForm($title, 'form', $action, 'post', true);
85
        $form->setExtra('enctype="multipart/form-data"');
86
87
        // Slides_cid
88
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_CID, 'slides_cid', 50, 255, $this->getVar('slides_cid')), false);
89
        // Slides_uid
90
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_UID, 'slides_uid', 50, 255, $this->getVar('slides_uid')), false);
91
        // Slides_title
92
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_TITLE, 'slides_title', 50, 255, $this->getVar('slides_title')), true);
93
        // Slides_content
94
        $editor_configs           = [];
95
        $editor_configs['name']   = 'slides_content';
96
        $editor_configs['value']  = $this->getVar('slides_content', 'e');
97
        $editor_configs['rows']   = 10;
98
        $editor_configs['cols']   = 80;
99
        $editor_configs['width']  = '100%';
100
        $editor_configs['height'] = '400px';
101
        $editor_configs['editor'] = $GLOBALS['xoopsModuleConfig']['presenter_editor'];
102
        $form->addElement(new XoopsFormEditor(_AM_PRESENTER_SLIDES_CONTENT, 'slides_content', $editor_configs), true);
103
104
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_CSS_ID, 'css_id', 50, 255, $this->getVar('css_id')), true);
105
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_CSS_CLASS, 'css_class', 50, 255, $this->getVar('css_class')), true);
106
107
        // Slides_transition_x
108
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_TRANSITION_X, 'slides_transition_x', 50, 255, $this->getVar('slides_transition_x')), false);
109
        // Slides_transition_y
110
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_TRANSITION_Y, 'slides_transition_y', 50, 255, $this->getVar('slides_transition_y')), false);
111
        // Slides_transition_z
112
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_TRANSITION_Z, 'slides_transition_z', 50, 255, $this->getVar('slides_transition_z')), false);
113
        // Slides_rotation_x
114
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_ROTATION_X, 'slides_rotation_x', 50, 255, $this->getVar('slides_rotation_x')), false);
115
        // Slides_rotation_y
116
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_ROTATION_Y, 'slides_rotation_y', 50, 255, $this->getVar('slides_rotation_y')), false);
117
        // Slides_rotation_z
118
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_ROTATION_Z, 'slides_rotation_z', 50, 255, $this->getVar('slides_rotation_z')), false);
119
        // Slides_scale_x
120
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_SCALE_X, 'slides_scale_x', 50, 255, $this->getVar('slides_scale_x')), false);
121
        // Slides_scale_y
122
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_SCALE_Y, 'slides_scale_y', 50, 255, $this->getVar('slides_scale_y')), false);
123
        // Slides_scale_z
124
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_SCALE_Z, 'slides_scale_z', 50, 255, $this->getVar('slides_scale_z')), false);
125
        // Slides_created
126
        $form->addElement(new XoopsFormTextDateSelect(_AM_PRESENTER_SLIDES_CREATED, 'slides_created', '', $this->getVar('slides_created')));
127
        // Slides_published
128
        $form->addElement(new XoopsFormTextDateSelect(_AM_PRESENTER_SLIDES_PUBLISHED, 'slides_published', '', $this->getVar('slides_published')));
129
        // Slides_position
130
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_POSITION, 'slides_position', 50, 255, $this->getVar('slides_position')), false);
131
        // Slides_online
132
        $slides_online = $this->isNew() ? 0 : $this->getVar('slides_online');
133
        $form->addElement(new XoopsFormRadioYN(_AM_PRESENTER_SLIDES_ONLINE, 'slides_online', $slides_online), false);
134
        // Slides_type
135
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_TYPE, 'slides_type', 50, 255, $this->getVar('slides_type')), false);
136
        // Slides_notes
137
        $editor_configs           = [];
138
        $editor_configs['name']   = 'slides_notes';
139
        $editor_configs['value']  = $this->getVar('slides_notes', 'e');
140
        $editor_configs['rows']   = 10;
141
        $editor_configs['cols']   = 80;
142
        $editor_configs['width']  = '100%';
143
        $editor_configs['height'] = '400px';
144
        $editor_configs['editor'] = $GLOBALS['xoopsModuleConfig']['presenter_editor'];
145
        $form->addElement(new XoopsFormEditor(_AM_PRESENTER_SLIDES_NOTES, 'slides_notes', $editor_configs), false);
146
        // Slides_mp3
147
        $form->addElement(new XoopsFormFile(_AM_PRESENTER_SLIDES_MP3, 'slides_mp3', $xoopsModuleConfig['maxsize']), false);
148
        // Slides_time
149
        $form->addElement(new XoopsFormText(_AM_PRESENTER_SLIDES_TIME, 'slides_time', 50, 255, $this->getVar('slides_time')), false);
150
        // Slides_status
151
        $slides_status       = $this->isNew() ? 0 : $this->getVar('slides_status');
152
        $check_slides_status = new XoopsFormCheckBox(_AM_PRESENTER_SLIDES_STATUS, 'slides_status', $slides_status);
153
        $check_slides_status->addOption(1, ' ');
154
        $form->addElement($check_slides_status);
155
        // Slides_waiting
156
        $slides_waiting       = $this->isNew() ? 0 : $this->getVar('slides_waiting');
157
        $check_slides_waiting = new XoopsFormCheckBox(_AM_PRESENTER_SLIDES_WAITING, 'slides_waiting', $slides_waiting);
158
        $check_slides_waiting->addOption(1, ' ');
159
        $form->addElement($check_slides_waiting);
160
        // Slides_online
161
        $slides_online       = $this->isNew() ? 0 : $this->getVar('slides_online');
162
        $check_slides_online = new XoopsFormCheckBox(_AM_PRESENTER_SLIDES_ONLINE, 'slides_online', $slides_online);
163
        $check_slides_online->addOption(1, ' ');
164
        $form->addElement($check_slides_online);
165
166
        $form->addElement(new XoopsFormHidden('op', 'save'));
167
        $form->addElement(new XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
168
169
        return $form;
170
    }
171
}
172
173
/**
174
 * Class PresenterSlidesHandler
175
 */
176
class PresenterSlidesHandler extends XoopsPersistableObjectHandler
177
{
178
    /**
179
     * PresenterSlidesHandler constructor.
180
     * @param XoopsDatabase $db
181
     */
182
    public function __construct(XoopsDatabase $db)
183
    {
184
        parent::__construct($db, 'presenter_slides', 'presenterslides', 'slides_id', 'slides_cid');
185
    }
186
}
187