Skip to content

Commit 6b1bfd9

Browse files
committed
Show Norway tags in post group tags widget
1 parent 412fdcf commit 6b1bfd9

1 file changed

Lines changed: 72 additions & 1 deletion

File tree

plugins/bcc-login/includes/class-bcc-login-visibility.php

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,24 @@ private function get_groups_of_the_roles_tag() {
802802
return $roles_tag_groups;
803803
}
804804

805+
// Get only BCC Norge Key Roles
806+
private function get_groups_of_the_norway_tag() {
807+
$site_groups = $this->_coreapi->get_translated_site_groups();
808+
$norway_key_roles = array();
809+
810+
// Take site groups belonging to "BCC Norge" group tag
811+
foreach ($site_groups as $site_group) {
812+
if (in_array('BCC Norge', $site_group->tags)) {
813+
$norway_key_roles[] = $site_group;
814+
}
815+
}
816+
817+
// Sort by name
818+
usort($norway_key_roles, fn($a, $b) => $a->name <=> $b->name);
819+
820+
return $norway_key_roles;
821+
}
822+
805823
public function get_filtering_groups_list() {
806824
$roles_tag_groups = $this->get_groups_of_the_roles_tag();
807825

@@ -1159,6 +1177,7 @@ function post_group_tags_widget($atts) {
11591177
$post_visibility_groups_uids = get_post_meta($post_id, 'bcc_visibility_groups', false);
11601178

11611179
$central_key_roles = $this->get_groups_of_the_roles_tag();
1180+
$norway_key_roles = $this->get_groups_of_the_norway_tag();
11621181

11631182
// If only_user_groups is set, filter out groups which the current user is not in
11641183
if ($only_user_groups) {
@@ -1174,14 +1193,30 @@ function post_group_tags_widget($atts) {
11741193
$post_target_groups = array();
11751194
$post_visibility_groups = array();
11761195

1177-
// Get only post groups which are in Central Key Roles
1196+
// Get post groups which are in Central Key Roles
1197+
// + Norwegian roles if the Global corresponding ones are not present
11781198
foreach ($central_key_roles as $role) {
1199+
// Target groups
11791200
if (in_array($role->uid, $post_target_groups_uids)) {
11801201
$post_target_groups[] = $role;
11811202
}
1203+
else {
1204+
$norway_role = $this->get_corresponding_role_for_norway($role->uid, $norway_key_roles);
1205+
if ($norway_role && in_array($norway_role->uid, $post_target_groups_uids)) {
1206+
$post_target_groups[] = $norway_role;
1207+
}
1208+
}
1209+
1210+
// Visibility groups
11821211
if (in_array($role->uid, $post_visibility_groups_uids)) {
11831212
$post_visibility_groups[] = $role;
11841213
}
1214+
else {
1215+
$norway_role = $this->get_corresponding_role_for_norway($role->uid, $norway_key_roles);
1216+
if ($norway_role && in_array($norway_role->uid, $post_visibility_groups_uids)) {
1217+
$post_visibility_groups[] = $norway_role;
1218+
}
1219+
}
11851220
}
11861221

11871222
// If limit is set, slice the arrays
@@ -1222,6 +1257,42 @@ function post_group_tags_widget($atts) {
12221257
return $html;
12231258
}
12241259

1260+
private function get_corresponding_role_for_norway($role_uid, $norway_key_roles) {
1261+
if ($role_uid == '5dabf96b-0a5c-42d4-aa67-3df3a43257cc') { // Board Member
1262+
return $this->get_role_by_uid($norway_key_roles, '50a624ea-fbc3-4ffb-9891-53ab6bbd7f6f'); // Board Member - Norway
1263+
}
1264+
else if ($role_uid == '65360793-95f6-442d-9afc-a1c9da3a74ae') { // Chairman of the Board
1265+
return $this->get_role_by_uid($norway_key_roles, '3c0cb369-a497-4b23-9ae8-75f230292064'); // Chairman of the Board - Norway
1266+
}
1267+
else if ($role_uid == '184d4e81-0cb6-4133-8397-6e7803846328') { // Communications Contact
1268+
return $this->get_role_by_uid($norway_key_roles, 'd9a47fde-ca8f-46c6-8e28-95ad343e5800'); // Communications Contact - Norway
1269+
}
1270+
else if ($role_uid == '2ae8f8c7-c319-4d03-978b-bd82017819c0') { // Donation Model Contact
1271+
return $this->get_role_by_uid($norway_key_roles, 'e7aac0bc-4038-4d50-8947-3f848af2fa74'); // Donation Model Contact - Norway
1272+
}
1273+
else if ($role_uid == 'c4039ef3-1a93-4699-9c3d-63f148c1f019') { // Finance Manager
1274+
return $this->get_role_by_uid($norway_key_roles, '6e906efa-4515-44ab-a959-4961e436c02b'); // Finance Manager - Norway
1275+
}
1276+
else if ($role_uid == '95b99360-198c-43ff-9dd4-28c2bce362c2') { // Local Church Elder
1277+
return $this->get_role_by_uid($norway_key_roles, 'da1d210b-742e-4fd0-ba7b-4ce1cb800d18'); // Local Church Elder - Norway
1278+
}
1279+
else if ($role_uid == 'acc1b388-3df1-46b2-9ed4-f8808e04d8b5') { // Member Admin
1280+
return $this->get_role_by_uid($norway_key_roles, '5abfa57b-7dc0-4c83-ad9c-c8047ce20061'); // Member Admin - Norway
1281+
}
1282+
1283+
return null;
1284+
}
1285+
1286+
private function get_role_by_uid($roles, $uid) {
1287+
foreach ($roles as $role) {
1288+
if ($role->uid === $uid) {
1289+
return $role;
1290+
}
1291+
}
1292+
1293+
return null;
1294+
}
1295+
12251296
function get_bcc_group_name_by_id($atts) {
12261297
$attributes = shortcode_atts(array('uid' => ''), $atts);
12271298
$uid = $attributes['uid'];

0 commit comments

Comments
 (0)