Testfields::getFormTestfields()   F
last analyzed

Complexity

Conditions 26
Paths > 20000

Size

Total Lines 222
Code Lines 172

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 26
eloc 172
nc 7864320
nop 1
dl 0
loc 222
rs 0
c 1
b 1
f 1

How to fix   Long Method    Complexity   

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
namespace XoopsModules\Mymodule3;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * My Module 3 module for xoops
17
 *
18
 * @copyright     2020 XOOPS Project (https://xooops.org)
19
 * @license        GPL 2.0 or later
20
 * @package        mymodule3
21
 * @since          1.0
22
 * @min_xoops      2.5.9
23
 * @author         TDM XOOPS - Email:<[email protected]> - Website:<http://xoops.org>
24
 */
25
26
use XoopsModules\Mymodule3;
27
28
defined('XOOPS_ROOT_PATH') || die('Restricted access');
29
30
/**
31
 * Class Object Testfields
32
 */
33
class Testfields extends \XoopsObject
34
{
35
	/**
36
	 * Constructor 
37
	 *
38
	 * @param null
39
	 */
40
	public function __construct()
41
	{
42
		$this->initVar('tf_id', XOBJ_DTYPE_INT);
43
		$this->initVar('tf_text', XOBJ_DTYPE_TXTBOX);
44
		$this->initVar('tf_textarea', XOBJ_DTYPE_TXTAREA);
45
		$this->initVar('tf_dhtml', XOBJ_DTYPE_TXTAREA);
46
		$this->initVar('tf_checkbox', XOBJ_DTYPE_INT);
47
		$this->initVar('tf_yesno', XOBJ_DTYPE_INT);
48
		$this->initVar('tf_selectbox', XOBJ_DTYPE_INT);
49
		$this->initVar('tf_user', XOBJ_DTYPE_INT);
50
		$this->initVar('tf_color', XOBJ_DTYPE_TXTBOX);
51
		$this->initVar('tf_imagelist', XOBJ_DTYPE_TXTBOX);
52
		$this->initVar('tf_urlfile', XOBJ_DTYPE_TXTBOX);
53
		$this->initVar('tf_uplimage', XOBJ_DTYPE_TXTBOX);
54
		$this->initVar('tf_uplfile', XOBJ_DTYPE_TXTBOX);
55
		$this->initVar('tf_textdateselect', XOBJ_DTYPE_INT);
56
		$this->initVar('tf_selectfile', XOBJ_DTYPE_TXTBOX);
57
		$this->initVar('tf_password', XOBJ_DTYPE_TXTBOX);
58
		$this->initVar('tf_country_list', XOBJ_DTYPE_TXTBOX);
59
		$this->initVar('tf_language', XOBJ_DTYPE_TXTBOX);
60
		$this->initVar('tf_radio', XOBJ_DTYPE_INT);
61
		$this->initVar('tf_status', XOBJ_DTYPE_INT);
62
		$this->initVar('tf_datetime', XOBJ_DTYPE_INT);
63
		$this->initVar('tf_combobox', XOBJ_DTYPE_INT);
64
	}
65
66
	/**
67
	 * @static function &getInstance
68
	 *
69
	 * @param null
70
	 */
71
	public static function getInstance()
72
	{
73
		static $instance = false;
74
		if (!$instance) {
75
			$instance = new self();
76
		}
77
	}
78
79
	/**
80
	 * The new inserted $Id
81
	 * @return inserted id
0 ignored issues
show
Bug introduced by
The type XoopsModules\Mymodule3\inserted was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
82
	 */
83
	public function getNewInsertedIdTestfields()
84
	{
85
		$newInsertedId = $GLOBALS['xoopsDB']->getInsertId();
86
		return $newInsertedId;
87
	}
88
89
	/**
90
	 * @public function getForm
91
	 * @param bool $action
92
	 * @return \XoopsThemeForm
93
	 */
94
	public function getFormTestfields($action = false)
95
	{
96
		$helper = \XoopsModules\Mymodule3\Helper::getInstance();
97
		if (false === $action) {
98
			$action = $_SERVER['REQUEST_URI'];
99
		}
100
		// Permissions for uploader
101
		$grouppermHandler = xoops_getHandler('groupperm');
102
		$groups = is_object($GLOBALS['xoopsUser']) ? $GLOBALS['xoopsUser']->getGroups() : XOOPS_GROUP_ANONYMOUS;
103
		if ($GLOBALS['xoopsUser']) {
104
			if (!$GLOBALS['xoopsUser']->isAdmin($GLOBALS['xoopsModule']->mid())) {
105
				$permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false;
0 ignored issues
show
Bug introduced by
The method checkRight() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
				$permissionUpload = $grouppermHandler->/** @scrutinizer ignore-call */ checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false;
Loading history...
106
			} else {
107
				$permissionUpload = true;
108
			}
109
		} else {
110
			$permissionUpload = $grouppermHandler->checkRight('upload_groups', 32, $groups, $GLOBALS['xoopsModule']->getVar('mid')) ? true : false;
111
		}
112
		// Title
113
		$title = $this->isNew() ? sprintf(_AM_MYMODULE3_TESTFIELD_ADD) : sprintf(_AM_MYMODULE3_TESTFIELD_EDIT);
114
		// Get Theme Form
115
		xoops_load('XoopsFormLoader');
116
		$form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
117
		$form->setExtra('enctype="multipart/form-data"');
118
		// Form Text tfText
119
		$form->addElement(new \XoopsFormText( _AM_MYMODULE3_TESTFIELD_TEXT, 'tf_text', 50, 255, $this->getVar('tf_text') ));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('tf_text') can also be of type array and array; however, parameter $value of XoopsFormText::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

119
		$form->addElement(new \XoopsFormText( _AM_MYMODULE3_TESTFIELD_TEXT, 'tf_text', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('tf_text') ));
Loading history...
120
		// Form Editor TextArea tfTextarea
121
		$form->addElement(new \XoopsFormTextArea( _AM_MYMODULE3_TESTFIELD_TEXTAREA, 'tf_textarea', $this->getVar('tf_textarea'), 4, 47 ));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('tf_textarea') can also be of type array and array; however, parameter $value of XoopsFormTextArea::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

121
		$form->addElement(new \XoopsFormTextArea( _AM_MYMODULE3_TESTFIELD_TEXTAREA, 'tf_textarea', /** @scrutinizer ignore-type */ $this->getVar('tf_textarea'), 4, 47 ));
Loading history...
122
		// Form Editor DhtmlTextArea tfDhtml
123
		$editorConfigs = [];
124
		$editorConfigs['name'] = 'tf_dhtml';
125
		$editorConfigs['value'] = $this->getVar('tf_dhtml', 'e');
126
		$editorConfigs['rows'] = 5;
127
		$editorConfigs['cols'] = 40;
128
		$editorConfigs['width'] = '100%';
129
		$editorConfigs['height'] = '400px';
130
		$editorConfigs['editor'] = $helper->getConfig('editor_dhtml');
131
		$form->addElement(new \XoopsFormEditor( _AM_MYMODULE3_TESTFIELD_DHTML, 'tf_dhtml', $editorConfigs));
132
		// Form Check Box tfCheckbox
133
		$tfCheckbox = $this->isNew() ? 0 : $this->getVar('tf_checkbox');
134
		$checkTfCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_TESTFIELD_CHECKBOX, 'tf_checkbox', $tfCheckbox);
135
		$checkTfCheckbox->addOption(1, _AM_MYMODULE3_TESTFIELD_CHECKBOX);
136
		$form->addElement($checkTfCheckbox);
137
		// Form Radio Yes/No tfYesno
138
		$tfYesno = $this->isNew() ? 0 : $this->getVar('tf_yesno');
139
		$form->addElement(new \XoopsFormRadioYN( _AM_MYMODULE3_TESTFIELD_YESNO, 'tf_yesno', $tfYesno));
0 ignored issues
show
Bug introduced by
It seems like $tfYesno can also be of type array and array; however, parameter $value of XoopsFormRadioYN::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

139
		$form->addElement(new \XoopsFormRadioYN( _AM_MYMODULE3_TESTFIELD_YESNO, 'tf_yesno', /** @scrutinizer ignore-type */ $tfYesno));
Loading history...
140
		// Testfields handler
141
		$testfieldsHandler = $helper->getHandler('testfields');
142
		// Form Select tfSelectbox
143
		$tfSelectboxSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_SELECTBOX, 'tf_selectbox', $this->getVar('tf_selectbox'));
144
		$tfSelectboxSelect->addOption('Empty');
145
		$tfSelectboxSelect->addOptionArray($testfieldsHandler->getList());
0 ignored issues
show
Bug introduced by
The method getList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsModuleHandler or XoopsImageHandler or XoopsRankHandler or XoopsCommentHandler or XoopsTplsetHandler or XoopsAvatarHandler or XoopsBlockHandler or XoopsImagesetHandler or XoopsPersistableObjectHandler or XoopsImagecategoryHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

145
		$tfSelectboxSelect->addOptionArray($testfieldsHandler->/** @scrutinizer ignore-call */ getList());
Loading history...
146
		$form->addElement($tfSelectboxSelect);
147
		// Form Select User tfUser
148
		$form->addElement(new \XoopsFormSelectUser( _AM_MYMODULE3_TESTFIELD_USER, 'tf_user', false, $this->getVar('tf_user') ));
149
		// Form Color Picker tfColor
150
		$form->addElement(new \XoopsFormColorPicker( _AM_MYMODULE3_TESTFIELD_COLOR, 'tf_color', $this->getVar('tf_color') ));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('tf_color') can also be of type array and array; however, parameter $value of XoopsFormColorPicker::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

150
		$form->addElement(new \XoopsFormColorPicker( _AM_MYMODULE3_TESTFIELD_COLOR, 'tf_color', /** @scrutinizer ignore-type */ $this->getVar('tf_color') ));
Loading history...
151
		// Form Frameworks Images Files tfImagelist
152
		// Form Frameworks Images tfImagelist: Select Uploaded Image
153
		$getTfImagelist = $this->getVar('tf_imagelist');
154
		$tfImagelist = $getTfImagelist ? $getTfImagelist : 'blank.gif';
155
		$imageDirectory = '/Frameworks/moduleclasses/icons/32';
156
		$imageTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_IMAGELIST, '<br>' );
