Completed
Push — master ( 31307f...55a138 )
by Michael
03:27
created

Etablissement   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 94
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
B getForm() 0 61 4
1
<?php namespace XoopsModules\Extcal;
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 23.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
//Kraven 30
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
21
// defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
22
23
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
24
25
//class Event extends \XoopsObject
26
//class extcal_etablissement extends \XoopsObject
27
28
/**
29
 * Class Etablissement.
30
 */
31
class Etablissement extends \XoopsObject
32
{
33
    /**
34
     *
35
     */
36
    public function __construct()
37
    {
38
        //Toutes les attributs de la table
39
        $this->initVar('id', XOBJ_DTYPE_INT, null, false, 5);
40
        $this->initVar('nom', XOBJ_DTYPE_TXTBOX, null, false);
41
        $this->initVar('description', XOBJ_DTYPE_TXTAREA, '', false);
42
        $this->initVar('logo', XOBJ_DTYPE_TXTBOX, null, false);
43
        $this->initVar('categorie', XOBJ_DTYPE_TXTBOX, null, false);
44
        $this->initVar('adresse', XOBJ_DTYPE_TXTBOX, null, false);
45
        $this->initVar('adresse2', XOBJ_DTYPE_TXTBOX, null, false);
46
        $this->initVar('cp', XOBJ_DTYPE_TXTBOX, null, false);
47
        $this->initVar('ville', XOBJ_DTYPE_TXTBOX, null, false);
48
        $this->initVar('tel_fixe', XOBJ_DTYPE_TXTBOX, null, false);
49
        $this->initVar('tel_portable', XOBJ_DTYPE_TXTBOX, null, false);
50
        $this->initVar('mail', XOBJ_DTYPE_TXTBOX, null, false);
51
        $this->initVar('site', XOBJ_DTYPE_TXTBOX, null, false);
52
        $this->initVar('horaires', XOBJ_DTYPE_TXTAREA, '', false);
53
        $this->initVar('divers', XOBJ_DTYPE_TXTBOX, null, false);
54
        $this->initVar('tarifs', XOBJ_DTYPE_TXTAREA, '', false);
55
        $this->initVar('map', XOBJ_DTYPE_URL, false);
56
    }
57
58
    /**
59
     * @param bool $action
60
     *
61
     * @return \XoopsThemeForm
62
     */
63
    public function getForm($action = false)
0 ignored issues
show
Coding Style introduced by
getForm uses the super-global variable $_SERVER which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
64
    {
65
        global $xoopsDB, $extcalConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
66
67
        if (false === $action) {
68
            $action = $_SERVER['REQUEST_URI'];
69
        }
70
71
        $title = $this->isNew() ? sprintf(_MD_EXTCAL_ETABLISSEMENT_ADD) : sprintf(_MD_EXTCAL_ETABLISSEMENT_EDIT);
72
73
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
74
75
        $form = new \XoopsThemeForm($title, 'form', $action, 'post', true);
76
        $form->setExtra('enctype="multipart/form-data"');
77
78
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_NOM, 'nom', 50, 255, $this->getVar('nom')), true);
79
        $form->addElement( new \XoopsFormDhtmlTextArea(_MD_EXTCAL_ETABLISSEMENT_DESCRIPTION, 'description', $this->getVar('description'), 10), false);
80
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_CATEGORIE, 'categorie', 40, 255, $this->getVar('categorie')), false);
81
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_ADRESSE, 'adresse', 50, 255, $this->getVar('adresse')), false);
82
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_ADRESSE2, 'adresse2', 50, 255, $this->getVar('adresse2')), false);
83
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_CP, 'cp', 10, 10, $this->getVar('cp')), false);
84
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_VILLE, 'ville', 20, 255, $this->getVar('ville')), false);
85
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_TEL_FIXE, 'tel_fixe', 20, 20, $this->getVar('tel_fixe')), false);
86
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_TEL_PORTABLE, 'tel_portable', 20, 20, $this->getVar('tel_portable')), false);
87
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_MAIL, 'mail', 50, 255, $this->getVar('mail')), false);
88
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_SITE, 'site', 50, 255, $this->getVar('site')), false);
89
        $form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_ETABLISSEMENT_HORAIRES, 'horaires', $this->getVar('horaires'), 3, 40));
90
        $form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_ETABLISSEMENT_DIVERS, 'divers', $this->getVar('divers'), 5, 40));
91
        //$form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_ETABLISSEMENT_TARIFS, 'tarifs', $this->getVar("tarifs"), 5, 40));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
92
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_TARIFS . ' ( ' . _MD_EXTCAL_DEVISE2 . ' )', 'tarifs', 20, 20, $this->getVar('tarifs')), false);
93
94
        //$form->addElement( new \XoopsFormTextArea(_MD_EXTCAL_ETABLISSEMENT_MAP, 'map', $this->getVar("map"), 5, 40));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
        $form->addElement( new \XoopsFormText(_MD_EXTCAL_ETABLISSEMENT_MAP, 'map', 150, 255, $this->getVar('map')), false);
96
97
        //Logo
98
        $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 2), '');
99
        if ('' != $this->getVar('logo')) {
100
            $file_tray->addElement( new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/etablissement/' . $this->getVar('logo') . "' name='image' id='image' alt=''><br><br>"));
101
            $check_del_img = new \XoopsFormCheckBox('', 'delimg');
102
            $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG);
103
            $file_tray->addElement($check_del_img);
104
            $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage', 3145728);
105
            unset($check_del_img);
106
        } else {
107
            $file_img = new \XoopsFormFile('', 'attachedimage', 3145728);
108
        }
109
        $file_img->setExtra("size ='40'");
110
        $file_tray->addElement($file_img);
111
        $msg        = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(3145728 / 1000), 500, 500);
112
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
113
        $file_tray->addElement($file_label);
114
        $form->addElement($file_tray);
115
        $form->addElement( new \XoopsFormHidden('file', $this->getVar('logo')));
116
        unset($file_img, $file_tray);
117
118
        $form->addElement( new \XoopsFormHidden('op', 'save_etablissement'));
119
        $form->addElement( new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
120
        $form->display();
121
122
        return $form;
123
    }
124
}
125
126