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

MartinHotelNewsHandler::GetHotelNews()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 23
rs 8.7972
cc 4
eloc 17
nc 3
nop 1
1
<?php
2
3
/**
4
 * @get       martin hotel news
5
 * @license   http://www.blags.org/
6
 * @created   :2010年06月29日 20时38分
7
 * @copyright 1997-2010 The Martin Group
8
 * @author    Martin <[email protected]>
9
 * */
10
class MartinHotelNews extends XoopsObject
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...
11
{
12
}
13
14
/**
15
 * @get       martin hotel news handler
16
 * @license   http://www.blags.org/
17
 * @created   :2010年06月29日 20时38分
18
 * @copyright 1997-2010 The Martin Group
19
 * @author    Martin <[email protected]>
20
 * */
21
class MartinHotelNewsHandler extends XoopsObjectHandler
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
22
{
23
    /**
24
     * @get       rows
25
     * @license   http://www.blags.org/
26
     * @created   :2010年06月20日 13时09分
27
     * @copyright 1997-2010 The Martin Group
28
     * @author    Martin <[email protected]>
29
     * @param      $sql
30
     * @param null $key
31
     * @return array
32
     */
33 View Code Duplication
    public function GetRows($sql, $key = null)
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...
34
    {
35
        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...
36
        $result = $xoopsDB->query($sql);
37
        $rows   = array();
38
        while ($row = $xoopsDB->fetchArray($result)) {
39
            if (is_null($key)) {
40
                $rows[] = $row;
41
            } else {
42
                $rows[$row[$key]] = $row;
43
            }
44
        }
45
46
        return $rows;
47
    }
48
49
    /**
50
     * @get       hotel news
51
     * @method:
52
     * @license   http://www.blags.org/
53
     * @created   :2010年06月29日 20时38分
54
     * @copyright 1997-2010 The Martin Group
55
     * @author    Martin <[email protected]>
56
     * @param $artids
57
     * @return array|string
58
     */
59
    public function GetHotelNews($artids)
60
    {
61
        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...
62
        if (empty($artids) || !is_array($artids)) {
63
            return $artids;
64
        }
65
        $artids    = implode(",", $artids);
66
        $sql       = "SELECT text_id,alias FROM " . $xoopsDB->prefix("news_text") . " WHERE art_id IN ($artids)";
67
        $text_rows = $this->GetRows($sql, 'text_id');
68
69
        $sql    = "SELECT art_id,cat_alias,art_title,art_pages FROM " . $xoopsDB->prefix("news_article") . "    WHERE art_id IN ($artids) ORDER BY art_time_publish DESC";
70
        $result = $xoopsDB->query($sql);
71
        $rows   = array();
72
        while ($row = $xoopsDB->fetchArray($result)) {
73
            $text_id              = unserialize($row['art_pages']);
74
            $text_id              = $text_id[0];
75
            $url                  = $text_rows[$text_id]['alias'];
76
            $url                  = XOOPS_URL . $row['cat_alias'] . $url;
77
            $rows[$row['art_id']] = array('url' => $url, 'title' => $row['art_title']);
78
        }
79
80
        return $rows;
81
    }
82
}
83