Passed
Push — master ( 34e6b5...1e23bd )
by Robbie
02:06
created

TaxonomyDirectoryController::renderBreadcrumb()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace SilverStripe\Taxonomy\Controllers;
4
5
use Page;
0 ignored issues
show
Bug introduced by
The type Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use PageController;
0 ignored issues
show
Bug introduced by
The type PageController was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SilverStripe\Control\HTTPRequest;
8
use SilverStripe\ORM\ArrayList;
9
use SilverStripe\View\ArrayData;
10
use SilverStripe\View\SSViewer;
11
12
/**
13
 * Class TaxonomyDirectoryController
14
 *
15
 * Controller for returning a list of pages tagged with a specific Taxonomy Term
16
 */
17
class TaxonomyDirectoryController extends PageController
18
{
19
20
    private static $allowed_actions = array(
0 ignored issues
show
introduced by
The private property $allowed_actions is not used, and could be removed.
Loading history...
21
        'index'
22
    );
23
24
    public function index(HTTPRequest $HTTPRequest)
25
    {
26
        $termString = $HTTPRequest->param('ID');
27
28
        $pages = Page::get()
29
            ->innerJoin(
30
                'BasePage_Terms',
31
                '"Page"."ID"="BasePage_Terms"."BasePageID"')
32
            ->innerJoin(
33
                'TaxonomyTerm',
34
                "\"BasePage_Terms\".\"TaxonomyTermID\"=\"TaxonomyTerm\".\"ID\" AND \"TaxonomyTerm\".\"Name\" = '$termString'");
35
36
        return $this->customise(new ArrayData(array(
37
            'Title' => $termString,
38
            'Term' => $termString,
39
            'Pages' => $pages,
40
            'Breadcrumbs' => $this->renderBreadcrumb($termString)
41
        )))->renderWith(array("TaxonomyDirectory", "Page"));
42
    }
43
44
    protected function renderBreadcrumb($termString)
45
    {
46
        $page = new Page();
47
        $page->Title = $termString;
48
49
        $template = new SSViewer('BreadcrumbsTemplate');
50
        return $template->process($this->customise(new ArrayData(array(
51
            "Pages" => new ArrayList(array($page))
52
        ))));
53
    }
54
55
}
56
57