Completed
Push — master ( e53778...db0b20 )
by Davide
03:26
created

LaravelJumbotronImages::getParametersArray()   B

Complexity

Conditions 8
Paths 40

Size

Total Lines 38
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 13.2607

Importance

Changes 0
Metric Value
cc 8
eloc 23
nc 40
nop 1
dl 0
loc 38
ccs 13
cts 23
cp 0.5652
crap 13.2607
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace DavideCasiraghi\LaravelJumbotronImages;
4
5
use DavideCasiraghi\LaravelJumbotronImages\Models\JumbotronImage;
6
7
class LaravelJumbotronImages
8
{
9
    /**
10
     * Return a random quote.
11
     *
12
     * @return \DavideCasiraghi\LaravelJumbotronImages\Models\JumbotronImage
13
     */
14 1
    public function getJumbotronImage($id)
15
    {
16 1
        $jumbotronImage = JumbotronImage::find($id);
17 1
        $jumbotronImage->parameters = $this->getParametersArray($jumbotronImage);
0 ignored issues
show
Bug introduced by
The property parameters does not seem to exist on DavideCasiraghi\LaravelJ...s\Models\JumbotronImage. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
18
19 1
        $ret = $jumbotronImage;
20 1
        return $ret;
21
    }
22
    
23
    /*****************************/
24
    
25
    /**
26
     * Show a Jumbotron Image.
27
     *
28
     * @return \DavideCasiraghi\LaravelJumbotronImages\Models\JumbotronImage
29
     */
30
    public function showJumbotronImage($jumbotronImageId)
31
    {    
32
        $jumbotronImage = JumbotronImage::find($jumbotronImageId);
33
        $jumbotronImage->parameters = $this->getParametersArray($jumbotronImage);
0 ignored issues
show
Bug introduced by
The property parameters does not seem to exist on DavideCasiraghi\LaravelJ...s\Models\JumbotronImage. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
34
        
35
        return view('laravel-jumbotron-images::jumbotronImages.show', compact('jumbotronImage'));
36
    }
37
    
38
    /***************************************************************************/
39
    
40
    /**
41
     * Attach to the jumbotron image object an array with the parameters for the show-jumbotron-image view.
42
     *
43
     * @return array
44
     */
45 1
    public static function getParametersArray($jumbotronImage)
46
    {   
47
        $ret = [
48 1
             'opacity' => 'opacity: '.$jumbotronImage->opacity.';',
49 1
             'background_color' => "background: #".$jumbotronImage->background_color.";",
50 1
             'image' => "background-image:url(images/banners/".$jumbotronImage->image_file_name.");",
51
         ];
52
             
53
        /* Parallax - The element is defined with stellar plugin like: <section class="parallax" data-stellar-background-ratio="0.5" ><span>Summer</span></section>*/
54 1
        if ($jumbotronImage->parallax == 1){
55
			$ret['parallax'] = " parallax";
56
			$ret['parallax_ratio'] = "data-stellar-background-ratio='0.5'";
57
		}
58
         
59 1
        if ($jumbotronImage->white_moon == 1){
60
            $ret['white_moon'] = " moon-curve ";
61
        }
62
        
63
        /* Scroll down arrow */
64 1
		if ($jumbotronImage->scroll_down_arrow  == 1){
65
			$ret['scroll_down_arrow'] = "<div class='scroll-arrow white'><span>SCROLL DOWN</span><img src='/vendor/laravel-jumbotron-images/assets/images/angle-down-regular.svg'></div>";
66
		}
67
        
68 1
        if ($jumbotronImage->text_width != 100){
69 1
    		switch ($jumbotronImage->text_horizontal_alignment) {
70 1
    			case 0:	// Left
71 1
    				$ret['text_width'] = "width: ".$jumbotronImage->text_width."%;";
72 1
    			break;
73
    			case 1: // Center
74
    				$ret['text_width'] = "width: ".$jumbotronImage->text_width."%; margin: auto;";
75
    			break;
76
    			case 2: // Right
77
    				$ret['text_width'] = "width: ".$jumbotronImage->text_width."%; float: right;";
78
    			break;
79
    		}
80
        }
81
82 1
        return $ret;
83
    }
84
85
}
86