mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Enhance channel management: add user group filtering to channel retrieval and display user groups in sidebar
This commit is contained in:
parent
cfe02b0a76
commit
0b28225740
6 changed files with 384 additions and 297 deletions
|
@ -346,6 +346,7 @@ Options All -Indexes
|
||||||
RewriteRule ^channel/([^/]+) view/channel.php?channelName=$1 [QSA]
|
RewriteRule ^channel/([^/]+) view/channel.php?channelName=$1 [QSA]
|
||||||
RewriteRule ^channel/?$ view/channel.php [QSA]
|
RewriteRule ^channel/?$ view/channel.php [QSA]
|
||||||
RewriteRule ^channels/?$ view/channels.php [NC,L]
|
RewriteRule ^channels/?$ view/channels.php [NC,L]
|
||||||
|
RewriteRule ^channels/([0-9]+)/?$ view/channels.php?user_groups_id=$1 [QSA]
|
||||||
|
|
||||||
|
|
||||||
# 1. Trending videos
|
# 1. Trending videos
|
||||||
|
|
|
@ -9,7 +9,7 @@ require_once $global['systemRootPath'] . 'objects/user.php';
|
||||||
|
|
||||||
class Channel
|
class Channel
|
||||||
{
|
{
|
||||||
public static function getChannels($activeOnly = true, $FIND_IN_SET = "", $users_id_array = array())
|
public static function getChannels($activeOnly = true, $FIND_IN_SET = "", $users_id_array = array(), $user_groups_id = null)
|
||||||
{
|
{
|
||||||
global $global;
|
global $global;
|
||||||
/**
|
/**
|
||||||
|
@ -29,6 +29,13 @@ class Channel
|
||||||
if(!empty($users_id_array) && is_array($users_id_array)){
|
if(!empty($users_id_array) && is_array($users_id_array)){
|
||||||
$sql .= " AND u.id IN(".implode(',',$users_id_array ).") ";
|
$sql .= " AND u.id IN(".implode(',',$users_id_array ).") ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add user group filter if specified
|
||||||
|
if (!empty($user_groups_id)) {
|
||||||
|
$user_groups_id = intval($user_groups_id);
|
||||||
|
$sql .= " AND u.id IN (SELECT users_id FROM users_has_users_groups WHERE users_groups_id = {$user_groups_id}) ";
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= BootGrid::getSqlFromPost(['user', 'about', 'channelName', 'u.name', 'u.email'], "", "", false, $FIND_IN_SET);
|
$sql .= BootGrid::getSqlFromPost(['user', 'about', 'channelName', 'u.name', 'u.email'], "", "", false, $FIND_IN_SET);
|
||||||
//var_dump($sql);exit;
|
//var_dump($sql);exit;
|
||||||
$res = sqlDAL::readSql($sql);
|
$res = sqlDAL::readSql($sql);
|
||||||
|
@ -48,15 +55,23 @@ class Channel
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static function getTotalChannels($activeOnly=true)
|
public static function getTotalChannels($activeOnly=true, $user_groups_id = null)
|
||||||
{
|
{
|
||||||
global $global;
|
global $global;
|
||||||
|
|
||||||
$sql = "SELECT count(*) as total "
|
$sql = "SELECT count(*) as total "
|
||||||
. " FROM users u "
|
. " FROM users u "
|
||||||
. " WHERE (SELECT count(v.id) FROM videos v where v.users_id = u.id) > 0 ";
|
. " WHERE (SELECT count(v.id) FROM videos v where v.users_id = u.id) > 0 ";
|
||||||
if ($activeOnly) {
|
if ($activeOnly) {
|
||||||
$sql .= " AND u.status = 'a' ";
|
$sql .= " AND u.status = 'a' ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add user group filter if specified
|
||||||
|
if (!empty($user_groups_id)) {
|
||||||
|
$user_groups_id = intval($user_groups_id);
|
||||||
|
$sql .= " AND u.id IN (SELECT users_id FROM users_has_users_groups WHERE users_groups_id = {$user_groups_id}) ";
|
||||||
|
}
|
||||||
|
|
||||||
$sql .= BootGrid::getSqlSearchFromPost(['user', 'about']);
|
$sql .= BootGrid::getSqlSearchFromPost(['user', 'about']);
|
||||||
//$sql .= BootGrid::getSqlFromPost(['user', 'about']);
|
//$sql .= BootGrid::getSqlFromPost(['user', 'about']);
|
||||||
$res = sqlDAL::readSql($sql);
|
$res = sqlDAL::readSql($sql);
|
||||||
|
@ -64,4 +79,38 @@ class Channel
|
||||||
sqlDAL::close($res);
|
sqlDAL::close($res);
|
||||||
return $res ? intval($data['total']) : 0;
|
return $res ? intval($data['total']) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getUserGroupsWithChannels($activeOnly = true)
|
||||||
|
{
|
||||||
|
global $global;
|
||||||
|
|
||||||
|
$sql = "SELECT DISTINCT ug.id, ug.group_name, COUNT(DISTINCT u.id) as total_channels "
|
||||||
|
. " FROM users_groups ug "
|
||||||
|
. " INNER JOIN users_has_users_groups uhug ON ug.id = uhug.users_groups_id "
|
||||||
|
. " INNER JOIN users u ON uhug.users_id = u.id "
|
||||||
|
. " WHERE (SELECT count(v.id) FROM videos v WHERE v.users_id = u.id) > 0 ";
|
||||||
|
|
||||||
|
if ($activeOnly) {
|
||||||
|
$sql .= " AND u.status = 'a' ";
|
||||||
|
}
|
||||||
|
|
||||||
|
$sql .= " GROUP BY ug.id, ug.group_name "
|
||||||
|
. " ORDER BY ug.group_name ASC ";
|
||||||
|
|
||||||
|
$res = sqlDAL::readSql($sql);
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
if ($res !== false) {
|
||||||
|
$fullResult = sqlDAL::fetchAllAssoc($res);
|
||||||
|
foreach ($fullResult as $row) {
|
||||||
|
$row = cleanUpRowFromDatabase($row);
|
||||||
|
$result[] = $row;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
die($sql . '\nError : (' . $global['mysqli']->errno . ') ' . $global['mysqli']->error);
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlDAL::close($res);
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,6 +280,7 @@ class CustomizeAdvanced extends PluginAbstract {
|
||||||
|
|
||||||
$obj->disableAnimatedGif = false;
|
$obj->disableAnimatedGif = false;
|
||||||
$obj->removeBrowserChannelLinkFromMenu = false;
|
$obj->removeBrowserChannelLinkFromMenu = false;
|
||||||
|
$obj->removeBrowserChannelPerGroupLinkFromMenu = true;
|
||||||
$obj->EnableMinifyJS = false;
|
$obj->EnableMinifyJS = false;
|
||||||
$obj->disableShareAndPlaylist = false;
|
$obj->disableShareAndPlaylist = false;
|
||||||
$obj->disableShareOnly = false;
|
$obj->disableShareOnly = false;
|
||||||
|
|
|
@ -15,12 +15,21 @@ if (isset($_SESSION['channelName'])) {
|
||||||
unset($_SESSION['channelName']);
|
unset($_SESSION['channelName']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$totalChannels = Channel::getTotalChannels();
|
$user_groups_id = intval(@$_REQUEST['user_groups_id']);
|
||||||
|
|
||||||
|
// Get user group name if user_groups_id is provided
|
||||||
|
$userGroupName = '';
|
||||||
|
if (!empty($user_groups_id)) {
|
||||||
|
$userGroup = new UserGroups($user_groups_id);
|
||||||
|
$userGroupName = $userGroup->getGroup_name();
|
||||||
|
}
|
||||||
|
|
||||||
|
$totalChannels = Channel::getTotalChannels(true, $user_groups_id);
|
||||||
|
|
||||||
$users_id_array = VideoStatistic::getUsersIDFromChannelsWithMoreViews();
|
$users_id_array = VideoStatistic::getUsersIDFromChannelsWithMoreViews();
|
||||||
|
|
||||||
$_REQUEST['rowCount'] = 10;
|
$_REQUEST['rowCount'] = 10;
|
||||||
$channels = Channel::getChannels(true, "u.id, '" . implode(",", $users_id_array) . "'");
|
$channels = Channel::getChannels(true, "u.id, '" . implode(",", $users_id_array) . "'", [], $user_groups_id);
|
||||||
|
|
||||||
$totalPages = ceil($totalChannels / $_REQUEST['rowCount']);
|
$totalPages = ceil($totalChannels / $_REQUEST['rowCount']);
|
||||||
//var_dump($channels, $totalPages, $totalChannels, $_REQUEST['rowCount']);exit;
|
//var_dump($channels, $totalPages, $totalChannels, $_REQUEST['rowCount']);exit;
|
||||||
|
@ -67,11 +76,17 @@ $_page->setExtraStyles(
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">
|
<div class="panel-heading">
|
||||||
|
<?php if (!empty($user_groups_id) && !empty($userGroupName)): ?>
|
||||||
|
<h3 class="panel-title" style="margin-bottom: 10px;">
|
||||||
|
<i class="fa fa-users"></i> <strong><?php echo htmlspecialchars($userGroupName); ?></strong>
|
||||||
|
</h3>
|
||||||
|
<?php endif; ?>
|
||||||
<form id="search-form" name="search-form" action="<?php echo $global['webSiteRootURL']; ?>channels" method="get">
|
<form id="search-form" name="search-form" action="<?php echo $global['webSiteRootURL']; ?>channels" method="get">
|
||||||
<div id="custom-search-input">
|
<div id="custom-search-input">
|
||||||
<div class="input-group col-md-12">
|
<div class="input-group col-md-12">
|
||||||
<input type="search" name="searchPhrase" class="form-control input-lg" placeholder="<?php echo __("Search Channels"); ?>"
|
<input type="search" name="searchPhrase" class="form-control input-lg" placeholder="<?php echo __("Search Channels"); ?>"
|
||||||
value="<?php echo @htmlentities(@$_GET['searchPhrase']); unsetSearch(); ?>" />
|
value="<?php echo @htmlentities(@$_GET['searchPhrase']); unsetSearch(); ?>" />
|
||||||
|
<input type="hidden" name="user_groups_id" value="<?php echo $user_groups_id; ?>" />
|
||||||
<span class="input-group-btn">
|
<span class="input-group-btn">
|
||||||
<button class="btn btn-info btn-lg" type="submit">
|
<button class="btn btn-info btn-lg" type="submit">
|
||||||
<i class="glyphicon glyphicon-search"></i>
|
<i class="glyphicon glyphicon-search"></i>
|
||||||
|
@ -87,7 +102,7 @@ $_page->setExtraStyles(
|
||||||
User::getChannelPanel($value['id']);
|
User::getChannelPanel($value['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
echo getPagination($totalPages, "{$global['webSiteRootURL']}channels?page=_pageNum_");
|
echo getPagination($totalPages, "{$global['webSiteRootURL']}channels?user_groups_id={$user_groups_id}&page=_pageNum_");
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -539,12 +539,28 @@ $tToleranceSide = 0.2;
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
||||||
|
|
||||||
|
if (empty($advancedCustom->removeBrowserChannelPerGroupLinkFromMenu)) {
|
||||||
|
$userGroupsWithChannels = Channel::getUserGroupsWithChannels();
|
||||||
|
if (!empty($userGroupsWithChannels)) {
|
||||||
|
foreach ($userGroupsWithChannels as $group) {
|
||||||
?>
|
?>
|
||||||
|
<li>
|
||||||
|
<a href="#" onclick="avideoModalIframeFull(webSiteRootURL + 'channels/<?php echo $group['id']; ?>'); return false;">
|
||||||
|
<i class="fa fa-users"></i>
|
||||||
|
<span class="menuLabel">
|
||||||
|
<?php echo htmlspecialchars($group['group_name']); ?>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<?php
|
<?php
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($avideoLayout->categoriesTopLeftMenu)) {
|
if (!empty($avideoLayout->categoriesTopLeftMenu)) {
|
||||||
?>
|
?>
|
||||||
<li>
|
<li>
|
||||||
|
@ -583,7 +599,7 @@ $tToleranceSide = 0.2;
|
||||||
|
|
||||||
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
||||||
$categories = Category::getAllCategories(false, true, $advancedCustom->CategoryShowOnlySuggested, $sameUserGroupAsMe, true);
|
$categories = Category::getAllCategories(false, true, $advancedCustom->CategoryShowOnlySuggested, $sameUserGroupAsMe, true);
|
||||||
if(empty($categories)){
|
if (empty($categories)) {
|
||||||
$categories = array();
|
$categories = array();
|
||||||
}
|
}
|
||||||
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
TimeLogEnd($tnameSide, __LINE__, $tToleranceSide);
|
||||||
|
|
|
@ -106,7 +106,8 @@
|
||||||
"commands": function(column, row) {
|
"commands": function(column, row) {
|
||||||
var editBtn = '<button type="button" class="btn btn-xs btn-default command-edit" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="<?php echo __('Edit'); ?>"><i class="fa-solid fa-pen-to-square"></i></button>'
|
var editBtn = '<button type="button" class="btn btn-xs btn-default command-edit" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="<?php echo __('Edit'); ?>"><i class="fa-solid fa-pen-to-square"></i></button>'
|
||||||
var deleteBtn = '<button type="button" class="btn btn-default btn-xs command-delete" data-row-id="' + row.id + ' data-toggle="tooltip" data-placement="left" title="<?php echo __('Delete'); ?>""><i class="fa fa-trash"></i></button>';
|
var deleteBtn = '<button type="button" class="btn btn-default btn-xs command-delete" data-row-id="' + row.id + ' data-toggle="tooltip" data-placement="left" title="<?php echo __('Delete'); ?>""><i class="fa fa-trash"></i></button>';
|
||||||
return editBtn + deleteBtn;
|
var channelsBtn = '<button type="button" class="btn btn-xs btn-default command-channels" data-row-id="' + row.id + '" data-toggle="tooltip" data-placement="left" title="<?php echo __('View Channels'); ?>"><i class="fa fa-tv"></i></button>';
|
||||||
|
return editBtn + deleteBtn + channelsBtn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).on("loaded.rs.jquery.bootgrid", function() {
|
}).on("loaded.rs.jquery.bootgrid", function() {
|
||||||
|
@ -178,6 +179,10 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}).end().find(".command-channels").on("click", function(e) {
|
||||||
|
var row_index = $(this).closest('tr').index();
|
||||||
|
var row = $("#grid").bootgrid("getCurrentRows")[row_index];
|
||||||
|
window.open(webSiteRootURL + 'channels/' + row.id, '_blank');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue