MartinHotelNewsHandler::GetHotelNews()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 3
nop 1
dl 0
loc 23
rs 9.552
c 0
b 0
f 0
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
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
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;
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;
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