Skip to content

v1.6 #83

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 8 commits into from
Apr 18, 2021
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
4 changes: 2 additions & 2 deletions views/group/add_category.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php if (!defined('APPLICATION')) exit(); ?>
<h1><?php echo t('Add New Category'); ?></h1>
<h1><?php echo t('Add'); ?></h1>
<?php
$Group = $this->data('Group');
echo $this->Form->open();
echo $this->Form->errors();
?>
<div class="Wrap">
<?php
echo '<div class="P">Are you sure you want to add a new category to \''. $Group->Name.'\'?</div>';
echo '<div class="P Message">Are you sure you want to add a new category?</div>';
echo '<div class="P">';
echo $this->Form->label('Category Name', 'Name');
echo wrap($this->Form->textBox('Name', ['maxlength' => 255, 'class' => 'InputBox']), 'div', ['class' => 'TextBoxWrapper']);
Expand Down
6 changes: 3 additions & 3 deletions views/group/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
$Group = $this->data('Group');
?>
<h1><?php echo 'Delete \''.$Group->Name.'\'' ?></h1>
<h1><?php echo 'Delete' ?></h1>
<?php
echo $this->Form->open();
echo $this->Form->errors();
Expand All @@ -11,10 +11,10 @@
<div class="Wrap">

<?php
echo '<div class="P">Are you sure you want to delete \''. $Group->Name.'\'?</div>';
echo '<div class="P Message">Are you sure you want to delete this item?</div>';
echo '<div class="Buttons Buttons-Confirm">';
echo $this->Form->button('Cancel', ['type' => 'button', 'class' => 'Button Close']);
echo $this->Form->button( 'Delete', ['class' => 'Button Primary GroupButton']);
echo $this->Form->button( 'Delete', ['class' => 'Button Primary Delete']);
echo '</div>';
?>
</div>
6 changes: 3 additions & 3 deletions views/group/delete_member.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<?php if (!defined('APPLICATION')) exit(); ?>
<h1><?php echo t('Delete Member'); ?></h1>
<h1><?php echo t('Delete'); ?></h1>
<?php
echo $this->Form->open();
echo $this->Form->errors();
?>
<div class="Wrap">
<div class="P">Are you sure you want to delete this member?</div>
<div class="P">Are you sure you want to delete this item?</div>
<?php
echo '<div class="Buttons Buttons-Confirm">';
echo $this->Form->button( 'Delete', ['class' => 'Button Primary GroupButton']);
echo $this->Form->button('Cancel', ['type' => 'button', 'class' => 'Button Close']);
echo $this->Form->button( 'Delete', ['class' => 'Button Primary Delete']);
echo '</div>';

?>
Expand Down
96 changes: 60 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,72 @@ function writeGroupHeader($group, $showDetails = false, $owner = null, $leaders
<?php echo writeGroupIcon($group, '', 'Group-Icon Group-Icon-Big');?>
</div>
<?php }?>
<?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>
<?php if(!$group->Archived) { ?>
<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>
<?php } else {?>
<div class="Group-Archived"><?php
$challengeAnchor = $group->ChallengeUrl? anchor('challenge', $group->ChallengeUrl,'', ['target' => 'blank']):'challenge';
echo '<span class="Archived">Archived</span><span>This '.$challengeAnchor.' forum has been archived.</span> ';
?>
</div>
<?php } ?>
</div>
</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-Footer">
<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="MItem TableRow">
<div class="TableCell Cell1">Privacy</div>
<div class="TableCell Cell2"><?php echo $group->Privacy; ?></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 Last">
<div class="TableCell Cell1">Archived</div>
<div class="TableCell Cell2"><?php echo $group->Archived == 1? 'yes': 'no'; ?></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="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);?>

6 changes: 3 additions & 3 deletions views/group/invite.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php if (!defined('APPLICATION')) exit(); ?>
<h1><?php echo t('Invite User'); ?></h1>
<h1><?php echo t('Invite'); ?></h1>
<?php
$Group = $this->data('Group');
echo $this->Form->open();
echo $this->Form->errors();
?>
<div class="Wrap">
<?php
echo '<div class="P">Are you sure you want to invite User to \''. $Group->Name.'\'?</div>';
echo '<div class="P Message">Are you sure you want to invite User?</div>';
echo '<div class="P">';
echo $this->Form->label('Username', 'Username');
echo wrap($this->Form->textBox('Username', ['maxlength' => 100, 'class' => 'InputBox BigInput']), 'div', ['class' => 'TextBoxWrapper']);
echo '</div>';
echo '<div class="Buttons Buttons-Confirm">';
echo $this->Form->button('Cancel', ['type' => 'button', 'class' => 'Button Close']);
echo $this->Form->button( 'Invite', ['class' => 'Button Primary GroupButton']);
echo $this->Form->button( 'Invite User', ['class' => 'Button Primary']);
echo '</div>';

?>
Expand Down
9 changes: 8 additions & 1 deletion views/groups/helper_functions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php if (!defined('APPLICATION')) exit();
<?php use Vanilla\Formatting\Formats\MarkdownFormat;

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

if (!function_exists('getGroupUrl')) :
function getGroupUrl($group) {
Expand Down Expand Up @@ -71,7 +73,12 @@ function writeGroup($group, $sender, $session) {
$cssClass = cssClass($group);
$groupUrl = getGroupUrl($group);
$groupName = $group->Name;
$isMarkdownFormatter = strcasecmp(Gdn_Format::defaultFormat(), MarkdownFormat::FORMAT_KEY) === 0;
$groupDesc = $group->Description;
if($isMarkdownFormatter) {
$groupDesc = Gdn_Format::to($groupDesc, MarkdownFormat::FORMAT_KEY);
$groupDesc = preg_replace('/<br\\s*?\/??>/i', "", $groupDesc);
}
$wrapCssClass = $group->Icon ? 'hasPhotoWrap':'noPhotoWrap';
?>
<li id="Group_<?php echo $group->GroupID; ?>" class="<?php echo $cssClass.' '.$wrapCssClass; ?> ">
Expand Down