157
		$imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE3_TESTFIELD_IMAGELIST_UPLOADS, ".{$imageDirectory}/"), 'tf_imagelist', $tfImagelist, 5);
158
		$imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory );
159
		foreach($imageArray as $image1) {
160
			$imageSelect->addOption("{$image1}", $image1);
161
		}
162
		$imageSelect->setExtra("onchange='showImgSelected(\"imglabel_tf_imagelist\", \"tf_imagelist\", \"" . $imageDirectory . "\", \"\", \"" . XOOPS_URL . "\")'");
163
		$imageTray->addElement($imageSelect, false);
164
		$imageTray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . "/" . $imageDirectory . "/" . $tfImagelist . "' id='imglabel_tf_imagelist' alt='' style='max-width:100px' />"));
165
		// Form Frameworks Images tfImagelist: Upload new image
166
		$fileSelectTray = new \XoopsFormElementTray('', '<br>' );
167
		$fileSelectTray->addElement(new \XoopsFormFile( _AM_MYMODULE3_FORM_UPLOAD_NEW, 'tf_imagelist', $helper->getConfig('maxsize_image') ));
168
		$fileSelectTray->addElement(new \XoopsFormLabel(''));
169
		$imageTray->addElement($fileSelectTray);
170
		$form->addElement($imageTray);
