@@ -991,19 +991,22 @@ public function save($formPostValues, $settings = false) {
991
991
992
992
$ groupID = val ('GroupID ' , $ formPostValues );
993
993
$ ownerID = val ('OwnerID ' , $ formPostValues );
994
+ $ type = val ('Type ' , $ formPostValues );
995
+ $ name = val ('Name ' , $ formPostValues );
996
+ $ archived = val ('Archived ' , $ formPostValues );
994
997
$ insert = $ groupID > 0 ? false : true ;
995
998
996
999
if ($ insert ) {
997
1000
// Figure out the next group ID.
998
1001
$ maxGroupID = $ this ->SQL ->select ('g.GroupID ' , 'MAX ' )->from ('Group g ' )->get ()->value ('GroupID ' , 0 );
999
1002
$ groupID = $ maxGroupID + 1 ;
1000
-
1001
1003
$ this ->addInsertFields ($ formPostValues );
1002
1004
$ formPostValues ['GroupID ' ] = strval ($ groupID ); // string for validation
1003
1005
} else {
1004
1006
$ this ->addUpdateFields ($ formPostValues );
1005
1007
}
1006
1008
1009
+ // TODO: Move creating Challenge group categories from challenge processor
1007
1010
// Validate the form posted values
1008
1011
if ($ this ->validate ($ formPostValues , $ insert )) {
1009
1012
$ fields = $ this ->Validation ->schemaValidationFields ();
@@ -1013,6 +1016,23 @@ public function save($formPostValues, $settings = false) {
1013
1016
$ this ->update ($ fields , ['GroupID ' => $ groupID ]);
1014
1017
} else {
1015
1018
$ this ->insert ($ fields );
1019
+ //Create a category for a regular group
1020
+ if ($ type == GroupModel::TYPE_REGULAR ) {
1021
+ $ categoryModel = new CategoryModel ();
1022
+ $ parentCategory = $ categoryModel ->getByCode ('groups ' );
1023
+ $ categoryData = [ 'Name ' => $ name ,
1024
+ 'ParentCategoryID ' => $ parentCategory ->CategoryID ,
1025
+ 'DisplayAs ' => 'Discussions ' ,
1026
+ 'AllowFileUploads ' => 1 ,
1027
+ 'UrlCode ' => 'group- ' .$ groupID ,
1028
+ 'GroupID ' => $ groupID ,
1029
+ 'Archived ' => $ archived ];
1030
+ $ categoryID = $ categoryModel ->save ($ categoryData );
1031
+ // TODO
1032
+ if (!$ categoryID ) {
1033
+ // Error
1034
+ }
1035
+ }
1016
1036
$ this ->SQL ->insert (
1017
1037
'UserGroup ' ,
1018
1038
[
@@ -1053,8 +1073,28 @@ public function deleteID($groupID, $options = []) {
1053
1073
* @inheritdoc
1054
1074
*/
1055
1075
public function validate ($ values , $ insert = false ) {
1076
+ $ result = true ;
1077
+ // TODO: Move Challenge group validation from challenge processor
1078
+ $ type = val ('Type ' , $ values );
1079
+ $ urlCode = val ('UrlCode ' , $ values );
1080
+ if ($ insert === true ) {
1081
+ $ categoryModel = new CategoryModel ();
1082
+ if ($ type === GroupModel::TYPE_REGULAR ) {
1083
+ $ category = $ categoryModel ->getByCode ($ urlCode );
1084
+ if ($ category ) {
1085
+ $ result = false ;
1086
+ $ this ->Validation ->addValidationResult ('UrlCode ' , 'Group UrlCode has existed. ' );
1087
+ }
1088
+ $ parentCategory = $ categoryModel ->getByCode ('groups ' );
1089
+ if (!$ parentCategory ) {
1090
+ $ result = false ;
1091
+ $ this ->Validation ->addValidationResult ('ParentCategoryID ' , 'Groups category was not found. ' );
1092
+ }
1056
1093
1057
- return parent ::validate ($ values , $ insert );
1094
+ }
1095
+ }
1096
+ $ result = $ result && parent ::validate ($ values , $ insert );
1097
+ return $ result ;
1058
1098
}
1059
1099
1060
1100
/**
@@ -1304,6 +1344,14 @@ public function canAddGroup() {
1304
1344
*
1305
1345
*/
1306
1346
public function canManageCategories ($ group ) {
1347
+ if ((int )$ group ->Archived === 1 ) {
1348
+ return false ;
1349
+ }
1350
+
1351
+ if ($ group ->Type === GroupModel::TYPE_REGULAR ) {
1352
+ return false ;
1353
+ }
1354
+
1307
1355
return $ this ->isProjectCopilot () || $ this ->isProjectManager () || Gdn::session ()->checkPermission (GroupsPlugin::GROUPS_CATEGORY_MANAGE_PERMISSION );
1308
1356
}
1309
1357
@@ -1329,6 +1377,9 @@ private function checkTopcoderProjectRole($topcoderProjectRole){
1329
1377
*
1330
1378
*/
1331
1379
public function canEdit ($ group ) {
1380
+ if ((int )$ group ->Archived === 1 ) {
1381
+ return false ;
1382
+ }
1332
1383
$ result = $ this ->getGroupRoleFor (Gdn::session ()->UserID , $ group ->GroupID );
1333
1384
$ groupRole = val ('Role ' , $ result , null );
1334
1385
if ($ groupRole == GroupModel::ROLE_LEADER ||
@@ -1347,6 +1398,9 @@ public function canEdit($group) {
1347
1398
*
1348
1399
*/
1349
1400
public function canDelete ($ group ){
1401
+ if ((int )$ group ->Archived === 1 ) {
1402
+ return false ;
1403
+ }
1350
1404
return Gdn::session ()->UserID == $ group ->OwnerID || Gdn::session ()->checkPermission (GroupsPlugin::GROUPS_GROUP_DELETE_PERMISSION );
1351
1405
}
1352
1406
@@ -1355,6 +1409,9 @@ public function canDelete($group){
1355
1409
*
1356
1410
*/
1357
1411
public function canJoin ($ group ) {
1412
+ if ((int )$ group ->Archived === 1 ) {
1413
+ return false ;
1414
+ }
1358
1415
return $ group ->Privacy == GroupModel::PRIVACY_PUBLIC ;
1359
1416
}
1360
1417
@@ -1363,6 +1420,9 @@ public function canJoin($group) {
1363
1420
*
1364
1421
*/
1365
1422
public function canRemoveMember ($ group ) {
1423
+ if ((int )$ group ->Archived === 1 ) {
1424
+ return false ;
1425
+ }
1366
1426
$ result = $ this ->getGroupRoleFor (Gdn::session ()->UserID , $ group ->GroupID );
1367
1427
$ groupRole = val ('Role ' , $ result , null );
1368
1428
if ($ groupRole == GroupModel::ROLE_LEADER ||
@@ -1377,6 +1437,9 @@ public function canRemoveMember($group) {
1377
1437
*
1378
1438
*/
1379
1439
public function canChangeGroupRole ($ group ) {
1440
+ if ((int )$ group ->Archived === 1 ) {
1441
+ return false ;
1442
+ }
1380
1443
$ result = $ this ->getGroupRoleFor (Gdn::session ()->UserID , $ group ->GroupID );
1381
1444
$ groupRole = val ('Role ' , $ result , null );
1382
1445
if ($ groupRole == GroupModel::ROLE_LEADER ||
@@ -1391,6 +1454,9 @@ public function canChangeGroupRole($group) {
1391
1454
*
1392
1455
*/
1393
1456
public function canLeave ($ group ) {
1457
+ if ((int )$ group ->Archived === 1 ) {
1458
+ return false ;
1459
+ }
1394
1460
if (isset ($ group ->ChallengeID )) {
1395
1461
return false ;
1396
1462
}
@@ -1409,6 +1475,9 @@ public function canLeave($group) {
1409
1475
*
1410
1476
*/
1411
1477
public function canManageMembers ($ group ) {
1478
+ if ((int )$ group ->Archived === 1 ) {
1479
+ return false ;
1480
+ }
1412
1481
$ result = $ this ->getGroupRoleFor (Gdn::session ()->UserID , $ group ->GroupID );
1413
1482
$ groupRole = val ('Role ' , $ result , null );
1414
1483
if ($ groupRole == GroupModel::ROLE_LEADER ||
@@ -1423,6 +1492,9 @@ public function canManageMembers($group) {
1423
1492
*
1424
1493
*/
1425
1494
public function canInviteNewMember ($ group ) {
1495
+ if ((int )$ group ->Archived === 1 ) {
1496
+ return false ;
1497
+ }
1426
1498
$ result = $ this ->getGroupRoleFor (Gdn::session ()->UserID , $ group ->GroupID );
1427
1499
$ groupRole = val ('Role ' , $ result , null );
1428
1500
if ($ groupRole === GroupModel::ROLE_LEADER ||
@@ -1438,6 +1510,9 @@ public function canInviteNewMember($group) {
1438
1510
*
1439
1511
*/
1440
1512
public function canAddDiscussion ($ group ) {
1513
+ if ((int )$ group ->Archived === 1 ) {
1514
+ return false ;
1515
+ }
1441
1516
$ result = $ this ->getGroupRoleFor (Gdn::session ()->UserID , $ group ->GroupID );
1442
1517
$ groupRole = val ('Role ' , $ result , null );
1443
1518
if ($ groupRole || Gdn::session ()->UserID == $ group ->OwnerID ) {
@@ -1451,6 +1526,9 @@ public function canAddDiscussion($group) {
1451
1526
*
1452
1527
*/
1453
1528
public function canAddAnnouncement ($ group ) {
1529
+ if ((int )$ group ->Archived === 1 ) {
1530
+ return false ;
1531
+ }
1454
1532
$ result = $ this ->getGroupRoleFor (Gdn::session ()->UserID , $ group ->GroupID );
1455
1533
$ groupRole = val ('Role ' , $ result , null );
1456
1534
if ($ groupRole === GroupModel::ROLE_LEADER || Gdn::session ()->UserID == $ group ->OwnerID
@@ -1764,4 +1842,24 @@ public function archiveGroup($group){
1764
1842
$ group ->Archived = 1 ;
1765
1843
$ this ->save ($ group );
1766
1844
}
1845
+
1846
+ public function getGroupDiscussionCategories ($ group ){
1847
+ if (is_numeric ($ group ) && $ group > 0 ) {
1848
+ $ group = $ this ->getByGroupID ($ group );
1849
+ }
1850
+ $ categoryModel = new CategoryModel ();
1851
+ return $ categoryModel ->getWhere (['GroupID ' => $ group ->GroupID , 'DisplayAs ' => 'Discussions ' ])->resultArray ();
1852
+ }
1853
+
1854
+ public function getRootGroupCategory ($ group ){
1855
+ if (is_numeric ($ group ) && $ group > 0 ) {
1856
+ $ group = $ this ->getByGroupID ($ group );
1857
+ }
1858
+ $ categoryModel = new CategoryModel ();
1859
+ if ($ group ->ChallengeID ) {
1860
+ return $ categoryModel ->getByCode ($ group ->ChallengeID );
1861
+ }
1862
+
1863
+ return -1 ; //return Vanilla root
1864
+ }
1767
1865
}
0 commit comments