Completed
Pull Request — master (#114)
by Bart
02:07
created

Schematic::getRecords()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 16
nc 5
nop 1
1
<?php
2
3
namespace NerdsAndCompany\Schematic;
4
5
use Craft;
6
7
/**
8
 * Schematic.
9
 *
10
 * Sync Craft Setups.
11
 *
12
 * @author    Nerds & Company
13
 * @copyright Copyright (c) 2015-2018, Nerds & Company
14
 * @license   MIT
15
 *
16
 * @see      http://www.nerds.company
17
 */
18
class Schematic
19
{
20
    const DATA_TYPES = [
21
        'sites' => Services\ModelProcessor::class,
22
        'volumes' => Services\Volumes::class,
23
        'assetTransforms' => Services\ModelProcessor::class,
24
        'fields' => Services\Fields::class,
25
        'plugins' => Services\Plugins::class,
26
        'sections' => Services\Sections::class,
27
        'globalSets' => Services\ModelProcessor::class,
28
        'userGroups' => Services\UserGroups::class,
29
        'users' => Services\Users::class,
30
        'categoryGroups' => Services\ModelProcessor::class,
31
        'tagGroups' => Services\TagGroups::class,
32
        'elementIndexSettings' => Services\ElementIndexSettings::class,
33
    ];
34
35
    /**
36
     * Get records for datatype.
37
     *
38
     * @TODO: Make this more dynamic
39
     *
40
     * @param string $datatype
41
     *
42
     * @return Model[]
43
     */
44
    public static function getRecords(string $datatype)
45
    {
46
        $records = [];
47
        switch ($datatype) {
48
            case 'assetTransforms':
49
                $records = Craft::$app->assetTransforms->getAllTransforms();
50
                break;
51
            case 'categoryGroups':
52
                $records = Craft::$app->categories->getAllGroups();
53
                break;
54
            case 'globalSets':
55
                $records = Craft::$app->globals->getAllSets();
56
                break;
57
            case 'sites':
58
                $records = Craft::$app->sites->getAllSites();
59
                break;
60
        }
61
62
        return $records;
63
    }
64
65
    /**
66
     * Is force enabled?
67
     *
68
     * @var bool
69
     */
70
    public static $force = false;
71
72
    /**
73
     * Logs an error message.
74
     *
75
     * @param string|array $message the message to be logged. This can be a simple string or a more
76
     *                              complex data structure, such as array.
77
     */
78
    public static function error($message)
79
    {
80
        Craft::error($message, 'schematic');
81
    }
82
83
    /**
84
     * Logs a warning message.
85
     *
86
     * @param string|array $message the message to be logged. This can be a simple string or a more
87
     *                              complex data structure, such as array.
88
     */
89
    public static function warning($message)
90
    {
91
        Craft::warning($message, 'schematic');
92
    }
93
94
    /**
95
     * Logs an info message.
96
     *
97
     * @param string|array $message the message to be logged. This can be a simple string or a more
98
     *                              complex data structure, such as array.
99
     */
100
    public static function info($message)
101
    {
102
        Craft::info($message, 'schematic');
103
    }
104
}
105