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

form_room::form_room()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 12
rs 9.4286
cc 1
eloc 9
nc 1
nop 3
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_room
17
 */
18
class form_room 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_room constructor.
22
     * @param $RoomObj
23
     * @param $hotelList
24
     * @param $TypeList
25
     */
26
    public function __construct(&$RoomObj, &$hotelList, &$TypeList)
27
    {
28
        $this->Obj             = &$RoomObj;
29
        $this->hotelList       = &$hotelList;
30
        $this->TypeList        = &$TypeList;
31
        $this->RoomBedTypeList = getModuleArray('room_bed_type', 'order_type', true);;
32
        parent::__construct(_AM_MARTIN_HOTEL_ROOMS, "op", xoops_getenv('PHP_SELF') . "?action=save");
33
        $this->setExtra('enctype="multipart/form-data"');
34
35
        $this->createElements();
36
        $this->createButtons();
37
    }
38
39
    /**
40
     * created elements
41
     * @license   http://www.blags.org/
42
     * @created   :2010年05月21日 20时40分
43
     * @copyright 1997-2010 The Martin Group
44
     * @author    Martin <[email protected]>
45
     * */
46
    public function createElements()
47
    {
48
        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...
49
        $TypeElement = new XoopsFormSelect(_AM_MARTIN_ROOM_CATEGORY, 'room_type_id', $this->Obj->room_type_id(), 1);
50
        $TypeElement->addOptionArray($this->TypeList);
51
        $this->addElement($TypeElement, true);
52
        $HotelElement = new XoopsFormSelect(_AM_MARTIN_HOTEL_NAME, 'hotel_id', $this->Obj->hotel_id(), 1);
53
        $HotelElement->addOptionArray($this->hotelList);
54
        $this->addElement($HotelElement, true);
55
56
        $BedTypeElement = new XoopsFormSelect(_AM_MARTIN_ROOM_BED_TYPE, 'room_bed_type', $this->Obj->room_bed_type(), 1);
57
        $BedTypeElement->addOptionArray($this->RoomBedTypeList);
58
        $this->addElement($BedTypeElement, true);
59
60
        //$this->addElement( new XoopsFormText('客房初始价格', 'room_initial_price', 11, 11, $this->Obj->room_initial_price()), true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% 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...
61
        $this->addElement(new XoopsFormText(_AM_MARTIN_ROOM_COUNT, 'room_count', 11, 11, $this->Obj->room_count()), true);
62
        $this->addElement(new XoopsFormText(_AM_MARTIN_ROOMS_AREA, 'room_area', 11, 11, $this->Obj->room_area()), true);
63
        $this->addElement(new XoopsFormText(_AM_MARTIN_ROOM_NAME, 'room_name', 45, 45, $this->Obj->room_name()), true);
64
        $this->addElement(new XoopsFormText(_AM_MARTIN_ROOM_FLOOR, 'room_floor', 45, 45, $this->Obj->room_floor()), true);
65
66
        /*$isHidden = $this->Obj->room_is_add_bed() ? '' :'$("#room_add_money").parent("td").parent("tr").hide();$("#room_bed_info").parent("td").parent("tr").hide();';
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% 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...
67
        $js = '<script type=\'text/javascript\'>
68
        jQuery.noConflict(); 
69
        jQuery(document).ready(function($){
70
            '.$isHidden.'
71
            $("#room_add_money").parent("td").parent("tr").prev("tr").find("input[type=\"radio\"]").click(function(){
72
                if(Number($(this).val()) > 0)
73
                {
74
                    $("#room_add_money").parent("td").parent("tr").show();
75
                    $("#room_bed_info").parent("td").parent("tr").show();
76
                }else{
77
                    $("#room_add_money").parent("td").parent("tr").hide();
78
                    $("#room_bed_info").parent("td").parent("tr").hide();
79
                }
80
            });
81
        });
82
        </script>';*/
83
        //$this->addElement( new XoopsFormRadioYN("是否加床", "room_is_add_bed", $this->Obj->room_is_add_bed() , _YES, " " . _NO . $js ) , true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% 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...
84
        //$this->addElement( new XoopsFormText('加价', 'room_add_money', 11, 11, $this->Obj->room_add_money()), false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% 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...
85
        $this->addElement(new XoopsFormTextArea(_AM_MARTIN_ROOM_DESCRIPTION, 'room_bed_info', $this->Obj->room_bed_info()), false);
86
        $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_ROOM_STATUS, 'room_status', $this->Obj->room_status(), _AM_MARTIN_PUBLISHED, _AM_MARTIN_DRAFT), true);
87
        //$this->addElement( new XoopsFormText(_AM_MARTIN_GIFT_VOUCHER, 'room_sented_coupon', 11, 11, (int)($this->Obj->room_sented_coupon())), false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% 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...
88
89
        $this->addElement(new XoopsFormHidden('id', $this->Obj->room_id()));
90
    }
91
92
    /**
93
     * @创建按钮
94
     * @license   http://www.blags.org/
95
     * @created   :2010年05月20日 23时52分
96
     * @copyright 1997-2010 The Martin Group
97
     * @author    Martin <[email protected]>
98
     * */
99 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...
100
    {
101
        $button_tray = new XoopsFormElementTray('', '');
102
        // No ID for category -- then it's new category, button says 'Create'
103
        if (!$this->Obj->room_id()) {
104
            $butt_create = new XoopsFormButton('', '', _SUBMIT, 'submit');
105
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
106
            $button_tray->addElement($butt_create);
107
108
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
109
            $button_tray->addElement($butt_clear);
110
111
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
112
            $butt_cancel->setExtra('onclick="history.go(-1)"');
113
            $button_tray->addElement($butt_cancel);
114
115
            $this->addElement($button_tray);
116
        } else {
117
            // button says 'Update'
118
            $butt_create = new XoopsFormButton('', '', _EDIT, 'submit');
119
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
120
            $button_tray->addElement($butt_create);
121
122
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
123
            $button_tray->addElement($butt_clear);
124
125
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
126
            $butt_cancel->setExtra('onclick="history.go(-1)"');
127
            $button_tray->addElement($butt_cancel);
128
129
            $this->addElement($button_tray);
130
        }
131
    }
132
}
133