Passed
Pull Request — master (#175)
by Michael
03:42
created

class/VideoController.php (1 issue)

Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace XoopsModules\Suico;
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         suico
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
/**
33
 * Class SuicoVideoController
34
 */
35
class VideoController extends SuicoController
36
{
37
    /**
38
     * Fetch videos
39
     * @param object $criteria
40
     * @return array of video objects
41
     */
42
    public function getVideos(
43
        $criteria
44
    ) {
45
        return $this->videosFactory->getObjects($criteria);
46
    }
47
48
    /**
49
     * Assign Videos Submit Form to theme
50
     * @param int $maxNbVideos the maximum number of videos a user can have
51
     * @param     $presentNb
52
     */
53
    public function showFormSubmitVideos(
54
        $maxNbVideos,
55
        $presentNb
56
    ) {
57
        global $xoopsTpl;
58
        if ($this->isUser) {
59
            if ((1 === $this->isOwner) && ($maxNbVideos > $presentNb)) {
60
                echo '&nbsp;';
61
                $this->videosFactory->renderFormSubmit($xoopsTpl);
62
            }
63
        }
64
    }
65
66
    /**
67
     * Assign Video Content to Template
68
     * @param $countVideos
69
     * @param $videos
70
     * @return bool
71
     */
72
    public function assignVideoContent(
73
        $countVideos,
74
        $videos
75
    ) {
76
        if (0 === $countVideos) {
77
            return false;
78
        }
79
        /**
80
         * Lets populate an array with the dati from the videos
81
         */
82
        $i = 0;
83
        foreach ($videos as $video) {
84
            $videosArray[$i]['url']            = $video->getVar('youtube_code', 's');
85
            $videosArray[$i]['title']          = $video->getVar('video_title', 's');
86
            $videosArray[$i]['desc']           = $video->getVar('video_desc', 's');
87
            $videosArray[$i]['id']             = $video->getVar('video_id', 's');
88
			$videosArray[$i]['featured_video'] = $video->getVar('featured_video', 's');;
89
            $videosArray[$i]['date_created']   = formatTimestamp($video->getVar('date_created', 's'));
90
            $videosArray[$i]['date_updated']   = formatTimestamp($video->getVar('date_updated', 's'));
91
            $i++;
92
        }
93
        return $videosArray;
94
    }
95
96
    /**
97
     * Create a page navbar for videos
98
     * @param     $countVideos
99
     * @param int $videosPerPage the number of videos in a page
100
     * @param int $start         at which position of the array we start
101
     * @param int $interval      how many pages between the first link and the next one
102
     * @return string|null
103
     * @return string|null
104
     */
105
    public function videosNavBar(
106
        $countVideos,
107
        $videosPerPage,
108
        $start,
109
        $interval
110
    ) {
111
        $pageNav = new XoopsPageNav($countVideos, $videosPerPage, $start, 'start', 'uid=' . $this->uidOwner);
112
        return $pageNav->renderImageNav($interval);
113
    }
114
115
    /**
116
     * @return bool|void
117
     */
118
    public function checkPrivilege()
119
    {
120
        if (0 === $this->helper->getConfig('enable_videos')) {
121
            \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 3, \_MD_SUICO_VIDEOS_ENABLED_NOT);
122
        }
123
        $criteria = new Criteria('config_uid', $this->owner->getVar('uid'));
124
        if (1 === $this->configsFactory->getCount($criteria)) {
125
            $configs = $this->configsFactory->getObjects($criteria);
126
            $config  = $configs[0]->getVar('videos');
0 ignored issues
show
The assignment to $config is dead and can be removed.
Loading history...
127
            /*
128
            if (!$this->checkPrivilegeLevel($config)) {
129
                \redirect_header('index.php?uid=' . $this->owner->getVar('uid'), 10, sprintf(_MD_SUICO_NOPRIVILEGE,'Videos'));
130
            }
131
            */
132
        }
133
        return true;
134
    }
135
}
136