Passed
Pull Request — master (#81)
by Michael
02:58
created

VideoController   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 27
dl 0
loc 113
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getVideos() 0 4 1
A checkPrivilege() 0 19 4
A videosNavBar() 0 9 1
A assignVideoContent() 0 25 3
A showFormSubmitVideos() 0 11 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Yogurt;
6
7
/*
8
 You may not change or alter any portion of this comment or credits
9
 of supporting developers from this source code or any supporting source code
10
 which is considered copyrighted (c) material of the original comment or credit authors.
11
12
 This program is distributed in the hope that it will be useful,
13
 but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15
*/
16
17
use Criteria;
18
use XoopsPageNav;
19
20
/**
21
 * @category        Module
22
 * @package         yogurt
23
 * @copyright       {@link https://xoops.org/ XOOPS Project}
24
 * @license         GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
25
 * @author          Marcello Brandão aka  Suico, Mamba, LioMJ  <https://xoops.org>
26
 */
27
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
28
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
29
require_once XOOPS_ROOT_PATH . '/class/criteria.php';
30
require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
31
/**
32
 * Module classes
33
 */
34
//require_once __DIR__ . '/Image.php';
35
//require_once __DIR__ . '/Visitors.php';
36
//require_once __DIR__ . '/Video.php';
37
//require_once __DIR__ . '/Audio.php';
38
//require_once __DIR__ . '/Friendrequest.php';
39
//require_once __DIR__ . '/Friendship.php';
40
//require_once __DIR__ . '/Relgroupuser.php';
41
//require_once __DIR__ . '/Groups.php';
42
//require_once __DIR__ . '/Notes.php';
43
//require_once __DIR__ . '/Configs.php';
44
//require_once __DIR__ . '/Suspensions.php';
45
//if (str_replace('.', '', PHP_VERSION) > 499) {
46
//    require_once __DIR__ . '/Id3v1.php';
47
//}
48
49
/**
50
 * Class YogurtVideoController
51
 */
52
class VideoController extends YogurtController
53
{
54
    /**
55
     * Fetch videos
56
     * @param object $criteria
57
     * @return array of video objects
58
     */
59
60
    public function getVideos(
61
        $criteria
62
    ) {
63
        return $this->videosFactory->getObjects($criteria);
64
    }
65
66
    /**
67
     * Assign Videos Submit Form to theme
68
     * @param int $maxNbVideos the maximum number of videos a user can have
69
     * @param     $presentNb
70
     */
71
72
    public function showFormSubmitVideos(
73
        $maxNbVideos,
74
        $presentNb
75
    ) {
76
        global $xoopsTpl;
77
78
        if ($this->isUser) {
79
            if ((1 === $this->isOwner) && ($maxNbVideos > $presentNb)) {
80
                echo '&nbsp;';
81
82
                $this->videosFactory->renderFormSubmit($xoopsTpl);
83
            }
84
        }
85
    }
86
87
    /**
88
     * Assign Video Content to Template
89
     * @param $countVideos
90
     * @param $videos
91
     * @return bool
92
     */
93
94
    public function assignVideoContent(
95
        $countVideos,
96
        $videos
97
    ) {
98
        if (0 === $countVideos) {
99
            return false;
100
        }
101
102
        /**
103
         * Lets populate an array with the dati from the videos
104
         */
105
106
        $i = 0;
107
108
        foreach ($videos as $video) {
109
            $videosArray[$i]['url'] = $video->getVar('youtube_code', 's');
110
111
            $videosArray[$i]['desc'] = $video->getVar('video_desc', 's');
112
113
            $videosArray[$i]['id'] = $video->getVar('video_id', 's');
114
115
            $i++;
116
        }
117
118
        return $videosArray;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $videosArray seems to be defined by a foreach iteration on line 108. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
119
    }
120
121
    /**
122
     * Create a page navbar for videos
123
     * @param     $countVideos
124
     * @param int $videosPerPage the number of videos in a page
125
     * @param int $start         at which position of the array we start
126
     * @param int $interval      how many pages between the first link and the next one
127
     * @return string|null
128
     * @return string|null
129
     */
130
131
    public function videosNavBar(
132
        $countVideos,
133
        $videosPerPage,
134
        $start,
135
        $interval
136
    ) {
137
        $pageNav = new XoopsPageNav($countVideos, $videosPerPage, $start, 'start', 'uid=' . $this->uidOwner);
138
139
        return $pageNav->renderImageNav($interval);
140
    }
141
142
    /**
143
     * @return bool|void
144
     */
145
146
    public function checkPrivilege()
147
    {
148
        if (0 === $this->helper->getConfig('enable_videos')) {
149
            \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 3, \_MD_YOGURT_VIDEOS_ENABLED_NOT);
150
        }
151
152
        $criteria = new Criteria('config_uid', $this->owner->getVar('uid'));
0 ignored issues
show
Bug introduced by
It seems like $this->owner->getVar('uid') can also be of type array and array; however, parameter $value of Criteria::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

152
        $criteria = new Criteria('config_uid', /** @scrutinizer ignore-type */ $this->owner->getVar('uid'));
Loading history...
153
154
        if (1 === $this->configsFactory->getCount($criteria)) {
155
            $configs = $this->configsFactory->getObjects($criteria);
156
157
            $config = $configs[0]->getVar('videos');
158
159
            if (!$this->checkPrivilegeLevel($config)) {
160
                \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 10, \_MD_YOGURT_NOPRIVILEGE);
161
            }
162
        }
163
164
        return true;
165
    }
166
}
167