Failed Conditions
Branch master (215e8c)
by Johannes
04:26
created

Hansard::gid_to_url()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 1
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace MySociety\TheyWorkForYou\Utility;
4
5
/**
6
 * Hansard Utilities
7
 *
8
 * Utility functions related to content
9
 */
10
11
class Hansard
12
{
13 View Code Duplication
    public static function get_gid_from_url($url) {
14
        $gid = NULL;
15
        $parts = parse_url($url);
16
        parse_str($parts['query'], $query);
17
18
        if ( $query['id'] ) {
19
            if (strpos($parts['path'], 'lords') !== false) {
20
                $gid = 'uk.org.publicwhip/lords/';
21
            } elseif (strpos($parts['path'], 'whall') !== false) {
22
                $gid = 'uk.org.publicwhip/westminhall/';
23
            } else {
24
                $gid = 'uk.org.publicwhip/debate/';
25
            }
26
            $gid .= $query['id'];
27
        }
28
        return $gid;
29
    }
30
31
32 View Code Duplication
    public static function gid_to_url($gid) {
33
        if ( !$gid ) {
34
            return '';
35
        }
36
        global $hansardmajors;
37
        $db = new \ParlDB();
38
39
        $q = $db->query("SELECT major FROM hansard WHERE gid = :gid", array( ':gid' => $gid ));
40
        $url_gid = fix_gid_from_db($gid);
41
        $url = new \URL($hansardmajors[$q->field(0, 'major')]['page']);
42
        $url->insert(array('id' => $url_gid));
43
        return $url->generate();
44
    }
45
}
46