171
		// Form Url Text File tfUrlfile
172
		$formUrlFile = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_URLFILE, '<br><br>' );
173
		$formUrl = $this->isNew() ? '' : $this->getVar('tf_urlfile');
174
		$formText = new \XoopsFormText( _AM_MYMODULE3_TESTFIELD_URLFILE_UPLOADS, 'tf_urlfile', 75, 255, $formUrl );
175
		$formUrlFile->addElement($formText);
176
		$formUrlFile->addElement(new \XoopsFormFile( _AM_MYMODULE3_FORM_UPLOAD, 'tf_urlfile', $helper->getConfig('maxsize_file') ));
177
		$form->addElement($formUrlFile);
178
		// Form Image tfUplimage
179
		// Form Image tfUplimage: Select Uploaded Image 
180
		$getTfUplimage = $this->getVar('tf_uplimage');
181
		$tfUplimage = $getTfUplimage ? $getTfUplimage : 'blank.gif';
182
		$imageDirectory = '/uploads/mymodule3/images/testfields';
183
		$imageTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_UPLIMAGE, '<br>' );
184
		$imageSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE3_TESTFIELD_UPLIMAGE_UPLOADS, ".{$imageDirectory}/"), 'tf_uplimage', $tfUplimage, 5);
185
		$imageArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $imageDirectory );
