Skip to content

Issues-561: Updated Group header and attributes #79

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions class.groups.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -781,15 +781,16 @@ public function base_userAnchor_handler($sender, $args){
if($sender instanceof DiscussionController || $sender instanceof GroupController || $sender instanceof PostController) {
$user = $args['User'];
$isTopcoderAdmin = $args['IsTopcoderAdmin'];
$hideRoles = isset($args['HideRoles'])? $args['HideRoles']: false;
$anchorText = &$args['Text'];
$resources = $sender->data('ChallengeResources');
$roleResources = $sender->data('ChallengeRoleResources');
$anchorText = '<span class="topcoderHandle">'.$anchorText.'</span>';
// Don't show Topcoder Challenge roles for admin roles
if(!$isTopcoderAdmin){
$roles = $this->topcoderProjectRolesText($user, $resources, $roleResources);
if($roles) {
$anchorText = $anchorText . '&nbsp;<span class="challengeRoles">('.$roles. ')</span>';
if(!$isTopcoderAdmin && !$hideRoles) {
$roles = $this->topcoderProjectRolesText($user, $resources, $roleResources);
if ($roles) {
$anchorText = $anchorText . '&nbsp;<span class="challengeRoles">(' . $roles . ')</span>';
}
}
}
Expand Down
36 changes: 28 additions & 8 deletions controllers/class.groupcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,10 @@ public function index($GroupID = '') {
$this->title($Group->Name);

$this->setData('Breadcrumbs', $this->buildBreadcrumb($Group));
// $this->setData('CurrentUserGroups', GroupModel::memberOf(Gdn::session()->UserID));
$this->setData('TotalMembers', $this->GroupModel->countOfMembers($GroupID));
$this->setData('Leaders', $this->GroupModel->getLeaders($GroupID));
$this->setData('Members', $this->GroupModel->getMembers($GroupID,[],'',30,0));

$roleResources = $this->data('ChallengeRoleResources');
$resources = $this->data('ChallengeResources');
$copilots = $this->getCopilots($resources, $roleResources);
$this->setData('Copilots', $copilots);
$groupDiscussions = $this->GroupModel->getGroupDiscussionCategories($Group);
$defaultDiscussionUrl = '/post/discussion/';
if($Group->Type == GroupModel::TYPE_REGULAR) {
Expand Down Expand Up @@ -128,6 +127,25 @@ public function index($GroupID = '') {
$this->render();
}

private function getCopilots($resources = null, $roleResources = null) {
$copilots = [];
$roleName = 'copilot';
if (isset($resources) && isset($roleResources)) {
$copilotRoleResources = array_filter($roleResources, function ($k) use ($roleName) {
return $roleName == strtolower($k->name);
});

$copilotRoleResource = reset($copilotRoleResources);
$memberResources = array_filter($resources, function ($k) use ($copilotRoleResource) {
return $k->roleId == $copilotRoleResource->id;
});
foreach ($memberResources as $memberResourceId => $memberResource) {
array_push($copilots, $memberResource->memberHandle);
}
}
return array_unique($copilots);
}

/**
* Create new group.
*
Expand Down Expand Up @@ -252,11 +270,12 @@ public function edit($groupID = false) {


/**
* Create new group.
* The list of members
*
* @since 2.0.0
* @access public
*/
// FIX: https://github.com/topcoder-platform/forums/issues/561
// Hide members endpoint and view
/*
public function members($GroupID = '',$Page = false) {

$this->allowJSONP(true);
Expand Down Expand Up @@ -317,6 +336,7 @@ public function members($GroupID = '',$Page = false) {

$this->render();
}
*/

/**
* Remove a member from a group
Expand Down
91 changes: 55 additions & 36 deletions views/group/helper_functions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php if (!defined('APPLICATION')) exit();
<?php use Vanilla\Formatting\DateTimeFormatter;
use Vanilla\Formatting\Formats\MarkdownFormat;

if (!defined('APPLICATION')) exit();

if (!function_exists('allMembersUrl')) {
/**
Expand Down Expand Up @@ -243,51 +246,67 @@ function writeGroupHeader($group, $showDetails = false, $owner = null, $leaders
<?php echo writeGroupIcon($group, '', 'Group-Icon Group-Icon-Big');?>
</div>
<?php }?>
<?php if($showDetails) { ?>
<?php if($showDetails) { ?>
<div class="Group-Info">
<div class="Group-Description"><?php echo $group->Description; ?></div>
<div class="Meta Group-Meta Table">
<?php if($group->ChallengeUrl) { ?>
<div class="MItem TableRow">
<div class="TableCell Cell1">Challenge</div>
<div class="TableCell Cell2"><?php echo anchor($group->Name, $group->ChallengeUrl);?></div>
</div>
<?php } ?>
<div class="MItem TableRow">
<div class="TableCell Cell1">Owner</div>
<div class="TableCell Cell2"><?php echo userAnchor($owner, 'Username');?></div>
</div>
<div class="MItem TableRow">
<div class="TableCell Cell1">Leaders</div>
<div class="TableCell Cell2">
<?php echo writeGroupMembers($leaders, ','); ?>
</div>
</div>
<div class="MItem TableRow">
<div class="TableCell Cell1">Member(s)</div>
<div class="TableCell Cell2"><?php echo $totalMembers; ?></div>
</div>
<div class="Group-Description"><?php
$isMarkdownFormatter = strcasecmp(Gdn_Format::defaultFormat(), MarkdownFormat::FORMAT_KEY) === 0;

$text = $isMarkdownFormatter? Gdn_Format::to($group->Description, MarkdownFormat::FORMAT_KEY):
$group->Description;
echo $text ;
?></div>
</div>
<?php }?>
</div>

<div class="MItem TableRow">
<div class="TableCell Cell1">Created on</div>
<div class="TableCell Cell2"><?php echo $group->DateInserted; ?></div>
<?php
}
}
if (!function_exists('writeGroupMetaData')) {
function writeGroupMetaData($group, $owner = null, $copilots=null) {
?>
<div class="Group-Header">
<div class="Group-Info">
<div class="Meta Group-Meta Table">
<div class="MItem TableRow">
<div class="TableCell Cell1">
<span class="MLabel">Author</span>
<span class="MValue"><?php echo userAnchor($owner, 'Username');?></span>
</div>
<div class="TableCell Cell2">
<span class="MLabel">Copilot</span>
<span class="MValue">
<?php
$copilotAnchors = [];
foreach ($copilots as $copilot) {
$user = Gdn::userModel()->getByUsername($copilot);
array_push($copilotAnchors, userAnchor($user, null, ['HideRoles'=> true]));
}
echo implode(', ', $copilotAnchors);
?>
</span>
</div>
<div class="MItem TableRow">
<div class="TableCell Cell1">Privacy</div>
<div class="TableCell Cell2"><?php echo $group->Privacy; ?></div>
</div>
<div class="MItem TableRow Last">
<div class="TableCell Cell1">
<span class="MLabel">Privacy</span>
<span class="MValue"><?php echo $group->Privacy; ?></span>
</div>
<div class="MItem TableRow Last">
<div class="TableCell Cell1">Archived</div>
<div class="TableCell Cell2"><?php echo $group->Archived == 1? 'yes': 'no'; ?></div>
<div class="TableCell Cell2">
<span class="MLabel">Date Created</span>
<span class="MValue"><?php
$dateFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($group->DateInserted, false, '%d %B %Y');
$timeFormatted = Gdn::getContainer()->get(DateTimeFormatter::class)->formatDate($group->DateInserted, false, '%I:%M %p');
echo $dateFormatted.', '.$timeFormatted;
?></span>
</div>
</div>
</div>
<?php }?>
</div>

</div>
<?php
}
}
?>



38 changes: 19 additions & 19 deletions views/group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@
$Session = Gdn::session();
$Group = $this->data('Group');
$Owner = Gdn::userModel()->getID($Group->OwnerID);
$Leaders = $this->data('Leaders');
$Members = $this->data('Members');
// $Leaders = $this->data('Leaders');
// $Members = $this->data('Members');
$Copilots = $this->data('Copilots');
$Discussions = $this->data('Discussions');
$Announcements = $this->data('Announcements');
$TotalMembers = $this->data('TotalMembers');
// $TotalMembers = $this->data('TotalMembers');
$bannerCssClass = $Group->Banner ? 'HasBanner':'NoBanner';
$groupModel = new GroupModel();
$currentTopcoderProjectRoles = Gdn::controller()->data('ChallengeCurrentUserProjectRoles');
//$groupModel->setCurrentUserTopcoderProjectRoles($currentTopcoderProjectRoles);

?>
<?php echo writeGroupHeader($Group, true, $Owner, $Leaders, $TotalMembers);?>
<?php echo writeGroupHeader($Group, true, $Owner);?>

<div class="Group-Content">
<div class="Group-Box Group-Announcements Section-DiscussionList">
Expand Down Expand Up @@ -73,20 +74,19 @@
<?php } ?>

</div>
<div class="Group-Info ClearFix clearfix">
<div class="Group-Box Group-MembersPreview">
<div class="PageControls">
<h1 class="Groups H">Members</h1>
</div>
<?php if(count($Members) > 0 ) { ?>
<div class="PhotoGrid PhotoGridSmall">
<?php echo writeGroupMembersWithPhoto($Members); ?>
<?php echo anchor('All Members',allMembersUrl($this->data('Group')), 'MoreWrap');?>
</div>
<?php } else {
echo '<div class="EmptyMessage">There are no members.</div>';
}?>
</div>
</div>
<?php
// echo '<div class="Group-Info ClearFix clearfix"><div class="Group-Box Group-MembersPreview"> <div class="PageControls">'.
// '<h1 class="Groups H">Members</h1></div>';
// if(count($Members) > 0 ) {
// echo '<div class="PhotoGrid PhotoGridSmall">'
// echo writeGroupMembersWithPhoto($Members);
// echo anchor('All Members',allMembersUrl($this->data('Group')), 'MoreWrap');
// echo '</div>'
// } else {
// echo '<div class="EmptyMessage">There are no members.</div>';
// }
// echo '</div></div>';
?>
</div>
<?php echo writeGroupMetaData($Group, $Owner, $Copilots);?>