Skip to content

Commit

Permalink
#4929: Fix type mismatch in usage of e107forum::getForumClassMembers()
Browse files Browse the repository at this point in the history
Also, `e107forum::getForumClassMembers()` is now documented and
deprecated because it has unintuitive return values.

Fixes: #4929
  • Loading branch information
Deltik committed Dec 25, 2022
1 parent ec68c88 commit 566cde0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
16 changes: 16 additions & 0 deletions e107_plugins/forum/forum_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ function getForumSef($threadInfo)

}

/**
* Get an array of the first alphabetical 50 usernames, user IDs, and the users' serialized user classes that match
* the forum's allowed viewers or a user class ID if the allowed viewers is a special user class except if the
* special user class is {@see e_UC_MAINADMIN} or {@see false} if the previous two possibilities are not encountered
*
* @deprecated v2.3.3 Due to the confusing usage, consider writing another method to get the list of members that
* can see the forum identified by its forum ID.
* @param $forumId int The ID from `e107_forum`.`forum_id`
* @param $type string Can only be "view"
* @return array|int|false When an array, the first 50 users, sorted alphabetically by username, that can view this
* forum, along with their user ID, username, and serialized user classes.
* When an int, the special user class ID as defined in {@see e107::set_constants()} except
* {@see e_UC_MAINADMIN}.
* When boolean false, this is an unhandled case probably due to the
* `e107_forum`.`forum_class` column missing from the table.
*/
function getForumClassMembers($forumId, $type='view')
{

Expand Down
19 changes: 8 additions & 11 deletions e107_plugins/forum/shortcodes/batch/viewforum_shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,29 +239,26 @@ function sc_viewable_by()
{
global $forum, $forumId;

if($users = $forum->getForumClassMembers($forumId))
if($usersOrUserClassId = $forum->getForumClassMembers($forumId))
{
$userList = array();
$viewable = e107::getUserClass()->getFixedClassDescription($users);
if(is_array($users))
if(is_array($usersOrUserClassId))
{
foreach($users as $user)
foreach($usersOrUserClassId as $user)
{
$userList[] = "<a href='" . e107::getUrl()->create('user/profile/view', $user) . "'>" . $user['user_name'] . "</a>";
}

$viewable = implode(', ', $userList);;
}
elseif($users == 0)
elseif($usersOrUserClassId == 0)
{
$viewable = '';
}
/*--
else
{
$viewable = e107::getUserClass()->getFixedClassDescription($users);
}
--*/
else
{
$viewable = e107::getUserClass()->getFixedClassDescription($usersOrUserClassId);
}
}

/*--
Expand Down

0 comments on commit 566cde0

Please sign in to comment.