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

form_group::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 11
rs 9.4286
cc 1
eloc 8
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_group
17
 */
18
class form_group 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_group constructor.
22
     * @param $GroupObj
23
     * @param $RoomList
24
     * @param $HotelList
25
     */
26
    public function __construct(&$GroupObj, &$RoomList, &$HotelList)
27
    {
28
        $this->Obj       = &$GroupObj;
29
        $this->RoomList  = &$RoomList;
30
        $this->HotelList = &$HotelList;
31
        parent::__construct(_AM_MARTIN_HOTEL_GROUP_BUY, "op", xoops_getenv('PHP_SELF') . "?action=save");
32
        $this->setExtra('enctype="multipart/form-data"');
33
34
        $this->createElements();
35
        $this->createButtons();
36
    }
37
38
    /**
39
     * created elements
40
     * @license   http://www.blags.org/
41
     * @created   :2010年05月21日 20时40分
42
     * @copyright 1997-2010 The Martin Group
43
     * @author    Martin <[email protected]>
44
     * */
45
    public function createElements()
46
    {
47
        //include_once MARTIN_ROOT_PATH . '/include/formdatetime.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
48
        include_once XOOPS_ROOT_PATH . "/modules/martin/class/xoopsformloader.php";
49
        include_once MARTIN_ROOT_PATH . '/include/formdatetime.php';
50
51
        $RoomStr = '';
52 View Code Duplication
        foreach ($this->RoomList as $room) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
53
            $RoomStr .= "<br><input type=checkbox name=room_id[] value={$room['room_id']} id=room_{$room['room_id']} checked=\"checked\" click=\"RoomRemove(this)\">&nbsp;<label for=room_{$room['room_id']}>{$room['room_name']}</label>&nbsp;&nbsp;"._AM_MARTIN_NUMBER_OF_ROOMS.":<input type=text name=\"room_count_{$room['room_id']}\" value={$room['room_count']}>";
54
        }
55
        $js          = '<script type=\'text/javascript\'>
56
            jQuery.noConflict();
57
            jQuery(document).ready(function($){
58
                $("#hotel_id").click(function(){
59
                    var hotel_id =  Number($(this).val());
60
                    $.post("martin.ajax.php?action=getroomlist",{hotel_id:hotel_id},function(data){
61
                        $("#room").html(data);
62
                    });
63
                });
64
            });
65
            function roomSelect(event)
66
            {
67
                var room_id = Number(jQuery("#ajaxroom").val());
68
                var room_name = jQuery.trim(jQuery("#ajaxroom option:selected").text());
69
                var roomExist = document.getElementById("room_"+room_id);
70
                if(roomExist) return false;
71
                if(room_id > 0)
72
                {
73
                    var Str = "<br><input type=checkbox name=room_id[] value="+room_id+" id=room_"+room_id+" checked=\"checked\" click=\"RoomRemove(this)\">&nbsp;"+"<label for=room_"+room_id+">" + room_name + "</label>";
74
                    var inputStr = "&nbsp;&nbsp;"._AM_MARTIN_NUMBER_OF_ROOMS.":<input type=text name=\"room_count_"+room_id+"\" value=1>";
75
                    jQuery("#rooms").append(Str + inputStr);
76
                }
77
            }
78
            </script>';
79
        $Room        = new XoopsFormElementTray($js . _AM_MARTIN_SELECT_ROOMS . '<br>' . _AM_MARTIN_FILTER_BY_HOTEL);
80
        $RoomElement = new XoopsFormSelect('', 'hotel_id', $this->HotelList, 5, false);
81
        $RoomElement->addOptionArray($this->HotelList);
82
        //$RoomElement->addOption('class','hotel');
0 ignored issues
show
Unused Code Comprehensibility introduced by
89% 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...
83
        $Room->addElement($RoomElement, false);
84
        $Room->addElement(new XoopsFormElementTray('<br><br><div id="room"></div><div id="rooms">' . $RoomStr . '</div>'), false);
85
86
        $this->addElement($Room, false);
87
88
        $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_CHECK_IN, 'check_in_date', $size = 15, $this->Obj->check_in_date(), false), true);
89
90
        $this->addElement(new XoopsFormTextDateSelect(_AM_MARTIN_LAUNCH_TIME, 'check_out_date', $size = 15, $this->Obj->check_out_date(), false), true);
