Completed
Push — master ( 6a1d7c...5e042f )
by Gabriel
06:31
created

MediaModule::loadAssetContent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 0
cts 8
cp 0
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
crap 6
1
<?php
2
3
namespace ByTIC\Modules\MediaLibrary;
4
5
use ByTIC\MediaLibrary\HasMedia\HasMediaTrait;
6
use ByTIC\Modules\MediaLibrary\Application\Library\View\View;
7
8
/**
9
 * Class MediaModule
10
 * @package ByTIC\Modules\MediaLibrary
11
 */
12
class MediaModule
13
{
14
15
    /**
16
     * @param $path
17
     * @return null|string
18
     */
19
    public static function loadAssetContent($path)
20
    {
21
        $fullPath = self::basePath()
22
            . DIRECTORY_SEPARATOR . 'resources'
23
            . DIRECTORY_SEPARATOR . 'assets'
24
            . $path;
25
        if (file_exists($fullPath)) {
26
            return file_get_contents($fullPath);
27
        }
28
        return '';
29
    }
30
31
    /**
32
     * @return string
33
     */
34 1
    public static function basePath()
35
    {
36 1
        return dirname(__DIR__);
37
    }
38
39
    /**
40
     * @param HasMediaTrait $item
0 ignored issues
show
introduced by
The type HasMediaTrait for parameter $item is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?
Loading history...
41
     * @return null|string
42
     */
43
    public static function getAdminImagesGridForModel($item)
44
    {
45
        $images = $item->getImages();
46
47
        return self::loadView(
48
            '/admin/gallery/images-grid',
49
            ['item' => $item, 'images' => $images]
50
        );
51
    }
52
53
    /**
54
     * @param $path
55
     * @param array $variables
56
     * @return null|string
57
     */
58
    public static function loadView($path, $variables = [])
59
    {
60
        return View::instance()->load($path, $variables, true);
61
    }
62
}
63