@@ -533,7 +533,7 @@ public function categoryModel_watch_create(CategoryModel $sender){
533
533
public function categoryModel_setCategoryMetaData_create (CategoryModel $ sender ) {
534
534
$ categoryIDs = val (0 , $ sender ->EventArguments );
535
535
$ userID = val (1 , $ sender ->EventArguments );
536
- $ watched = val (2 , $ sender ->EventArguments );
536
+ $ watched = val (2 , $ sender ->EventArguments ); // 1, 2- partly watched, null- remove
537
537
$ userMetaModel = new UserMetaModel ();
538
538
if (is_numeric ($ categoryIDs ) ) {
539
539
$ categoryIDs = [$ categoryIDs ];
@@ -552,7 +552,13 @@ public function categoryModel_setCategoryMetaData_create(CategoryModel $sender)
552
552
$ userMetaModel = new UserMetaModel ();
553
553
$ userMetaModel ->setWatchedCategoriesCount ($ userID );
554
554
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 ;
556
562
}
557
563
558
564
/**
@@ -601,6 +607,43 @@ public function categoryModel_hasWatched_create(CategoryModel $sender) {
601
607
return false ;
602
608
}
603
609
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
+
604
647
//
605
648
// EMAIL TEMPLATES
606
649
//
@@ -892,8 +935,9 @@ public function base_beforeRenderDiscussionFilters_handler($sender, $args){
892
935
if ($ sender instanceof CategoriesController || $ sender instanceof PostController) {
893
936
$ category = $ sender ->data ('Category ' );
894
937
if ($ category ) {
895
- $ groupID = val ('GroupID ' , $ category );
896
- if ($ groupID ) {
938
+ $ categoryID = val ('CategoryID ' , $ category );
939
+ $ isChallengeForums = $ sender ->checkChallengeForums ($ categoryID );
940
+ if ($ isChallengeForums ) {
897
941
$ menu ['AllCategories ' ]['IsActive ' ] = false ;
898
942
return ;
899
943
}
@@ -923,8 +967,9 @@ private function getMenuItemCssClassFromQuery($sender, $requestMethod){
923
967
if ($ sender instanceof CategoriesController || $ sender instanceof PostController) {
924
968
$ category = $ sender ->data ('Category ' );
925
969
if ($ category ) {
926
- $ groupID = val ('GroupID ' , $ category );
927
- if ($ groupID ) {
970
+ $ categoryID = val ('CategoryID ' , $ category );
971
+ $ isChallengeForums = $ sender ->checkChallengeForums ($ categoryID );
972
+ if ($ isChallengeForums ) {
928
973
$ cssClass = ' Active ' ;
929
974
}
930
975
}
@@ -993,4 +1038,120 @@ function wrapCheckOrRadio($fieldName, $labelCode, $listOptions, $attributes = []
993
1038
return $ result ;
994
1039
}
995
1040
}
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
+ }
996
1157
}
0 commit comments