91
        //$this->addElement( new XoopsFormTextDateSelect(_AM_MARTIN_HOTEL_APPLY_START_TIME, 'apply_start_date', $size = 15, $this->Obj->apply_start_date(),false ) ,true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% 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
        $this->addElement(new MartinFormDateTime(_AM_MARTIN_HOTEL_APPLY_START_TIME, 'apply_start_date', $size = 15, $this->Obj->apply_start_date()), true);
93
        //$this->addElement( new XoopsFormTextDateSelect(_AM_MARTIN_END_BUY_TIME, 'apply_end_date', $size = 15, $this->Obj->apply_end_date() ) ,true);
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...
94
        $this->addElement(new MartinFormDateTime(_AM_MARTIN_END_BUY_TIME, 'apply_end_date', $size = 15, $this->Obj->apply_end_date()), true);
95
96
        $this->addElement(new XoopsFormText(_AM_MARTIN_PRICE, 'group_price', 11, 11, $this->Obj->group_price()), true);
97
        $this->addElement(new XoopsFormText(_AM_MARTIN_GIFT_VOUCHER . '?', 'group_sented_coupon', 11, 11, (int)($this->Obj->group_sented_coupon())), true);
98
        $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_CAN_YOU_USE_CASH_VOLUME, 'group_can_use_coupon', $this->Obj->group_can_use_coupon(), _YES, _NO), true);
99
        $this->addElement(new XoopsFormRadioYN(_AM_MARTIN_STATUS, 'group_status', $this->Obj->group_status(), _AM_MARTIN_PUBLISHED, _AM_MARTIN_DRAFT), true);
100
101
        $this->addElement(new XoopsFormText(_AM_MARTIN_TITLE, 'group_name', 50, 255, $this->Obj->group_name()), true);
102
        $editor     = 'tinymce';
103
        $group_info = $this->Obj->group_info();
104
        //var_dump($group_info);
105
        $editor_configs           = array();
106
        $editor_configs["name"]   = "group_info";
107
        $editor_configs["value"]  = $group_info;
108
        $editor_configs["rows"]   = empty($xoopsModuleConfig["editor_rows"]) ? 35 : $xoopsModuleConfig["editor_rows"];
0 ignored issues
show
Bug introduced by
The variable $xoopsModuleConfig seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
109
        $editor_configs["cols"]   = empty($xoopsModuleConfig["editor_cols"]) ? 60 : $xoopsModuleConfig["editor_cols"];
110
        $editor_configs["width"]  = empty($xoopsModuleConfig["editor_width"]) ? "100%" : $xoopsModuleConfig["editor_width"];
111
        $editor_configs["height"] = empty($xoopsModuleConfig["editor_height"]) ? "400px" : $xoopsModuleConfig["editor_height"];
112
113
        $this->addElement(new XoopsFormEditor(_AM_MARTIN_CUSTOMERS_DETAILS, $editor, $editor_configs, false, $onfailure = null), false);
114
        $this->addElement(new XoopsFormHidden('id', $this->Obj->group_id()));
115
    }
116
117
    /**
118
     * @创建按钮
119
     * @license   http://www.blags.org/
120
     * @created   :2010年05月20日 23时52分
121
     * @copyright 1997-2010 The Martin Group
122
     * @author    Martin <[email protected]>
123
     * */
124 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...
125
    {
126
        $button_tray = new XoopsFormElementTray('', '');
127
        // No ID for category -- then it's new category, button says 'Create'
128
        if (!$this->Obj->group_id()) {
129
            $butt_create = new XoopsFormButton('', '', _SUBMIT, 'submit');
130
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
131
            $button_tray->addElement($butt_create);
132
133
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
134
            $button_tray->addElement($butt_clear);
135
136
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
137
            $butt_cancel->setExtra('onclick="history.go(-1)"');
138
            $button_tray->addElement($butt_cancel);
139
140
            $this->addElement($button_tray);
141
        } else {
142
            // button says 'Update'
143
            $butt_create = new XoopsFormButton('', '', _EDIT, 'submit');
144
            $butt_create->setExtra('onclick="this.form.elements.op.value=\'addcategory\'"');
145
            $button_tray->addElement($butt_create);
146
147
            $butt_clear = new XoopsFormButton('', '', _RESET, 'reset');
148
            $button_tray->addElement($butt_clear);
149
150
            $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
151
            $butt_cancel->setExtra('onclick="history.go(-1)"');
152
            $button_tray->addElement($butt_cancel);
153
154
            $this->addElement($button_tray);
155
        }
156
    }
157
}
158