martin.hotel.php ➔ martin_hotel_search_show()   B
last analyzed

Complexity

Conditions 8
Paths 20

Size

Total Lines 49

Duplication

Lines 8
Ratio 16.33 %

Importance

Changes 0
Metric Value
cc 8
nc 20
nop 1
dl 8
loc 49
rs 7.8682
c 0
b 0
f 0
1
<?php
2
/**
3
 * @订房搜索
4
 * @license   http://www.blags.org/
5
 * @created   :2010年05月19日 22时38分
6
 * @copyright 1997-2010 The Martin Group
7
 * @author    Martin <[email protected]>
8
 * */
9
if (!defined('XOOPS_ROOT_PATH')) {
10
    exit();
11
}
12
13
/**
14
 * hoel search show function
15
 * @param $options
16
 * @return
17
 */
18
function martin_hotel_search_show($options)
19
{
20
    global $xoopsModuleConfig, $xoopsModule, $xoopsTpl;
21
    //新闻
22
    /*if($xoopsModule->dirname() != 'martin')
23
    {*/
24
    $module_handler    =& xoops_gethandler('module');
25
    $config_handler    =& xoops_gethandler('config');
26
    $xoopsModule       =& $module_handler->getByDirname('martin');
27
    $xoopsModuleConfig =& $config_handler->getConfigsByCat(0, $xoopsModule->getVar('mid'));
28
    /*}*/
29
    //var_dump($xoopsModuleConfig);
30
31
    include_once XOOPS_ROOT_PATH . '/modules/martin/include/functions.php';
32
    $hotel_handler   =& xoops_getmodulehandler("hotel", 'martin');
33
    $group_handler   =& xoops_getmodulehandler("group", 'martin');
34
    $auction_handler =& xoops_getmodulehandler("auction", 'martin');
35
    $news_handler    =& xoops_getmodulehandler("hotelnews", 'martin');
36
37
    $hotel_guide         = explode(",", $xoopsModuleConfig['hotel_guide']);
38
    $hotel_today_special = explode(",", $xoopsModuleConfig['hotel_today_special']);
39
    $hotel_news_ids      = (is_array($hotel_guide) && is_array($hotel_today_special)) ? array_merge($hotel_guide, $hotel_today_special) : null;
40
    $hotelnews           = $news_handler->GetHotelNews($hotel_news_ids);
41
42
    $hotel_guide_rows         = array();
43
    $hotel_today_special_rows = array();
44 View Code Duplication
    foreach ($hotelnews as $key => $row) {
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...
45
        if (in_array($key, $hotel_guide) && count($hotel_guide_rows) < 6) {
46
            $hotel_guide_rows[] = $row;
47
        }
48
        if (in_array($key, $hotel_today_special) && count($hotel_today_special_rows) < 6) {
49
            $hotel_today_special_rows[] = $row;
50
        }
51
    }
52
53
    $block['module_url']               = XOOPS_URL . '/modules/martin/';
0 ignored issues
show
Coding Style Comprehensibility introduced by
$block was never initialized. Although not strictly required by PHP, it is generally a good practice to add $block = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
54
    $block['hotelrank']                = getModuleArray('hotelrank', 'hotelrank', true, null, $xoopsModuleConfig);
55
    $block['groupList']                = $group_handler->GetGroupList();
56
    $block['auctionList']              = $auction_handler->GetAuctionList();
57
    $block['hotel_guide_rows']         = $hotel_guide_rows;
58
    $block['hotel_today_special_rows'] = $hotel_today_special_rows;
59
    $block['cityList']                 = $hotel_handler->GetCityList('WHERE city_parentid = 0');
60
    $block['hotel_static_prefix']      = $xoopsModuleConfig['hotel_static_prefix'];
61
62
    unset($hotel_handler, $group_handler, $auction_handler, $news_handler, $hotel_guide_rows, $hotel_today_special_rows);
63
64
    //var_dump($block);
65
    return $block;
66
}
67
68
/**
69
 * hoel search edit function
70
 * @param $options
71
 * @return string
72
 */
73
function martin_hotel_search_edit($options)
0 ignored issues
show
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
{
75
    return '';
76
}
77