View   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 91
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0
ccs 0
cts 43
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A getCatalogue() 0 8 2
A getImages() 0 11 2
A getFlipbookWidth() 0 6 2
A getFlipbookHeight() 0 6 2
1
<?php
2
/**
3
 * File: View.php
4
 *
5
 * @author      Maciej Sławik <[email protected]>
6
 * Github:      https://github.com/maciejslawik
7
 */
8
9
namespace MSlwk\ICatalogue\Block;
10
11
use Magento\Framework\UrlInterface;
12
use Magento\Framework\View\Element\Template;
13
use Magento\Framework\App\Request\Http;
14
use Magento\Framework\View\Element\Template\Context;
15
use MSlwk\ICatalogue\Model\CatalogueFactory;
16
use MSlwk\ICatalogue\Model\Catalogue;
17
use MSlwk\ICatalogue\Model\ResourceModel\Catalogue as CatalogueResource;
18
19
/**
20
 * Class View
21
 *
22
 * @package MSlwk\ICatalogue\Block
23
 */
24
class View extends Template
25
{
26
    /**
27
     * @var CatalogueFactory
28
     */
29
    protected $catalogueFactory;
30
31
    /**
32
     * @var CatalogueResource
33
     */
34
    protected $catalogueResource;
35
36
    /**
37
     * @var Catalogue
38
     */
39
    protected $catalogue;
40
41
    /**
42
     * @var Http
43
     */
44
    protected $request;
45
46
    /**
47
     * Details constructor.
48
     *
49
     * @param Http $request
50
     * @param CatalogueFactory $catalogueFactory
51
     * @param CatalogueResource $catalogueResource
52
     * @param Context $context
53
     * @param array $data
54
     */
55
    public function __construct(
56
        Http $request,
57
        CatalogueFactory $catalogueFactory,
58
        CatalogueResource $catalogueResource,
59
        Context $context,
60
        array $data = []
61
    ) {
62
        $this->request = $request;
63
        $this->catalogueFactory = $catalogueFactory;
64
        $this->catalogueResource = $catalogueResource;
65
        parent::__construct($context, $data);
66
    }
67
68
    /**
69
     * @return Catalogue
70
     */
71
    public function getCatalogue()
72
    {
73
        if (!$this->catalogue) {
74
            $this->catalogue = $this->catalogueFactory->create();
75
            $this->catalogueResource->load($this->catalogue, $this->request->getParam('id'));
76
        }
77
        return $this->catalogue;
78
    }
79
80
    /**
81
     * @return array
82
     */
83
    public function getImages()
84
    {
85
        $images = [];
86
        foreach ($this->getCatalogue()->getImages() as $image) {
87
            $images[] = [
88
                'url' => $this->_storeManager->getStore()->getBaseUrl(UrlInterface::URL_TYPE_MEDIA)
89
                    . $image['image_uri']
90
            ];
91
        }
92
        return $images;
93
    }
94
95
    /**
96
     * @return int
97
     */
98
    public function getFlipbookWidth()
99
    {
100
        return is_numeric($this->_scopeConfig->getValue('mslwk_icatalogue/general/width'))
101
            ? 2 * intval($this->_scopeConfig->getValue('mslwk_icatalogue/general/width'))
102
            : 922;
103
    }
104
105
    /**
106
     * @return int
107
     */
108
    public function getFlipbookHeight()
109
    {
110
        return is_numeric($this->_scopeConfig->getValue('mslwk_icatalogue/general/height'))
111
            ? intval($this->_scopeConfig->getValue('mslwk_icatalogue/general/height'))
112
            : 600;
113
    }
114
}
115