Skip to content

Issues-670: Updated email message for Client Manager #114

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 3 commits into from
Jan 27, 2022
Merged
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
97 changes: 78 additions & 19 deletions Topcoder/class.topcoder.plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2397,27 +2397,86 @@ public function activityModel_BeforeCheckPreference_handler($sender, $args) {
$data = $activity['Data'];
$challengeID = $data['ChallengeID'];
if($challengeID) {
$resources = $this->getChallengeResources($challengeID);
$roleResources = $this->getRoleResources();
$currentProjectRoles = $this->getTopcoderProjectRoles($user, $resources, $roleResources);
if($currentProjectRoles) {
$currentProjectRoles = array_map('strtolower',$currentProjectRoles);
$isClientManager = count(array_intersect($currentProjectRoles, ["client manager"])) > 0;
if($isClientManager) {
$activity['Data']['EmailUrl'] = val('EmbedUrl',$data);
$activity['Data']['EmailTemplate'] = 'email-selfservice';
$category = CategoryModel::categories($challengeID);
$categoryName = val('Name', $category);
$headline = 'Message From a Topcoder Member on Your Work - Please See';
$activity['HeadlineFormat'] = $headline;
$activity['Headline'] = $headline;
$activity['Story']= sprintf('A new message has been posted on your work forum tied to your Topcoder Work "%s". You can read the full message below.<br/>
To answer, click "Open Discussion" below to be taken to this discussion.<br/>
$activityType = $activity['RecordType'];
if($activityType == 'Discussion' || $activityType == 'Comment') {
$resources = $this->getChallengeResources($challengeID);
$roleResources = $this->getRoleResources();
$currentProjectRoles = $this->getTopcoderProjectRoles($user, $resources, $roleResources);
if($currentProjectRoles) {
$currentProjectRoles = array_map('strtolower', $currentProjectRoles);
$isClientManager = count(array_intersect($currentProjectRoles, ["client manager"])) > 0;
if ($isClientManager) {
$recordID = $activity['RecordID'];
$category = CategoryModel::categories($challengeID);
$categoryName = val('Name', $category);
$userModel = new UserModel();
$discussionModel = new DiscussionModel();
if ($activityType == 'Discussion') {
$discussion = $discussionModel->getID($recordID);
$message = Gdn::formatService()->renderQuote(val('Body', $discussion), val('Format', $discussion));
$author = $userModel->getID(val('InsertUserID', $discussion));
$dateInserted = Gdn_Format::dateFull(val('DateInserted',$discussion));
// $categoryBreadcrumbs = array_column(array_values(CategoryModel::getAncestors(val('CategoryID',$discussion))), 'Name');

$activity['Story'] =
'<p>A new message has been posted on your work forum tied to your Topcoder Work "' . $categoryName . '" ' .
'which was updated ' . $dateInserted . ' by ' . $author->Name . ':<p/>' .
'<hr/>' .
'<div style="padding: 0; margin: 0">' .
'<p><span>Discussion: ' . val('Name', $discussion) . '</p>' .
'<p><span>Author: ' . val('Name', $author) . '</p>' .
// '<p><span>Category: ' . implode('›', $categoryBreadcrumbs) . '</p>' .
'<p><span>Message:</span> ' . $message . '</p>' .
'<hr/>'.
'<p>To answer, click "Open Discussion" below to be taken to this discussion.<br/>
Please do not reply to this email.<br/>
Thank you!
The Topcoder Team</p>' .
'</div>' .
'<hr/>';

} else { // Comment
$commentModel = new CommentModel();
$comment = $commentModel->getID($recordID);
// $discussion = $discussionModel->getID(val('DiscussionID', $comment));
// $discussionName = val('Name',$discussion);
$commentDateInserted = Gdn_Format::dateFull(val('DateInserted',$comment));
$commentAuthor = $userModel->getID(val('InsertUserID',$comment));
$commentStory = Gdn::formatService()->renderQuote(val('Body',$comment), val('Format',$comment));
$activity['Story'] =
'<p>A new message has been posted on your work forum tied to your Topcoder Work "' . $categoryName . '" ' .
'which was updated ' . $commentDateInserted . ' by ' . val('Name',$commentAuthor) . ':</p>' .
'<hr/>' .
'<p class="label"><span style="display: block">Message:</span>'.'</p>' .
$commentStory .
'<br/><hr/>';

$parentCommentID = (int)val('ParentCommentID',$comment);
if($parentCommentID > 0) {
$parentComment = $commentModel->getID($parentCommentID, DATASET_TYPE_ARRAY);
$parentCommentAuthor = $userModel->getID($parentComment['InsertUserID']);
$parentCommentStory = condense(Gdn_Format::to($parentComment['Body'], $parentComment['Format']));
$activity['Story'] .=
'<p class="label">Original Message (by '.$parentCommentAuthor->Name.' ):</p>'.
'<p>' .
$parentCommentStory.
'</p>' .
'<hr/>';
}
$activity['Story'] .= '<p>To answer, click "Open Discussion" below to be taken to this discussion.<br/>
Please do not reply to this email.<br/>
Thank you!
The Topcoder Team', $categoryName);
return;
}
The Topcoder Team</p>';
}

$headline = 'Message From a Topcoder Member on Your Work - Please See';
$activity['HeadlineFormat'] = $headline;
$activity['Headline'] = $headline;
$activity['Data']['EmailUrl'] = val('EmbedUrl', $data);
$activity['Data']['EmailTemplate'] = 'email-selfservice';
return;
}
}
}
}
$activity['Data']['EmailUrl'] = externalUrl(val('Route', $activity) == '' ? '/' : val('Route', $activity));
Expand Down