Completed
Push — master ( 68e592...ac418e )
by WEBEWEB
01:42
created

WikiController::getWikiPages()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 33
rs 9.392
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\BootstrapBundle\Controller;
13
14
use Symfony\Component\HttpFoundation\Request;
15
use Symfony\Component\HttpFoundation\Response;
16
use WBW\Bundle\BootstrapBundle\Model\WikiPage;
17
18
/**
19
 * Wiki controller.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Controller
23
 */
24
class WikiController extends AbstractWikiController {
25
26
    /**
27
     * Get the wiki pages.
28
     *
29
     * @return WikiPage[] Returns the wiki pages.
30
     */
31
    public static function getWikiPages() {
32
33
        // Initialize the table of contents.
34
        $tableContents = [];
35
36
        // Twig extensions > CSS
37
        $tableContents[] = new WikiPage("Twig-extension", "CSS", "button", "Button");
38
        $tableContents[] = new WikiPage("twig-extension", "CSS", "code", "Code");
39
        $tableContents[] = new WikiPage("Twig-extension", "CSS", "grid", "Grid");
40
        $tableContents[] = new WikiPage("Twig-extension", "CSS", "image", "Image");
41
        $tableContents[] = new WikiPage("Twig-extension", "CSS", "typography", "Typography");
42
43
        // Twig extensions > Component
44
        $tableContents[] = new WikiPage("Twig-extension", "Component", "alert", "Alert");
45
        $tableContents[] = new WikiPage("Twig-extension", "Component", "badge", "Badge");
46
        $tableContents[] = new WikiPage("Twig-extension", "Component", "glyphicon", "Glyphicon");
47
        $tableContents[] = new WikiPage("Twig-extension", "Component", "label", "Label");
48
        $tableContents[] = new WikiPage("Twig-extension", "Component", "progress-bar", "Progress bar");
49
50
        // Twig extensions > Plugin
51
        $tableContents[] = new WikiPage("Twig-extension", "Plugin", "font-awesome", "Font Awesome");
52
        $tableContents[] = new WikiPage("Twig-extension", "Plugin", "jquery-inputmask", "jQuery InputMask");
53
        $tableContents[] = new WikiPage("Twig-extension", "Plugin", "material-design-iconic-font", "Material Design Iconic Font");
54
        $tableContents[] = new WikiPage("Twig-extension", "Plugin", "meteocons", "Meteocons");
55
56
        // Twig extensions > Utility
57
        $tableContents[] = new WikiPage("Twig-extension", "Utility", "form-button", "Form button");
58
        $tableContents[] = new WikiPage("Twig-extension", "Utility", "role-label", "Role label");
59
        $tableContents[] = new WikiPage("Twig-extension", "Utility", "table-button", "Table button");
60
61
        // Return the table of contents.
62
        return $tableContents;
63
    }
64
65
    /**
66
     * Displays a wiki page.
67
     *
68
     * @param Request $request The request.
69
     * @param string $category The category.
70
     * @param string $package The parent.
71
     * @param string $page The page.
72
     * @return Response Returns the response.
73
     */
74
    public function indexAction(Request $request, $category, $package, $page) {
75
76
        // Initialize.
77
        $wikiPages = self::getWikiPages();
78
        $wikiPage  = null;
79
80
        // Find the wiki page.
81
        foreach ($wikiPages as $current) {
82
            if ($category === $current->getCategory() && $package === $current->getPackage() && $page === $current->getPage()) {
83
                $wikiPage = $current;
84
                break;
85
            }
86
        }
87
88
        // Check if the wiki page exists.
89
        if (null === $wikiPage) {
90
91
            // Set the default wiki page.
92
            $wikiPage = $wikiPages[0];
93
94
            // Notify the user.
95
            $this->notifyDanger("The requested page was not found");
96
            $this->notifyInfo("You have been redirected to homepage");
97
        }
98
99
        // Set the template.
100
        $template = [
101
            "@",
102
            $wikiPage->getBundle(),
103
            "/Wiki/",
104
            strtolower($wikiPage->getCategory()),
105
            "/",
106
            strtolower($wikiPage->getPackage()),
107
            "/",
108
            $wikiPage->getPage(),
109
            ".html.twig",
110
        ];
111
112
        // Returns the response.
113
        return $this->render(implode("", $template), [
114
                "wikiPage"                  => $wikiPage,
115
                "wikiPages"                 => $wikiPages,
116
                "syntaxHighlighterConfig"   => $this->getSyntaxHighlighterConfig(),
117
                "syntaxHighlighterDefaults" => $this->getSyntaxHighlighterDefaults(),
118
                "user"                      => $this->getSampleUser(),
119
                "userRoleColors"            => $this->getSampleUserRoleColors(),
120
                "userRoleTranslations"      => $this->getSampleUserRoleTranslations(),
121
        ]);
122
    }
123
124
}
125