186
		foreach($imageArray as $image1) {
187
			$imageSelect->addOption("{$image1}", $image1);
188
		}
189
		$imageSelect->setExtra("onchange='showImgSelected(\"imglabel_tf_uplimage\", \"tf_uplimage\", \"" . $imageDirectory . "\", \"\", \"" . XOOPS_URL . "\")'");
190
		$imageTray->addElement($imageSelect, false);
191
		$imageTray->addElement(new \XoopsFormLabel('', "<br><img src='" . XOOPS_URL . "/" . $imageDirectory . "/" . $tfUplimage . "' id='imglabel_tf_uplimage' alt='' style='max-width:100px' />"));
192
		// Form Image tfUplimage: Upload new image
193
		if ($permissionUpload) {
194
			$maxsize = $helper->getConfig('maxsize_image');
195
			$imageTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE3_FORM_UPLOAD_NEW, 'tf_uplimage', $maxsize ));
196
			$imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' '  . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB));
197
			$imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_IMG_WIDTH, $helper->getConfig('maxwidth_image') . ' px'));
198
			$imageTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_IMG_HEIGHT, $helper->getConfig('maxheight_image') . ' px'));
199
		} else {
200
			$imageTray->addElement(new \XoopsFormHidden( 'tf_uplimage', $tfUplimage ));
201
		}
202
		$form->addElement($imageTray, );
203
		// Form File Upload tfUplfile
204
		$tfUplfile = $this->isNew() ? '' : $this->getVar('tf_uplfile');
205
		if ($permissionUpload) {
206
			$fileUploadTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_UPLFILE, '<br>' );
207
			$fileDirectory = '/uploads/mymodule3/files/testfields';
208
			if (!$this->isNew()) {
209
				$fileUploadTray->addElement(new \XoopsFormLabel(sprintf(_AM_MYMODULE3_TESTFIELD_UPLFILE_UPLOADS, ".{$fileDirectory}/"), $tfUplfile));
0 ignored issues
show
Bug introduced by
It seems like $tfUplfile can also be of type array and array; however, parameter $value of XoopsFormLabel::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

209
				$fileUploadTray->addElement(new \XoopsFormLabel(sprintf(_AM_MYMODULE3_TESTFIELD_UPLFILE_UPLOADS, ".{$fileDirectory}/"), /** @scrutinizer ignore-type */ $tfUplfile));
Loading history...
210
			}
211
			$maxsize = $helper->getConfig('maxsize_file');
212
			$fileUploadTray->addElement(new \XoopsFormFile( '', 'tf_uplfile', $maxsize ));
213
			$fileUploadTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' '  . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB));
214
			$form->addElement($fileUploadTray, );
215
		} else {
216
			$form->addElement(new \XoopsFormHidden( 'tf_uplfile', $tfUplfile ));
0 ignored issues
show
Bug introduced by
It seems like $tfUplfile can also be of type array and array; however, parameter $value of XoopsFormHidden::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

216
			$form->addElement(new \XoopsFormHidden( 'tf_uplfile', /** @scrutinizer ignore-type */ $tfUplfile ));
Loading history...
217
		}
218
		// Form Text Date Select tfTextdateselect
219
		$tfTextdateselect = $this->isNew() ? 0 : $this->getVar('tf_textdateselect');
220
		$form->addElement(new \XoopsFormTextDateSelect( _AM_MYMODULE3_TESTFIELD_TEXTDATESELECT, 'tf_textdateselect', '', $tfTextdateselect ));
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type integer expected by parameter $size of XoopsFormTextDateSelect::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

