Location::getForm()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 60
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 44
dl 0
loc 60
rs 9.216
c 0
b 0
f 0
cc 4
nc 8
nop 1

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
namespace XoopsModules\Extcal;
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
 * @copyright    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @package      extcal
19
 * @since
20
 * @author       XOOPS Development Team,
21
 */
22
23
//Kraven 30
24
25
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
26
27
//class Event extends \XoopsObject
28
//class extcal_location extends \XoopsObject
29
30
/**
31
 * Class Location.
32
 */
33
class Location extends \XoopsObject
34
{
35
    public function __construct()
36
    {
37
        //Toutes les attributs de la table
38
        $this->initVar('id', \XOBJ_DTYPE_INT, null, false, 5);
39
        $this->initVar('nom', \XOBJ_DTYPE_TXTBOX, null, false);
40
        $this->initVar('description', \XOBJ_DTYPE_TXTAREA, '', false);
41
        $this->initVar('logo', \XOBJ_DTYPE_TXTBOX, null, false);
42
        $this->initVar('categorie', \XOBJ_DTYPE_TXTBOX, null, false);
43
        $this->initVar('adresse', \XOBJ_DTYPE_TXTBOX, null, false);
44
        $this->initVar('adresse2', \XOBJ_DTYPE_TXTBOX, null, false);
45
        $this->initVar('cp', \XOBJ_DTYPE_TXTBOX, null, false);
46
        $this->initVar('ville', \XOBJ_DTYPE_TXTBOX, null, false);
47
        $this->initVar('tel_fixe', \XOBJ_DTYPE_TXTBOX, null, false);
48
        $this->initVar('tel_portable', \XOBJ_DTYPE_TXTBOX, null, false);
49
        $this->initVar('mail', \XOBJ_DTYPE_TXTBOX, null, false);
50
        $this->initVar('site', \XOBJ_DTYPE_TXTBOX, null, false);
51
        $this->initVar('horaires', \XOBJ_DTYPE_TXTAREA, '', false);
52
        $this->initVar('divers', \XOBJ_DTYPE_TXTBOX, null, false);
53
        $this->initVar('tarifs', \XOBJ_DTYPE_TXTAREA, '', false);
54
        $this->initVar('map', \XOBJ_DTYPE_URL, false);
55
    }
56
57
    /**
58
     * @param bool $action
59
     *
60
     * @return \XoopsThemeForm
61
     */
62
    public function getForm($action = false)
63
    {
64
        global $xoopsDB;
65
66
        if (false === $action) {
67
            $action = $_SERVER['REQUEST_URI'];
68
        }
69
70
        $title = $this->isNew() ? \sprintf(\_MD_EXTCAL_LOCATION_ADD) : \sprintf(\_MD_EXTCAL_LOCATION_EDIT);
71
72
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
73
74
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
75
        $form->setExtra('enctype="multipart/form-data"');
76
77
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_NOM, 'nom', 50, 255, $this->getVar('nom')), true);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('nom') 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

77
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_NOM, 'nom', 50, 255, /** @scrutinizer ignore-type */ $this->getVar('nom')), true);
Loading history...
78
        $form->addElement(new \XoopsFormDhtmlTextArea(\_MD_EXTCAL_LOCATION_DESCRIPTION, 'description', $this->getVar('description'), 10), false);
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('description') can also be of type array and array; however, parameter $value of XoopsFormDhtmlTextArea::__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

78
        $form->addElement(new \XoopsFormDhtmlTextArea(\_MD_EXTCAL_LOCATION_DESCRIPTION, 'description', /** @scrutinizer ignore-type */ $this->getVar('description'), 10), false);
Loading history...
79
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_CATEGORIE, 'categorie', 40, 255, $this->getVar('categorie')), false);
80
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_ADRESSE, 'adresse', 50, 255, $this->getVar('adresse')), false);
81
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_ADRESSE2, 'adresse2', 50, 255, $this->getVar('adresse2')), false);
82
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_CP, 'cp', 10, 10, $this->getVar('cp')), false);
83
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_VILLE, 'ville', 20, 255, $this->getVar('ville')), false);
84
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_TEL_FIXE, 'tel_fixe', 20, 20, $this->getVar('tel_fixe')), false);
85
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_TEL_PORTABLE, 'tel_portable', 20, 20, $this->getVar('tel_portable')), false);
86
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_MAIL, 'mail', 50, 255, $this->getVar('mail')), false);
87
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_SITE, 'site', 50, 255, $this->getVar('site')), false);
88
        $form->addElement(new \XoopsFormTextArea(\_MD_EXTCAL_LOCATION_HORAIRES, 'horaires', $this->getVar('horaires'), 3, 40));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('horaires') 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

88
        $form->addElement(new \XoopsFormTextArea(\_MD_EXTCAL_LOCATION_HORAIRES, 'horaires', /** @scrutinizer ignore-type */ $this->getVar('horaires'), 3, 40));
Loading history...
89
        $form->addElement(new \XoopsFormTextArea(\_MD_EXTCAL_LOCATION_DIVERS, 'divers', $this->getVar('divers'), 5, 40));
90
        //$form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_LOCATION_TARIFS, 'tarifs', $this->getVar("tarifs"), 5, 40));
91
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_TARIFS . ' ( ' . \_MD_EXTCAL_DEVISE2 . ' )', 'tarifs', 20, 20, $this->getVar('tarifs')), false);
92
93
        //$form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_LOCATION_MAP, 'map', $this->getVar("map"), 5, 40));
94
        $form->addElement(new \XoopsFormText(\_MD_EXTCAL_LOCATION_MAP, 'map', 150, 255, $this->getVar('map')), false);
95
96
        //Logo
97
        $file_tray = new \XoopsFormElementTray(\sprintf(\_MD_EXTCAL_FORM_IMG, 2), '');
98
        if ('' != $this->getVar('logo')) {
99
            $file_tray->addElement(new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/location/' . $this->getVar('logo') . "' name='image' id='image' alt=''><br><br>"));
100
            $check_del_img = new \XoopsFormCheckBox('', 'delimg');
101
            $check_del_img->addOption(1, \_MD_EXTCAL_DEL_IMG);
102
            $file_tray->addElement($check_del_img);
103
            $file_img = new \XoopsFormFile(\_MD_EXTCAL_IMG, 'attachedimage', 3145728);
104
            unset($check_del_img);
105
        } else {
106
            $file_img = new \XoopsFormFile('', 'attachedimage', 3145728);
107
        }
108
        $file_img->setExtra("size ='40'");
109
        $file_tray->addElement($file_img);
110
        $msg        = \sprintf(\_MD_EXTCAL_IMG_CONFIG, (int)(3145728 / 1000), 500);
111
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
112
        $file_tray->addElement($file_label);
113
        $form->addElement($file_tray);
114
        $form->addElement(new \XoopsFormHidden('file', $this->getVar('logo')));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('logo') 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

114
        $form->addElement(new \XoopsFormHidden('file', /** @scrutinizer ignore-type */ $this->getVar('logo')));
Loading history...
115
        unset($file_img, $file_tray);
116
117
        $form->addElement(new \XoopsFormHidden('op', 'save_location'));
118
        $form->addElement(new \XoopsFormButton('', 'submit', \_SUBMIT, 'submit'));
119
        $form->display();
120
121
        return $form;
122
    }
123
}
124