Completed
Push — master ( 5be1c3...395766 )
by Michael
26:05
created

form_hotel_service::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 10
Ratio 100 %
Metric Value
dl 10
loc 10
rs 9.4286
cc 1
eloc 7
nc 1
nop 2
1
<?php
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 18 and the first side effect is on line 10.

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
 * @城市表单
4
 * @license   http://www.blags.org/
5
 * @created   :2010年05月20日 23时52分
6
 * @copyright 1997-2010 The Martin Group
7
 * @author    Martin <[email protected]>
8
 * */
9
if (!defined('XOOPS_ROOT_PATH')) {
10
    return;
11
}
12
13
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
14
15
/**
16
 * Class form_hotel_service
17
 */
18
class form_hotel_service extends XoopsThemeForm
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
19
{
20
    /**
21
     * form_hotel_service constructor.
22
     * @param $HotelServiceObj
23
     * @param $TypeList
24
     */
25 View Code Duplication
    public function __construct(&$HotelServiceObj, &$TypeList)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
    {
27
        $this->Obj      = &$HotelServiceObj;
28
        $this->TypeList = &$TypeList;
29
        parent::__construct(_AM_MARTIN_HOTEL_SERVICE, "op", xoops_getenv('PHP_SELF') . "?action=save");
30
        $this->setExtra('enctype="multipart/form-data"');
31
32
        $this->createElements();
33
        $this->createButtons();
34
    }
35
36
    /**
37
     * created elements
38
     * @license   http://www.blags.org/
39
     * @created   :2010年05月21日 20时40分
40
     * @copyright 1997-2010 The Martin Group
41
     * @author    Martin <[email protected]>
42
     * */
43
    public function createElements()
44
    {
45
        global $xoopsDB;
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...
46
        $TypeElement = new XoopsFormSelect(_AM_MARTIN_SERVICE_TYPE, 'service_type_id', $this->Obj->service_type_id(), 1);
47
        $TypeElement->addOptionArray($this->TypeList);
48
        $this->addElement($TypeElement, true);
49
        $this->addElement(new XoopsFormText(_AM_MARTIN_SERVICE_UNITS . '<br>' . _AM_MARTIN_SERVICE_UNITS_DESC, 'service_unit', 45, 45, $this->Obj->service_unit()), true);
50
        $this->addElement(new XoopsFormText(_AM_MARTIN_SERVICE_NAME, 'service_name', 50, 255, $this->Obj->service_name()), true);
51
        $this->addElement(new XoopsFormTextArea(_AM_MARTIN_SERVICE_DESCRIPTION, 'service_instruction', $this->Obj->service_instruction()), true);
52
        $this->addElement(new XoopsFormHidden('id', $this->Obj->service_id()));
53
    }
54
55
    /**
56
     * @创建按钮
57
     * @license   http://www.blags.org/
58
     * @created   :2010年05月20日 23时52分
59
     * @copyright 1997-2010 The Martin Group
60
     * @author    Martin <[email protected]>
61
     * */
62 View Code Duplication
    public function createButtons()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
63
    {
64
        $button_tray = new XoopsFormElementTray('', '');
65
        // No ID for category -- then it's new category, button says 'Create'
66
        if (!$this->Obj->service_id()) {
67
            $butt_create = new XoopsFormButton('', '', _SUBMIT, 'submit');
68
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
69
            $button_tray->addElement($butt_create);
70
71
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
72
            $button_tray->addElement($butt_clear);
73
74
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
75
            $butt_cancel->setExtra('onclick="history.go(-1)"');
76
            $button_tray->addElement($butt_cancel);
77
78
            $this->addElement($button_tray);
79
        } else {
80
            // button says 'Update'
81
            $butt_create = new XoopsFormButton('', '', _EDIT, 'submit');
82
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
83
            $button_tray->addElement($butt_create);
84
85
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
86
            $button_tray->addElement($butt_clear);
87
88
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
89
            $butt_cancel->setExtra('onclick="history.go(-1)"');
90
            $button_tray->addElement($butt_cancel);
91
92
            $this->addElement($button_tray);
93
        }
94
    }
95
}
96