Skip to content

Commit 60a3b5a

Browse files
authored
Merge pull request #90 from topcoder-platform/develop
Version 1.7
2 parents 7763a05 + 56b411e commit 60a3b5a

9 files changed

+436
-69
lines changed

class.groups.plugin.php

Lines changed: 167 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ public function categoryModel_watch_create(CategoryModel $sender){
533533
public function categoryModel_setCategoryMetaData_create(CategoryModel $sender) {
534534
$categoryIDs = val(0, $sender->EventArguments);
535535
$userID = val(1, $sender->EventArguments);
536-
$watched = val(2, $sender->EventArguments);
536+
$watched = val(2, $sender->EventArguments); // 1, 2- partly watched, null- remove
537537
$userMetaModel = new UserMetaModel();
538538
if(is_numeric($categoryIDs) ) {
539539
$categoryIDs = [$categoryIDs];
@@ -552,7 +552,13 @@ public function categoryModel_setCategoryMetaData_create(CategoryModel $sender)
552552
$userMetaModel = new UserMetaModel();
553553
$userMetaModel->setWatchedCategoriesCount($userID);
554554
Gdn::cache()->remove("UserMeta_{$userID}");
555-
return;// $sender->hasWatched($categoryIDs,$userID);
555+
556+
$discussionModel = new DiscussionModel();
557+
// Don't change bookmark flag in UserDiscussion
558+
if($watched != 2) {
559+
$discussionModel->bookmarkAll($categoryIDs, $userID, $watched == 1 ? 1 : 0);
560+
}
561+
return;
556562
}
557563

558564
/**
@@ -601,6 +607,43 @@ public function categoryModel_hasWatched_create(CategoryModel $sender) {
601607
return false;
602608
}
603609

610+
/**
611+
* Get user notification preferences
612+
*
613+
* @param $userID
614+
* @param $categoryIDs array|int
615+
* @return array The list of categories with all preference keys.
616+
*/
617+
public function categoryModel_getCategoryNotificationPreferences_create(CategoryModel $sender) {
618+
$categoryIDs = val(0, $sender->EventArguments);
619+
$userID = val(1, $sender->EventArguments);
620+
621+
if(is_numeric($categoryIDs) ) {
622+
$categoryIDs = [$categoryIDs];
623+
}
624+
$result = [];
625+
$userMetaModel = new UserMetaModel();
626+
foreach ($categoryIDs as $categoryID) {
627+
// need to cast to int, by default all values are strings
628+
$newEmailDiscussionKey = 'Preferences.Email.NewDiscussion.' . $categoryID;
629+
$newEmailDiscussionValue = $userMetaModel->getUserMeta($userID, $newEmailDiscussionKey, null);
630+
$result[$categoryID][$newEmailDiscussionKey] = $newEmailDiscussionValue[$newEmailDiscussionKey];
631+
632+
$newEmailCommentKey = 'Preferences.Email.NewComment.' . $categoryID;
633+
$newEmailCommentValue = $userMetaModel->getUserMeta($userID, $newEmailCommentKey, null);
634+
$result[$categoryID][$newEmailCommentKey] = $newEmailCommentValue[$newEmailCommentKey];
635+
636+
$newPopupDiscussionKey = 'Preferences.Popup.NewDiscussion.' . $categoryID;
637+
$newPopupDiscussionValue = $userMetaModel->getUserMeta($userID, $newPopupDiscussionKey, null);
638+
$result[$categoryID][$newPopupDiscussionKey] = $newPopupDiscussionValue[$newPopupDiscussionKey];
639+
640+
$newPopupCommentKey = 'Preferences.Popup.NewComment.' . $categoryID;
641+
$newPopupCommentValue = $userMetaModel->getUserMeta($userID, $newPopupCommentKey, null);
642+
$result[$categoryID][$newPopupCommentKey] = $newPopupCommentValue[$newPopupCommentKey];
643+
}
644+
return $result;
645+
}
646+
604647
//
605648
// EMAIL TEMPLATES
606649
//
@@ -892,8 +935,9 @@ public function base_beforeRenderDiscussionFilters_handler($sender, $args){
892935
if ($sender instanceof CategoriesController || $sender instanceof PostController) {
893936
$category = $sender->data('Category');
894937
if($category) {
895-
$groupID = val('GroupID', $category);
896-
if($groupID) {
938+
$categoryID = val('CategoryID', $category);
939+
$isChallengeForums = $sender->checkChallengeForums($categoryID);
940+
if($isChallengeForums) {
897941
$menu['AllCategories']['IsActive'] = false;
898942
return;
899943
}
@@ -923,8 +967,9 @@ private function getMenuItemCssClassFromQuery($sender, $requestMethod){
923967
if ($sender instanceof CategoriesController || $sender instanceof PostController) {
924968
$category = $sender->data('Category');
925969
if($category) {
926-
$groupID = val('GroupID', $category);
927-
if($groupID) {
970+
$categoryID = val('CategoryID', $category);
971+
$isChallengeForums = $sender->checkChallengeForums($categoryID);
972+
if($isChallengeForums) {
928973
$cssClass = ' Active';
929974
}
930975
}
@@ -993,4 +1038,120 @@ function wrapCheckOrRadio($fieldName, $labelCode, $listOptions, $attributes = []
9931038
return $result;
9941039
}
9951040
}
1041+
}
1042+
1043+
if (!function_exists('groupSorts')) {
1044+
/**
1045+
* Returns group sorting.
1046+
*
1047+
* @param string $extraClasses any extra classes you add to the drop down
1048+
* @return string
1049+
*/
1050+
function groupSorts($extraClasses = '') {
1051+
if (!Gdn::session()->isValid()) {
1052+
return;
1053+
}
1054+
1055+
$baseUrl = preg_replace('/\?.*/', '', Gdn::request()->getFullPath());
1056+
$transientKey = Gdn::session()->transientKey();
1057+
$filters = [
1058+
[
1059+
'name' => t('New'),
1060+
'param' => 'sort',
1061+
'value' => 'new',
1062+
'extra' => ['TransientKey' => $transientKey, 'save' => 1, 'filter'=>'challenge']
1063+
],
1064+
1065+
[
1066+
'name' => t('Old'),
1067+
'param' => 'sort',
1068+
'value' => 'old',
1069+
'extra' => ['TransientKey' => $transientKey, 'save' => 1, 'filter'=>'challenge']
1070+
]
1071+
];
1072+
1073+
$defaultParams = [];
1074+
if (!empty($defaultParams)) {
1075+
$defaultUrl = $baseUrl.'?'.http_build_query($defaultParams);
1076+
} else {
1077+
$defaultUrl = $baseUrl;
1078+
}
1079+
1080+
return groupSortsDropDown(
1081+
$baseUrl,
1082+
$filters,
1083+
$extraClasses,
1084+
null,
1085+
$defaultUrl,
1086+
'Sort'
1087+
);
1088+
}
1089+
}
1090+
1091+
if (!function_exists('groupSortsDropDown')) {
1092+
/**
1093+
* Returns a sorting drop-down menu.
1094+
*
1095+
* @param string $baseUrl Target URL with no query string applied.
1096+
* @param array $filters A multidimensional array of rows with the following properties:
1097+
* ** 'name': Friendly name for the filter.
1098+
* ** 'param': URL parameter associated with the filter.
1099+
* ** 'value': A value for the URL parameter.
1100+
* @param string $extraClasses any extra classes you add to the drop down
1101+
* @param string|null $default The default label for when no filter is active. If `null`, the default label is not added
1102+
* @param string|null $defaultURL URL override to return to the default, unfiltered state.
1103+
* @param string $label Text for the label to attach to the cont
1104+
* @return string
1105+
*/
1106+
function groupSortsDropDown($baseUrl, array $filters = [], $extraClasses = '', $default = null, $defaultUrl = null, $label = 'Sort') {
1107+
$links = [];
1108+
$active = Gdn::session()->getPreference('GroupSort', null);
1109+
// Translate filters into links.
1110+
foreach ($filters as $filter) {
1111+
// Make sure we have the bare minimum: a label and a URL parameter.
1112+
if (!array_key_exists('name', $filter)) {
1113+
throw new InvalidArgumentException('Sort does not have a name field.');
1114+
}
1115+
if (!array_key_exists('param', $filter)) {
1116+
throw new InvalidArgumentException('Sort does not have a param field.');
1117+
}
1118+
1119+
// Prepare for consumption by linkDropDown.
1120+
$query = [$filter['param'] => $filter['value']];
1121+
if (array_key_exists('extra', $filter) && is_array($filter['extra'])) {
1122+
$query += $filter['extra'];
1123+
}
1124+
$url = url($baseUrl . '?' . http_build_query($query));
1125+
$link = [
1126+
'name' => $filter['name'],
1127+
'url' => $url
1128+
];
1129+
1130+
// If we don't already have an active link, and this parameter and value match, this is the active link.
1131+
if ($active === null && Gdn::request()->get($filter['param']) == $filter['value']) {
1132+
$active = $filter['value'];
1133+
$link['active'] = true;
1134+
} else if ($active == $filter['value']){
1135+
$link['active'] = true;
1136+
$active = $filter['value'];
1137+
}
1138+
1139+
// Queue up another filter link.
1140+
$links[] = $link;
1141+
}
1142+
1143+
if ($default !== null) {
1144+
$default = t('All');
1145+
// Add the default link to the top of the list.
1146+
array_unshift($links, [
1147+
'active' => $active === null,
1148+
'name' => $default,
1149+
'url' => $defaultUrl ?: $baseUrl
1150+
]);
1151+
}
1152+
1153+
// Generate the markup for the drop down menu.
1154+
$output = linkDropDown($links, 'selectBox-following ' . trim($extraClasses), t($label) . ': ');
1155+
return $output;
1156+
}
9961157
}

controllers/class.groupcontroller.php

Lines changed: 60 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,47 +86,98 @@ public function index($GroupID = '') {
8686
$this->setData('Group', $Group, true);
8787

8888
$this->title($Group->Name);
89+
$category = $this->CategoryModel->getByCode($Group->ChallengeID);
90+
$categoryID= val('CategoryID', $category);
91+
$this->setData('GroupCategoryID', $categoryID);
92+
$this->setData('Breadcrumbs', $this->buildBreadcrumbs($categoryID));
8993

90-
$this->setData('Breadcrumbs', $this->buildBreadcrumb($Group));
9194
$roleResources = $this->data('ChallengeRoleResources');
9295
$resources = $this->data('ChallengeResources');
9396
$copilots = $this->getCopilots($resources, $roleResources);
9497
$this->setData('Copilots', $copilots);
9598
$groupDiscussions = $this->GroupModel->getGroupDiscussionCategories($Group);
96-
$defaultDiscussionUrl = '/post/discussion/';
99+
$defaultDiscussionUrl= $defaultAnnouncementUrl = '/post/discussion/';
97100
if($Group->Type == GroupModel::TYPE_REGULAR) {
98101
if(count($groupDiscussions) > 0) {
99102
$defaultDiscussionUrl .= $groupDiscussions[0]['UrlCode'];
100103
}
101104
} else if($Group->Type == GroupModel::TYPE_CHALLENGE) {
102105
if(count($groupDiscussions) == 1) {
103-
$defaultDiscussionUrl .= $groupDiscussions[0]['UrlCode'];
106+
$defaultAnnouncementUrl .= $groupDiscussions[0]['UrlCode'];
104107
} else {
105108
foreach ($groupDiscussions as $groupDiscussion) {
106109
if ($groupDiscussion['Name'] == 'Code Questions') {
107-
$defaultDiscussionUrl .= $groupDiscussion['UrlCode'];
110+
$defaultAnnouncementUrl .= $groupDiscussion['UrlCode'];
108111
break;
109112
}
110113
}
111114
}
112115
}
113116

114-
$this->setData('DefaultAnnouncementUrl', $defaultDiscussionUrl.'?announce=1');
117+
$CategoryIDs = $this->GroupModel->getAllGroupCategoryIDs($Group->GroupID);
118+
$Categories = $this->CategoryModel->getFull($CategoryIDs)->resultArray();
119+
$this->setData('Categories', $Categories);
120+
121+
// Get category data and discussions
122+
123+
$this->DiscussionsPerCategory = c('Vanilla.Discussions.PerCategory', 5);
124+
$DiscussionModel = new DiscussionModel();
125+
$DiscussionModel->setSort(Gdn::request()->get());
126+
$DiscussionModel->setFilters(Gdn::request()->get());
127+
$this->setData('Sort', $DiscussionModel->getSort());
128+
$this->setData('Filters', $DiscussionModel->getFilters());
129+
130+
$this->CategoryDiscussionData = [];
131+
$Discussions = [];
132+
133+
foreach ($this->CategoryData->result() as $Category) {
134+
if ($Category->CategoryID > 0) {
135+
$this->CategoryDiscussionData[$Category->CategoryID] = $DiscussionModel->get(0, $this->DiscussionsPerCategory,
136+
['d.CategoryID' => $Category->CategoryID, 'Announce' => '0']);
137+
$Discussions = array_merge(
138+
$Discussions,
139+
$this->CategoryDiscussionData[$Category->CategoryID]->resultObject()
140+
);
141+
}
142+
}
143+
$this->setData('Discussions', $Discussions);
144+
145+
// render dropdown options
146+
$this->ShowOptions = true;
147+
148+
$this->setData('DefaultAnnouncementUrl', $defaultAnnouncementUrl.'?announce=1');
115149
$this->setData('DefaultDiscussionUrl', $defaultDiscussionUrl);
116150

117151
// Find all discussions with content from after DateMarkedRead.
118152
$discussionModel = new DiscussionModel();
119153
$categoryIDs = $this->GroupModel->getAllGroupCategoryIDs($Group->GroupID);
120-
$wheres = ['d.CategoryID' => $categoryIDs];
121154
$announcementsWheres = ['d.CategoryID' => $categoryIDs, 'd.Announce > '=> 0];
122-
//Don't use WhereRecent due to load all data including announce.
123-
$discussions = $discussionModel->getWhere($wheres,'DateInserted', 'asc');
124155
$announcements = $discussionModel->getAnnouncements($announcementsWheres );
125156
$this->setData('Announcements', $announcements);
126-
$this->setData('Discussions', $discussions);
157+
158+
$Path = $this->fetchViewLocation('helper_functions', 'discussions', 'vanilla', false);
159+
if ($Path) {
160+
include_once $Path;
161+
}
162+
163+
// For GetOptions function
164+
$Path2 = $this->fetchViewLocation('helper_functions', 'categories', 'vanilla', false);
165+
if ($Path2) {
166+
include_once $Path2;
167+
}
127168
$this->render();
128169
}
129170

171+
public function __get($name) {
172+
switch ($name) {
173+
case 'CategoryData':
174+
// deprecated('CategoriesController->CategoryData', "CategoriesController->data('Categories')");
175+
$this->CategoryData = new Gdn_DataSet($this->data('Categories'), DATASET_TYPE_ARRAY);
176+
$this->CategoryData->datasetType(DATASET_TYPE_OBJECT);
177+
return $this->CategoryData;
178+
}
179+
}
180+
130181
private function getCopilots($resources = null, $roleResources = null) {
131182
$copilots = [];
132183
$roleName = 'copilot';

0 commit comments

Comments
 (0)