Passed
Pull Request — Showing-Posts (#54)
by Stone
04:55 queued 02:28
created

SiteConfig::getSiteConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Modules;
4
5
use App\Models\CategoryModel;
6
use Core\Modules\Module;
7
use App\Models\ConfigModel;
8
9
class SiteConfig extends Module
10
{
11
    /**
12
     * Gets the entire site configuration and arranges it into a displayable list
13
     * @return array the config ordered and ready to display
14
     * @throws \ReflectionException
15
     */
16
    public function getSiteConfig():array
17
    {
18
19
        $configs = new ConfigModel($this->container);
20
        $siteConfig = $configs->getAllConfig();
21
        $data = [];
22
        foreach ($siteConfig as $config) {
23
            $data[$config->configs_name] = $config->configs_value;
24
        }
25
        return $data;
26
    }
27
28
    /**
29
     * create the front end menu object to be sent to twig and add the urls
30
     * @return array
31
     * @throws \ReflectionException
32
     */
33
    public function getMenu():array
34
    {
35
        $categoryModel = new CategoryModel($this->container);
36
37
        $data = [];
38
        //get the categories from database
39
        $categories = $categoryModel->getCategories();
40
        foreach ($categories as $category) {
41
            $data += [
42
                $category->category_name => '/category/posts/' . $category->categories_slug
43
            ];
44
        }
45
        return $data;
46
    }
47
}