220
		$form->addElement(new \XoopsFormTextDateSelect( _AM_MYMODULE3_TESTFIELD_TEXTDATESELECT, 'tf_textdateselect', /** @scrutinizer ignore-type */ '', $tfTextdateselect ));
Loading history...
221
		// Form File tfSelectfile
222
		// Form File tfSelectfile: Select Uploaded File 
223
		$getTfSelectfile = $this->getVar('tf_selectfile');
224
		$tfSelectfile = $getTfSelectfile ? $getTfSelectfile : 'blank.gif';
225
		$fileDirectory = '/uploads/mymodule3/files/testfields';
226
		$fileTray = new \XoopsFormElementTray(_AM_MYMODULE3_TESTFIELD_SELECTFILE, '<br>' );
227
		$fileSelect = new \XoopsFormSelect( sprintf(_AM_MYMODULE3_TESTFIELD_SELECTFILE_UPLOADS, ".{$fileDirectory}/"), 'tf_selectfile', $tfSelectfile, 5);
228
		$fileArray = \XoopsLists::getImgListAsArray( XOOPS_ROOT_PATH . $fileDirectory );
229
		foreach($fileArray as $file1) {
230
			$fileSelect->addOption("{$file1}", $file1);
231
		}
232
		$fileTray->addElement($fileSelect, false);
233
		// Form File tfSelectfile: Upload new file
234
		if ($permissionUpload) {
235
			$maxsize = $helper->getConfig('maxsize_file');
236
			$fileTray->addElement(new \XoopsFormFile( '<br>' . _AM_MYMODULE3_FORM_UPLOAD_NEW, 'tf_selectfile', $maxsize ));
237
			$fileTray->addElement(new \XoopsFormLabel(_AM_MYMODULE3_FORM_UPLOAD_SIZE, ($maxsize / 1048576) . ' '  . _AM_MYMODULE3_FORM_UPLOAD_SIZE_MB));
238
		} else {
239
			$fileTray->addElement(new \XoopsFormHidden( 'tf_selectfile', $tfSelectfile ));
240
		}
241
		$form->addElement($fileTray, );
242
		// Form Text Enter Password tfPassword
243
		$form->addElement(new \XoopsFormPassword( _AM_MYMODULE3_TESTFIELD_PASSWORD, 'tf_password', 10, 32 ));
244
		// Form Select Country tfCountry_list
245
		$tfCountry_listSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_COUNTRY_LIST, 'tf_country_list', $this->getVar('tf_country_list'));
246
		$tfCountry_listSelect->addOption('', _NONE);
247
		$countryArray = \XoopsLists::getCountryList();
248
		$tfCountry_listSelect->addOptionArray($countryArray);
249
		$form->addElement($tfCountry_listSelect);
250
		// Form Select Lang tfLanguage
251
		$tfLanguageSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_LANGUAGE, 'tf_language', $this->getVar('tf_language'));
252
		$tfLanguageSelect->addOption('', _NONE);
253
		$langArray = \XoopsLists::getLangList();
254
		$tfLanguageSelect->addOptionArray($langArray);
255
		$form->addElement($tfLanguageSelect);
256
		// Form Radio tfRadio
257
		$tfRadio = $this->isNew() ? 0 : $this->getVar('tf_radio');
258
		$tfRadioSelect = new \XoopsFormRadio( _AM_MYMODULE3_TESTFIELD_RADIO, 'tf_radio', $tfRadio);
0 ignored issues
show
Bug introduced by
It seems like $tfRadio can also be of type array and array; however, parameter $value of XoopsFormRadio::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

258
		$tfRadioSelect = new \XoopsFormRadio( _AM_MYMODULE3_TESTFIELD_RADIO, 'tf_radio', /** @scrutinizer ignore-type */ $tfRadio);
Loading history...
259
		$tfRadioSelect->addOption('0', _NONE);
260
		$tfRadioSelect->addOption('1', _AM_MYMODULE3_LIST_1);
261
		$tfRadioSelect->addOption('2', _AM_MYMODULE3_LIST_2);
262
		$tfRadioSelect->addOption('3', _AM_MYMODULE3_LIST_3);
