@@ -827,23 +827,15 @@ public function checkPermission($userID,$groupID,$categoryID = null, $permission
827
827
* @param $UserID
828
828
* @param bool $watched
829
829
* @param bool $followed
830
- * @return bool|Gdn_DataSet|object|string
831
830
*/
832
831
public function join ($ GroupID , $ UserID , $ watched = true , $ followed = true ){
833
- GroupsPlugin::logMessage ('!!!-----------------join:enter-----------------!!! ' , ['GroupID ' => $ GroupID , 'userID ' =>$ UserID , 'watched ' => $ watched , 'followed ' =>$ followed ], __FILE__ , __LINE__ ) ;
834
832
$ Fields = ['Role ' => GroupModel::ROLE_MEMBER , 'GroupID ' => $ GroupID ,'UserID ' => $ UserID , 'DateInserted ' => Gdn_Format::toDateTime ()];
835
833
if ( $ this ->SQL ->getWhere ('UserGroup ' , ['GroupID ' => $ GroupID ,'UserID ' => $ UserID ])->numRows () == 0 ) {
836
834
$ this ->SQL ->insert ('UserGroup ' , $ Fields );
837
- GroupsPlugin::logMessage ('join:user was added in UserGroup ' , ['userID ' =>$ UserID , 'watched ' => $ watched , 'followed ' =>$ followed ],__FILE__ , __LINE__ );
838
- if ($ followed === true ) {
839
- $ this ->followGroup ($ GroupID , $ UserID );
840
- }
841
- if ($ watched === true ) {
842
- $ this ->watchGroup ($ GroupID , $ UserID );
843
- }
844
835
$ this ->notifyJoinGroup ($ GroupID , $ UserID );
845
836
}
846
- GroupsPlugin::logMessage ('join:exit ' , [],__FILE__ , __LINE__ );
837
+ $ this ->followGroup ($ GroupID , $ UserID , $ followed );
838
+ $ this ->watchGroup ($ GroupID , $ UserID , $ watched );
847
839
848
840
}
849
841
@@ -1252,30 +1244,22 @@ public function hasWatchedGroup($group) {
1252
1244
* Follow all group's categories
1253
1245
* @param $group
1254
1246
* @param $userID
1247
+ * @param bool $followed
1255
1248
*/
1256
- public function followGroup ($ group , $ userID ) {
1257
- //TODO: Remove extra logging after testing
1258
- GroupsPlugin::logMessage ('-----------------followGroup:enter------------ ' , ['userID ' =>$ userID , 'group ' =>$ group ],__FILE__ , __LINE__ );
1249
+ public function followGroup ($ group , $ userID , $ followed = true ) {
1259
1250
if (is_numeric ($ group ) && $ group > 0 ) {
1260
1251
$ group = $ this ->getByGroupID ($ group );
1261
1252
}
1262
1253
if ($ group ->ChallengeID ) {
1263
1254
$ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1264
1255
$ categoryIDs = array_column ($ categories , 'CategoryID ' );
1265
- GroupsPlugin::logMessage ('follow:allCatIDs ' , ['userID ' =>$ userID , 'catIds ' =>$ categoryIDs ], __FILE__ , __LINE__ ) ;
1266
1256
1267
1257
foreach ($ categoryIDs as $ categoryID ) {
1268
- try {
1269
- Gdn::sql ()->insert (
1270
- 'UserCategory ' ,
1271
- ['Followed ' => 1 , 'UserID ' => $ userID , 'CategoryID ' => $ categoryID ]
1272
- );
1273
- } catch (Exception $ e ) {
1274
- Gdn::sql ()->update ('UserCategory ' ,
1275
- ['Followed ' => 1 ],
1276
- ['UserID ' => $ userID , 'CategoryID ' => $ categoryID ]
1277
- )->put ();
1278
- }
1258
+ $ this ->SQL ->replace (
1259
+ 'UserCategory ' ,
1260
+ ['Followed ' => (int )$ followed ],
1261
+ ['UserID ' => $ userID , 'CategoryID ' => $ categoryID ]
1262
+ );
1279
1263
}
1280
1264
CategoryModel::clearUserCache ($ userID );
1281
1265
Gdn::cache ()->remove ("Follow_ {$ userID }" );
@@ -1288,92 +1272,56 @@ public function followGroup($group, $userID) {
1288
1272
* @param $userID
1289
1273
*/
1290
1274
public function unfollowGroup ($ group , $ userID ) {
1291
- GroupsPlugin::logMessage ('-----------------unfollow:enter----------------- ' , ['userID ' =>$ userID , 'group ' =>$ group ], __FILE__ , __LINE__ ) ;
1292
- if (is_numeric ($ group ) && $ group > 0 ) {
1293
- $ group = $ this ->getByGroupID ($ group );
1294
- }
1295
-
1296
- if ($ group ->ChallengeID ) {
1297
- $ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1298
- $ categoryIDs = array_column ($ categories , 'CategoryID ' );
1299
- GroupsPlugin::logMessage ('unfollow:allCatIDs ' , ['userID ' =>$ userID , 'catIds ' =>$ categoryIDs ], __FILE__ , __LINE__ ) ;
1300
-
1301
- foreach ($ categoryIDs as $ categoryID ) {
1302
- Gdn::sql ()->update ('UserCategory ' , [ 'Followed ' => 0 ],
1303
- ['UserID ' => $ userID ,'CategoryID ' => $ categoryID ])->put ();
1304
- }
1305
-
1306
- Gdn::cache ()->remove ("Follow_ {$ userID }" );
1307
- CategoryModel::clearUserCache ($ userID );
1308
- }
1275
+ $ this ->followGroup ($ group , $ userID , false );
1309
1276
}
1310
1277
1311
1278
/**
1312
1279
* Watch all group's categories
1313
1280
* @param $group
1314
1281
* @param $userID
1282
+ * @param int $watched 1 - watch, 0/null - unwatch
1315
1283
*/
1316
- public function watchGroup ($ group , $ userID ) {
1317
- //TODO: Remove extra logging after testing
1318
- GroupsPlugin::logMessage ('-----------------watch:enter----------------- ' , ['userID ' =>$ userID , 'group ' =>$ group ], __FILE__ , __LINE__ ) ;
1319
-
1284
+ public function watchGroup ($ group , $ userID , $ watched = true ) {
1320
1285
if (is_numeric ($ group ) && $ group > 0 ) {
1321
1286
$ group = $ this ->getByGroupID ($ group );
1322
1287
}
1323
1288
1324
1289
if ($ group ->ChallengeID ) {
1325
1290
$ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1326
1291
$ categoryIDs = array_column ($ categories , 'CategoryID ' );
1327
- GroupsPlugin::logMessage ('watch:allCatIDs ' , ['userID ' =>$ userID , 'catIds ' =>$ categoryIDs ], __FILE__ , __LINE__ ) ;
1328
- // Don't use setCategoryMetaData due to cache
1292
+ // Don't use setCategoryMetaData due to cache
1329
1293
$ metaKeys = ['Preferences.Email.NewComment. ' ,
1330
1294
'Preferences.Email.NewDiscussion. ' ,
1331
1295
'Preferences.Popup.NewComment. ' ,
1332
1296
'Preferences.Popup.NewDiscussion. ' ];
1333
1297
foreach ($ categoryIDs as $ categoryID ) {
1334
1298
foreach ($ metaKeys as $ metaKey ) {
1335
- Gdn::sql ()->insert ('UserMeta ' , [
1336
- 'UserID ' => $ userID ,
1337
- 'Name ' => $ metaKey . $ categoryID ,
1338
- 'Value ' => 1
1339
- ]);
1299
+ if ($ watched ) {
1300
+ $ this ->SQL ->replace (
1301
+ 'UserMeta ' ,
1302
+ [ 'Value ' => (int )$ watched ],
1303
+ [ 'UserID ' => $ userID , 'Name ' => $ metaKey . $ categoryID ,]
1304
+ );
1305
+ } else {
1306
+ Gdn::sql ()->delete ('UserMeta ' , [
1307
+ 'UserID ' => $ userID ,
1308
+ 'Name ' => $ metaKey . $ categoryID
1309
+ ]);
1310
+ }
1340
1311
}
1341
1312
}
1342
1313
CategoryModel::clearUserCache ($ userID );
1343
- $ result = Gdn::cache ()->remove ("UserMeta_ {$ userID }" );
1344
- GroupsPlugin::logMessage ('watch:UserMetaCacheRemoved ' , ['userID ' =>$ userID , 'cacheRemoved ' =>$ result ], __FILE__ , __LINE__ ) ;
1314
+ Gdn::cache ()->remove ("UserMeta_ {$ userID }" );
1345
1315
}
1346
1316
}
1347
1317
1348
1318
/**
1349
1319
* Unwatch all group's categories
1350
1320
* @param $group
1321
+ * @param $userID
1351
1322
*/
1352
1323
public function unwatchGroup ($ group , $ userID ) {
1353
- GroupsPlugin::logMessage ('-----------------unwatch:enter----------------- ' , ['userID ' =>$ userID , 'group ' =>$ group ], __FILE__ , __LINE__ ) ;
1354
-
1355
- if (is_numeric ($ group ) && $ group > 0 ) {
1356
- $ group = $ this ->getByGroupID ($ group );
1357
- }
1358
- if ($ group ->ChallengeID ) {
1359
- $ categories = Gdn::sql ()->getWhere ('Category ' , ['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1360
- $ categoryIDs = array_column ($ categories , 'CategoryID ' );
1361
- // Don't use setCategoryMetaData due to cache
1362
- $ metaKeys = ['Preferences.Email.NewComment. ' ,
1363
- 'Preferences.Email.NewDiscussion. ' ,
1364
- 'Preferences.Popup.NewComment. ' ,
1365
- 'Preferences.Popup.NewDiscussion. ' ];
1366
- foreach ($ categoryIDs as $ categoryID ) {
1367
- foreach ($ metaKeys as $ metaKey ) {
1368
- Gdn::sql ()->delete ('UserMeta ' , [
1369
- 'UserID ' => $ userID ,
1370
- 'Name ' => $ metaKey . $ categoryID
1371
- ]);
1372
- }
1373
- }
1374
- Gdn::cache ()->remove ("UserMeta_ {$ userID }" );
1375
- CategoryModel::clearUserCache ($ userID );
1376
- }
1324
+ $ this ->watchGroup ($ group ,$ userID ,false );
1377
1325
}
1378
1326
1379
1327
0 commit comments