Passed
Push — master ( 1d068a...ac1bb1 )
by Struan
10:55 queued 04:23
created

AtoZView::display()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 22
rs 9.8333
1
<?php
2
3
namespace MySociety\TheyWorkForYou\GlossaryView;
4
5
class AtoZView extends BaseView {
6
    public function display(): array {
7
        $data = [
8
            'template_name' => 'atoz',
9
            'this_page' => 'glossary',
10
        ];
11
12
13
        $az = filter_input(INPUT_GET, 'az', FILTER_VALIDATE_REGEXP, ['options' => ['default' => 'A', 'regexp' => '#^[A-Z]$#']]);
14
15
        $data['letter'] = $az;
16
17
        if ($this->has_edit_access()) {
18
            $url = new \MySociety\TheyWorkForYou\Url('glossary_addterm');
19
            $data['add_url'] = $url->generate('url');
20
        }
21
22
        $glossary = new \GLOSSARY(['sort' => 'regexp_replace']);
23
        $glossary->current_letter = $az;
24
25
        $data['page_title'] = $az . ': Glossary Index';
26
        $data['glossary'] = $glossary;
27
        return $data;
28
    }
29
30
    private function get_next_prev($glossary): array {
0 ignored issues
show
Unused Code introduced by
The method get_next_prev() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
31
        $url = new \MySociety\TheyWorkForYou\Url('glossary');
32
        $url->insert(['gl' => $glossary->previous_term['glossary_id']]);
33
        $previous_link = $url->generate('url');
34
        $url->insert(['gl' => $glossary->next_term['glossary_id']]);
35
        $next_link = $url->generate('url');
36
37
        $nextprev =  [
38
            'next'	=>  [
39
                'url'	=> $next_link,
40
                'title'	=> 'Next term',
41
                'body'	=> $glossary->next_term['title'],
42
            ],
43
            'prev'	=>  [
44
                'url'	=> $previous_link,
45
                'title'	=> 'Previous term',
46
                'body'	=> $glossary->previous_term['title'],
47
            ],
48
        ];
49
50
        return $nextprev;
51
    }
52
}
53