Passed
Push — master ( 93ffcd...6429db )
by Iman
04:12
created

ModulesRepo::getAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\ModuleGenerator;
4
5
use Illuminate\Support\Facades\DB;
6
7
class ModulesRepo
8
{
9
    public static function getControllerName($moduleId)
10
    {
11
        return self::find($moduleId)->controller;
12
    }
13
14
    public static function find($id)
15
    {
16
        return self::first(['id' => $id]);
17
    }
18
19
    private static function where($conditions)
20
    {
21
        return DB::table('cms_moduls')->where($conditions);
22
    }
23
24
    public static function getByTableName($table)
25
    {
26
        return self::first(['table_name' => $table]);
27
    }
28
29
    /**
30
     * @param $path
31
     * @return mixed
32
     */
33
    public static function modulePathExists($path)
34
    {
35
        return (boolean) self::count(['path' => $path, 'deleted_at' => null]);
36
    }
37
38
    public static function updateById($id, $data)
39
    {
40
        return self::where(['id' => $id])->update($data);
41
    }
42
43
    public static function getByPath($modulepath)
44
    {
45
        return self::first(['path' => $modulepath]);
46
    }
47
48
    public static function countByPath($modulepath)
49
    {
50
        return self::count(['path' => $modulepath]);
51
    }
52
53
    /**
54
     * @param $conditions
55
     * @return mixed
56
     */
57
    private static function first($conditions)
58
    {
59
        return self::where($conditions)->first();
60
    }
61
62
    /**
63
     * @param $conditions
64
     * @return mixed
65
     */
66
    private static function count($conditions)
67
    {
68
        return self::where($conditions)->count();
69
    }
70
71
    public static function getAll($cols = null)
72
    {
73
        return self::where(['is_protected' => 0])->orderby("name", "asc")->get($cols);
74
    }
75
}