Passed
Pull Request — dev (#45)
by Stone
04:22 queued 02:13
created

ConfigModel   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 29
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAllConfig() 0 22 2
1
<?php
2
3
namespace App\Models;
4
5
use Core\Model;
6
7
/**
8
 * Class ConfigModel
9
 * @package App\Models
10
 */
11
class ConfigModel extends Model
12
{
13
    /**
14
     * Returns all the configs orderd with their class names
15
     * @return array
16
     * @throws \Exception
17
     */
18
    public function getAllConfig():array
19
    {
20
        $returnData = [];
21
        //Grabbing the configs class
22
        $sql = 'select * from configs_class order by class';
23
        $this->query($sql);
24
        $this->execute();
25
        $configClass = $this->stmt->fetchAll();
26
27
        //getting the configurations grouped by class
28
        $sql = "select idconfigs, configs_name, configs_value from configs where configs_class_idconfigsclass = :classId";
29
        $this->query($sql);
30
31
        foreach ($configClass as $class) {
32
            //we remove the first 3 characters as they are used for ordering (10_global_site_configuration)
33
            $className = substr($class->class, 3);
34
35
            $this->bind(':classId', $class->idconfigsclass);
36
            $this->execute();
37
            $returnData[$className] = $this->stmt->fetchAll();
38
        }
39
        return $returnData;
40
    }
41
}