Completed
Push — master ( c4a686...2e0334 )
by Arjay
11:39
created

FileAssetEloquentRepository::strParser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
namespace Yajra\CMS\Repositories\FileAsset;
4
5
use Yajra\CMS\Entities\Configuration;
6
use Yajra\CMS\Entities\FileAsset;
7
use Yajra\CMS\Entities\FileAssetGroup;
8
use Yajra\CMS\Repositories\RepositoryAbstract;
9
use Roumen\Asset\Asset;
10
11
/**
12
 * Class FileAssetEloquentRepository
13
 *
14
 * @package Yajra\CMS\Repositories\Article
15
 */
16
class FileAssetEloquentRepository extends RepositoryAbstract implements FileAssetRepository
17
{
18
    /**
19
     * Get repository model.
20
     *
21
     * @return \Yajra\CMS\Entities\FileAsset
22
     */
23
    public function getModel()
24
    {
25
        return new FileAsset();
26
    }
27
28
    /**
29
     * Get all file assets.
30
     *
31
     * @return \Illuminate\Database\Eloquent\Collection|static[]
32
     */
33
    public function all()
34
    {
35
        return $this->getModel()->query()->get();
36
    }
37
38
    /**
39
     * Register admin required assets.
40
     */
41
    public function registerAdminRequireAssets()
42
    {
43
        foreach (config('asset.admin_required_assets', []) as $asset => $requiredValue) {
44
            Asset::add($requiredValue);
45
        }
46
    }
47
48
    /**
49
     * Get file asset by name.
50
     *
51
     * @param string $name
52
     * @param null $category
53
     * @return \Yajra\CMS\Entities\FileAsset
54
     */
55
    public function getByName($name, $category = null)
56
    {
57
        if (is_null($category)) {
58
            $category = config('asset.default');
59
        }
60
        
61
        return $this->getModel()
62
                    ->where('name', $name)
63
                    ->where('category', $category)
64
                    ->first();
65
    }
66
67
    /**
68
     * Get file asset by type and name.
69
     *
70
     * @param string $type
71
     * @param string $name
72
     * @return \Yajra\CMS\Entities\FileAsset
73
     */
74
    private function getByTypeAndName($type, $name)
75
    {
76
        return $this->getModel()
77
                    ->where('type', $type)
78
                    ->where('name', $name)
79
                    ->where('category', Configuration::key('asset.default'))
80
                    ->first();
81
    }
82
83
    /**
84
     * Add site asset.
85
     *
86
     * @param string $type
87
     * @return \Roumen\Asset\Asset;
0 ignored issues
show
Documentation introduced by
The doc-type \Roumen\Asset\Asset; could not be parsed: Expected "|" or "end of type", but got ";" at position 19. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
88
     */
89
    public function addAsset($type)
90
    {
91
        $backEndAssets = $this->getGroupByType($type, 'backend');
92
        foreach ($backEndAssets as $asset) {
93
            Asset::add($this->getByTypeAndName($type, $asset->file_asset_name)->url);
94
        }
95
    }
96
97
    /**
98
     * Get asset group by type and user.
99
     *
100
     * @param string $type
101
     * @param string $user
102
     * @return \Yajra\CMS\Entities\FileAssetGroup
103
     */
104
    public function getGroupByType($type, $user)
105
    {
106
        return FileAssetGroup::where('type', $type)
107
                             ->orderBy('order', 'asc')
108
                             ->orderBy('user', $user)
109
                             ->get();
110
    }
111
}