form_room::createButtons()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 33

Duplication

Lines 33
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 0
dl 33
loc 33
rs 9.392
c 0
b 0
f 0
1
<?php
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
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;
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);
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();';
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);
84
        //$this->addElement( new XoopsFormText('加价', 'room_add_money', 11, 11, $this->Obj->room_add_money()), false);
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);
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