CoverController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 53
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 1
A getCover() 0 20 4
1
<?php
2
/**
3
 * Audio Player
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the LICENSE.md file.
7
 *
8
 * @author Marcel Scherello <[email protected]>
9
 * @author Sebastian Doell <[email protected]>
10
 * @copyright 2016-2019 Marcel Scherello
11
 * @copyright 2015 Sebastian Doell
12
 */
13
14
namespace OCA\audioplayer\Controller;
15
16
use OCP\AppFramework\Controller;
17
use OCP\IL10N;
18
use OCP\IRequest;
19
use OCP\ILogger;
20
use OCP\IDbConnection;
21
use \OCA\audioplayer\Http\ImageResponse;
22
23
24
class CoverController extends Controller
25
{
26
27
    private $userId;
28
    private $l10n;
29
    private $logger;
30
    private $DBController;
31
    private $db;
32
33
    public function __construct(
34
        $appName,
35
        IRequest $request,
36
        $userId,
37
        IL10N $l10n,
38
        IDbConnection $db,
39
        ILogger $logger,
40
        DbController $DBController
41
    )
42
    {
43
        parent::__construct($appName, $request);
44
        $this->userId = $userId;
45
        $this->l10n = $l10n;
46
        $this->db = $db;
47
        $this->logger = $logger;
48
        $this->DBController = $DBController;
49
    }
50
51
    /**
52
     * @NoAdminRequired
53
     * @NoCSRFRequired
54
     * @param $album
55
     * @return ImageResponse
56
     */
57
    public function getCover($album)
58
    {
59
        $cover = '';
60
        $SQL = "SELECT  `cover`, `name`, `artist_id`
61
				FROM `*PREFIX*audioplayer_albums` 
62
			 	WHERE  `user_id` = ? AND `id` = ? 
63
			 	";
64
65
        $stmt = $this->db->prepare($SQL);
66
        $stmt->execute(array($this->userId, $album));
67
        $results = $stmt->fetchAll();
68
        foreach ($results as $row) {
69
            $artist = $this->DBController->loadArtistsToAlbum($album, $row['artist_id']);
70
            $cover = $row['cover'];
71
            if ($row['name'] === $this->l10n->t('Unknown') AND $artist === $this->l10n->t('Various Artists')) {
72
                $cover = 'iVBORw0KGgoAAAANSUhEUgAAAPoAAAD6CAIAAAAHjs1qAAAAK3RFWHRDcmVhdGlvbiBUaW1lAERpIDE1IE5vdiAyMDE2IDExOjU3OjA0ICswMTAwCiwhogAAAAd0SU1FB+ALDwo7AioIm6cAAAAJcEhZcwAALiMAAC4jAXilP3YAAAAEZ0FNQQAAsY8L/GEFAAAO2UlEQVR42u3d+1NU9R/H8f5EWG5ykzukZUR4wVBD00olsxwzvDRUIxNUViQzFZE6EGmlNSqokBd0FKPClDtetvfgfBu/nvf7s8vu+ZzP4bxfjx+dz9mjZ5+7fnb3c855JgNAjWdc/wUAgoPcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHJ3oLS09Ny5c7OzsyMjIytWrAhgjzU1NS+++GJeXp7rf7pjyD1oVN7Nmzfj/3Pnzp26ujp7uyssLOzr65ucnKRX1+jo6I4dO1wfAJeQe6AaGhoePHgQ/39zc3NFRUU2dkdv5+Pj40/t7t1333V9GJxB7sF566234oL9+/fb2OPhw4fZ3dXX17s+GG4g94C0tbXFZd3d3TZ2OjAwwO5uYmIiPz/f9SFxALlbF4vFenp64kbHjx+3sesLFy5Ie+zv73d9YBxA7nbl5uYODg7GE7GU+6FDhww7bW5udn14gobcLSorKxsbG0vYur3cc3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S0tLQ5zp8+UhseU7jMzODgobUKvBNdH1C7knq7Nmzenv3IhtdylO+aR1tZWdhPDKkv25I+IQe4+qK2tlda3WM1d+ll0eHiYXfGSlZUlnflBInYbJhZy90dpaeno6GjAudPc3ft9Iv1XI12NwzD1ku5IHDHI3Te5ubnSVdIt5Z6xsCTuyWtszM/Pb9y4kR1JL0jp8gSkoaHB9fELAnL3E00hpIUolnLPWJiiNDU1HTp0aPv27YazS6W1wfHI3aLDALn7L4X1ZLZvgWRYMhAXLj4TScjdiubm5vDkXllZaZjGdHZ2uj5awUHutqxbty759WT2cqepjnRnjvjCbeDz8vJcH6rgIHeLqqqqpCv3BpZ7V1eXYb9bt251fZAChdztKigoGB4edpV7bW2tYaf9/f2uD0/QkLt1NJ2QbkZgO/dPPvlE2uPk5GT0LhKWEHIPiHTO/2OWTiCSLu0blxdLRhtyD450Rw1y8OBBG3uUvn+UbnETecg9UFu2bPGuJ7t//77h+gLpyMnJ8Z57NTAwEMlryCQDuQeNPj4+uU6L5tAvv/yyvd1VVlYODQ09fo09fPiwr68vqlcZSAZyd6C8vPzy5cvxhRND6+vrbe+OPivTZKm3t5fmNq7/6Y4hd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDoogd1AEuYMiyB0UQe6gCHIHRZA7KILcQRHkDor8C3D7LDKaAfDjAAAAAElFTkSuQmCC';
73
            }
74
        }
75
        $imageData = base64_decode($cover);
76
        return new ImageResponse(array('mimetype' => 'image/jpg', 'content' => $imageData));
77
    }
78
}
79