263
		$form->addElement($tfRadioSelect);
264
		// Form Select Status tfStatus
265
		$tfStatusSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_STATUS, 'tf_status', $this->getVar('tf_status'));
266
		$tfStatusSelect->addOption(Constants::STATUS_NONE, _AM_MYMODULE3_STATUS_NONE);
267
		$tfStatusSelect->addOption(Constants::STATUS_OFFLINE, _AM_MYMODULE3_STATUS_OFFLINE);
268
		$tfStatusSelect->addOption(Constants::STATUS_SUBMITTED, _AM_MYMODULE3_STATUS_SUBMITTED);
269
		$tfStatusSelect->addOption(Constants::STATUS_APPROVED, _AM_MYMODULE3_STATUS_APPROVED);
270
		$form->addElement($tfStatusSelect, true);
271
		// Form Text Date Select tfDatetime
272
		$tfDatetime = $this->isNew() ? 0 : $this->getVar('tf_datetime');
273
		$form->addElement(new \XoopsFormDateTime( _AM_MYMODULE3_TESTFIELD_DATETIME, 'tf_datetime', '', $tfDatetime ));
0 ignored issues
show
Bug introduced by
'' of type string is incompatible with the type integer expected by parameter $size of XoopsFormDateTime::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

273
		$form->addElement(new \XoopsFormDateTime( _AM_MYMODULE3_TESTFIELD_DATETIME, 'tf_datetime', /** @scrutinizer ignore-type */ '', $tfDatetime ));
Loading history...
274
		// Testfields handler
275
		$testfieldsHandler = $helper->getHandler('testfields');
0 ignored issues
show
Unused Code introduced by
The assignment to $testfieldsHandler is dead and can be removed.
Loading history...
276
		// Form Select tfCombobox
277
		$tfComboboxSelect = new \XoopsFormSelect( _AM_MYMODULE3_TESTFIELD_COMBOBOX, 'tf_combobox', $this->getVar('tf_combobox'), 5);
278
		$tfComboboxSelect->addOption('0', _NONE);
279
		$tfComboboxSelect->addOption('1', _AM_MYMODULE3_LIST_1);
280
		$tfComboboxSelect->addOption('2', _AM_MYMODULE3_LIST_2);
281
		$tfComboboxSelect->addOption('3', _AM_MYMODULE3_LIST_3);
282
		$form->addElement($tfComboboxSelect);
283
		// Permissions
284
		$memberHandler = xoops_getHandler('member');
285
		$groupList = $memberHandler->getGroupList();
0 ignored issues
show
Bug introduced by
The method getGroupList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

285
		/** @scrutinizer ignore-call */ 
286
  $groupList = $memberHandler->getGroupList();
Loading history...
286
		$grouppermHandler = xoops_getHandler('groupperm');
287
		$fullList[] = array_keys($groupList);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$fullList was never initialized. Although not strictly required by PHP, it is generally a good practice to add $fullList = array(); before regardless.
Loading history...
288
		if (!$this->isNew()) {
289
			$groupsIdsApprove = $grouppermHandler->getGroupIds('mymodule3_approve_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid'));
0 ignored issues
show
Bug introduced by
The method getGroupIds() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsGroupPermHandler or XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

289
			/** @scrutinizer ignore-call */ 
290
   $groupsIdsApprove = $grouppermHandler->getGroupIds('mymodule3_approve_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid'));
Loading history...
290
			$groupsIdsApprove[] = array_values($groupsIdsApprove);
291
			$groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_APPROVE, 'groups_approve_testfields[]', $groupsIdsApprove);
292
			$groupsIdsSubmit = $grouppermHandler->getGroupIds('mymodule3_submit_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid'));
293
			$groupsIdsSubmit[] = array_values($groupsIdsSubmit);
294
			$groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_SUBMIT, 'groups_submit_testfields[]', $groupsIdsSubmit);
295
			$groupsIdsView = $grouppermHandler->getGroupIds('mymodule3_view_testfields', $this->getVar('tf_id'), $GLOBALS['xoopsModule']->getVar('mid'));
296
			$groupsIdsView[] = array_values($groupsIdsView);
