Completed
Push — master ( 658b35...b781ca )
by Richard
28s queued 23s
created

FileForm   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 40
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 60 2
1
<?php
2
3
namespace XoopsModules\Publisher\Form;
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
 *  Publisher form class
17
 *
18
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
19
 * @license         GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
20
 * @package         Publisher
21
 * @since           1.0
22
 * @author          trabis <[email protected]>
23
 * @version         $Id$
24
 */
25
use Xoops;
26
use Xoops\Form\Button;
27
use Xoops\Form\ElementTray;
28
use Xoops\Form\File;
29
use Xoops\Form\Hidden;
30
use Xoops\Form\RadioYesNo;
31
use Xoops\Form\Text;
32
use Xoops\Form\TextArea;
33
use Xoops\Form\ThemeForm;
34
use XoopsModules\Publisher;
35
use XoopsModules\Publisher\Helper;
36
37
require_once \dirname(\dirname(__DIR__)) . '/include/common.php';
38
39
/**
40
 * Class FileForm
41
 * @package XoopsModules\Publisher\Form
42
 */
43
class FileForm extends ThemeForm
44
{
45
    public function __construct(Publisher\File $obj)
46
    {
47
        $xoops = Xoops::getInstance();
48
        $helper = Helper::getInstance();
49
        $helper->loadLanguage('main');
50
51
        parent::__construct(_AM_PUBLISHER_UPLOAD_FILE, 'form', $xoops->getEnv('PHP_SELF'));
52
        $this->setExtra('enctype="multipart/form-data"');
53
54
        // NAME
55
        $name_text = new Text(_CO_PUBLISHER_FILENAME, 'name', 50, 255, $obj->getVar('name'));
0 ignored issues
show
Bug introduced by
It seems like $obj->getVar('name') can also be of type string[]; however, parameter $value of Xoops\Form\Text::__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

55
        $name_text = new Text(_CO_PUBLISHER_FILENAME, 'name', 50, 255, /** @scrutinizer ignore-type */ $obj->getVar('name'));
Loading history...
56
        $name_text->setDescription(_CO_PUBLISHER_FILE_NAME_DSC);
57
        $this->addElement($name_text, true);
58
59
        // DESCRIPTION
60
        $description_text = new TextArea(_CO_PUBLISHER_FILE_DESCRIPTION, 'description', $obj->getVar('description'));
0 ignored issues
show
Bug introduced by
It seems like $obj->getVar('description') can also be of type string[]; however, parameter $value of Xoops\Form\TextArea::__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

60
        $description_text = new TextArea(_CO_PUBLISHER_FILE_DESCRIPTION, 'description', /** @scrutinizer ignore-type */ $obj->getVar('description'));
Loading history...
61
        $description_text->setDescription(_CO_PUBLISHER_FILE_DESCRIPTION_DSC);
62
        $this->addElement($description_text);
63
64
        // FILE TO UPLOAD
65
        $file_box = new File(_CO_PUBLISHER_FILE_TO_UPLOAD, 'item_upload_file');
66
        $file_box->set('size', 50);
67
        $this->addElement($file_box);
68
69
        $status_select = new RadioYesNo(_CO_PUBLISHER_FILE_STATUS, 'file_status', _PUBLISHER_STATUS_FILE_ACTIVE);
70
        $status_select->setDescription(_CO_PUBLISHER_FILE_STATUS_DSC);
71
        $this->addElement($status_select);
72
73
        // fileid
74
        $this->addElement(new Hidden('fileid', $obj->getVar('fileid')));
0 ignored issues
show
Bug introduced by
It seems like $obj->getVar('fileid') can also be of type string[]; however, parameter $value of Xoops\Form\Hidden::__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

74
        $this->addElement(new Hidden('fileid', /** @scrutinizer ignore-type */ $obj->getVar('fileid')));
Loading history...
75
76
        // itemid
77
        $this->addElement(new Hidden('itemid', $obj->getVar('itemid')));
78
79
        $files_button_tray = new ElementTray('', '');
80
        $files_hidden = new Hidden('op', 'uploadfile');
81
        $files_button_tray->addElement($files_hidden);
82
83
        if (!$obj->getVar('fileid')) {
84
            $files_butt_create = new Button('', '', _MD_PUBLISHER_UPLOAD, 'submit');
85
            $files_butt_create->setExtra('onclick="this.form.elements.op.value=\'uploadfile\'"');
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

85
            /** @scrutinizer ignore-deprecated */ $files_butt_create->setExtra('onclick="this.form.elements.op.value=\'uploadfile\'"');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
86
            $files_button_tray->addElement($files_butt_create);
87
88
            $files_butt_another = new Button('', '', _CO_PUBLISHER_FILE_UPLOAD_ANOTHER, 'submit');
89
            $files_butt_another->setExtra('onclick="this.form.elements.op.value=\'uploadanother\'"');
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

89
            /** @scrutinizer ignore-deprecated */ $files_butt_another->setExtra('onclick="this.form.elements.op.value=\'uploadanother\'"');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
90
            $files_button_tray->addElement($files_butt_another);
91
        } else {
92
            $files_butt_create = new Button('', '', _MD_PUBLISHER_MODIFY, 'submit');
93
            $files_butt_create->setExtra('onclick="this.form.elements.op.value=\'modify\'"');
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

93
            /** @scrutinizer ignore-deprecated */ $files_butt_create->setExtra('onclick="this.form.elements.op.value=\'modify\'"');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
94
            $files_button_tray->addElement($files_butt_create);
95
        }
96
97
        $files_butt_clear = new Button('', '', _MD_PUBLISHER_CLEAR, 'reset');
98
        $files_button_tray->addElement($files_butt_clear);
99
100
        $buttonCancel = new Button('', '', _MD_PUBLISHER_CANCEL, 'button');
101
        $buttonCancel->setExtra('onclick="history.go(-1)"');
0 ignored issues
show
Deprecated Code introduced by
The function Xoops\Form\Element::setExtra() has been deprecated: please use attributes for event scripting ( Ignorable by Annotation )

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

101
        /** @scrutinizer ignore-deprecated */ $buttonCancel->setExtra('onclick="history.go(-1)"');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
102
        $files_button_tray->addElement($buttonCancel);
103
104
        $this->addElement($files_button_tray);
105
    }
106
}
107