-
Notifications
You must be signed in to change notification settings - Fork 4
/
Video.php
181 lines (166 loc) · 5.31 KB
/
Video.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
declare(strict_types=1);
namespace XoopsModules\Suico;
/*
You may not change or alter any portion of this comment or credits
of supporting developers from this source code or any supporting source code
which is considered copyrighted (c) material of the original comment or credit authors.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
/**
* @category Module
* @package suico
* @copyright {@link https://xoops.org/ XOOPS Project}
* @license GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
* @author Marcello Brandão aka Suico, Mamba, LioMJ <https://xoops.org>
*/
use Xmf\Module\Helper\Permission;
use XoopsDatabaseFactory;
use XoopsObject;
/**
* Includes of form objects and uploader
*/
require_once XOOPS_ROOT_PATH . '/class/uploader.php';
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
require_once XOOPS_ROOT_PATH . '/kernel/object.php';
/**
* Video class.
* $this class is responsible for providing data access mechanisms to the data source
* of XOOPS user class objects.
*/
class Video extends XoopsObject
{
public $db;
public $helper;
public $permHelper;
// constructor
/**
* Video constructor.
* @param null $id
*/
public function __construct($id = null)
{
/** @var Helper $helper */
$this->helper = Helper::getInstance();
$this->permHelper = new Permission();
$this->db = XoopsDatabaseFactory::getDatabaseConnection();
$this->initVar('video_id', \XOBJ_DTYPE_INT, null, false, 10);
$this->initVar('uid_owner', \XOBJ_DTYPE_INT, null, false, 10);
$this->initVar('video_title', \XOBJ_DTYPE_OTHER, null, false);
$this->initVar('video_desc', \XOBJ_DTYPE_OTHER, null, false);
$this->initVar('youtube_code', \XOBJ_DTYPE_TXTBOX, null, false);
$this->initVar('featured_video', \XOBJ_DTYPE_TXTBOX, null, false);
$this->initVar('date_created', \XOBJ_DTYPE_INT);
$this->initVar('date_updated', \XOBJ_DTYPE_INT);
if (!empty($id)) {
if (\is_array($id)) {
$this->assignVars($id);
} else {
$this->load((int)$id);
}
} else {
$this->setNew();
}
}
/**
* @param $id
*/
public function load($id)
{
$sql = 'SELECT * FROM ' . $this->db->prefix('suico_videos') . ' WHERE video_id=' . $id;
$myrow = $this->db->fetchArray($this->db->query($sql));
$this->assignVars($myrow);
if (!$myrow) {
$this->setNew();
}
}
/**
* @param array $criteria
* @param bool $asobject
* @param string $sort
* @param string $order
* @param int $limit
* @param int $start
* @return array
*/
public function getAllVideos(
$criteria = [],
$asobject = false,
$sort = 'video_id',
$order = 'DESC',
$limit = 0,
$start = 0
) {
$db = XoopsDatabaseFactory::getDatabaseConnection();
$ret = [];
$whereQuery = '';
if (\is_array($criteria) && \count($criteria) > 0) {
$whereQuery = ' WHERE';
foreach ($criteria as $c) {
$whereQuery .= " ${c} AND";
}
$whereQuery = mb_substr($whereQuery, 0, -4);
} elseif (!\is_array($criteria) && $criteria) {
$whereQuery = ' WHERE ' . $criteria;
}
if (!$asobject) {
$sql = 'SELECT video_id FROM ' . $db->prefix('suico_videos') . "${whereQuery} ORDER BY ${sort} ${order}";
$result = $db->query($sql, $limit, $start);
while (false !== ($myrow = $db->fetchArray($result))) {
$ret[] = $myrow['suico_video_id'];
}
} else {
$sql = 'SELECT * FROM ' . $db->prefix('suico_videos') . "${whereQuery} ORDER BY ${sort} ${order}";
$result = $db->query($sql, $limit, $start);
while (false !== ($myrow = $db->fetchArray($result))) {
$ret[] = new self($myrow);
}
}
return $ret;
}
/**
* Get form
*
* @return \XoopsModules\Suico\Form\VideoForm
*/
public function getForm()
{
return new Form\VideoForm($this);
}
/**
* @return array|null
*/
public function getGroupsRead()
{
//$permHelper = new \Xmf\Module\Helper\Permission();
return $this->permHelper->getGroupsForItem(
'sbcolumns_read',
$this->getVar('video_id')
);
}
/**
* @return array|null
*/
public function getGroupsSubmit()
{
//$permHelper = new \Xmf\Module\Helper\Permission();
return $this->permHelper->getGroupsForItem(
'sbcolumns_submit',
$this->getVar('video_id')
);
}
/**
* @return array|null
*/
public function getGroupsModeration()
{
//$permHelper = new \Xmf\Module\Helper\Permission();
return $this->permHelper->getGroupsForItem(
'sbcolumns_moderation',
$this->getVar('video_id')
);
}
}