297
			$groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_VIEW, 'groups_view_testfields[]', $groupsIdsView);
298
		} else {
299
			$groupsCanApproveCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_APPROVE, 'groups_approve_testfields[]', $fullList);
300
			$groupsCanSubmitCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_SUBMIT, 'groups_submit_testfields[]', $fullList);
301
			$groupsCanViewCheckbox = new \XoopsFormCheckBox( _AM_MYMODULE3_PERMISSIONS_VIEW, 'groups_view_testfields[]', $fullList);
302
		}
303
		// To Approve
304
		$groupsCanApproveCheckbox->addOptionArray($groupList);
305
		$form->addElement($groupsCanApproveCheckbox);
306
		// To Submit
307
		$groupsCanSubmitCheckbox->addOptionArray($groupList);
308
		$form->addElement($groupsCanSubmitCheckbox);
309
		// To View
310
		$groupsCanViewCheckbox->addOptionArray($groupList);
311
		$form->addElement($groupsCanViewCheckbox);
312
		// To Save
313
		$form->addElement(new \XoopsFormHidden('op', 'save'));
314
		$form->addElement(new \XoopsFormButtonTray('', _SUBMIT, 'submit', '', false));
315
		return $form;
316
	}
317
318
	/**
319
	 * Get Values
320
	 * @param null $keys 
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $keys is correct as it would always require null to be passed?
Loading history...
321
	 * @param null $format 
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $format is correct as it would always require null to be passed?
Loading history...
322
	 * @param null$maxDepth 
323
	 * @return array
324
	 */
325
	public function getValuesTestfields($keys = null, $format = null, $maxDepth = null)
326
	{
327
		$helper = \XoopsModules\Mymodule3\Helper::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $helper is dead and can be removed.
Loading history...
328
		$ret = $this->getValues($keys, $format, $maxDepth);
329
		$ret['id'] = $this->getVar('tf_id');
330
		$ret['text'] = $this->getVar('tf_text');
331
		$ret['textarea'] = strip_tags($this->getVar('tf_textarea'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('tf_textarea') can also be of type array and array; however, parameter $str of strip_tags() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

331
		$ret['textarea'] = strip_tags(/** @scrutinizer ignore-type */ $this->getVar('tf_textarea'));
Loading history...
332
		$ret['dhtml'] = strip_tags($this->getVar('tf_dhtml'));
333
		$ret['checkbox'] = $this->getVar('tf_checkbox');
334
		$ret['yesno'] = (int)$this->getVar('tf_yesno') > 0 ? _YES : _NO;
335
		$ret['selectbox'] = $this->getVar('tf_selectbox');
336
		$ret['user'] = \XoopsUser::getUnameFromId($this->getVar('tf_user'));
337
		$ret['color'] = $this->getVar('tf_color');
338
		$ret['imagelist'] = $this->getVar('tf_imagelist');
339
		$ret['urlfile'] = $this->getVar('tf_urlfile');
340
		$ret['uplimage'] = $this->getVar('tf_uplimage');
341
		$ret['uplfile'] = $this->getVar('tf_uplfile');
342
		$ret['textdateselect'] = formatTimeStamp($this->getVar('tf_textdateselect'), 's');
343
		$ret['selectfile'] = $this->getVar('tf_selectfile');
344
		$ret['password'] = $this->getVar('tf_password');
345
		$ret['country_list'] = $this->getVar('tf_country_list');
346
		$ret['language'] = $this->getVar('tf_language');
347
		$ret['radio'] = $this->getVar('tf_radio');
348
		$ret['status'] = $this->getVar('tf_status');
349
		$ret['datetime'] = formatTimeStamp($this->getVar('tf_datetime'), 'm');
350
		$ret['combobox'] = $this->getVar('tf_combobox');
351
		return $ret;
352
	}
353
354
	/**
355
	 * Returns an array representation of the object
356
	 *
357
	 * @return array
358
	 */
359
	public function toArrayTestfields()
360
	{
361
		$ret = [];
362
		$vars = $this->getVars();
363
		foreach(array_keys($vars) as $var) {
364
			$ret[$var] = $this->getVar('"{$var}"');
365
		}
366
		return $ret;
367
	}
368
}
369