diff --git a/app/Http/Controllers/ContactTableController.php b/app/Http/Controllers/ContactTableController.php index c0111431..dbc71150 100644 --- a/app/Http/Controllers/ContactTableController.php +++ b/app/Http/Controllers/ContactTableController.php @@ -32,10 +32,10 @@ public function index(Request $request): View // Determine what site to pull profiles from $site_id = $this->profile->getSiteID($request->data['base']); - $profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.profile_group_id')); + $profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.group_id')); // show table of contents if custom field 'table_of_contents' is not set to 'hide' - if (isset($request->data['base']['data']['table_of_contents']) && $request->data['base']['data']['table_of_contents'] === 'hide') { + if (config('profile.table_of_contents') === 'hide') { $profiles['anchors'] = []; } diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.php index 82fe82e1..455c7bf4 100644 --- a/app/Http/Controllers/DirectoryController.php +++ b/app/Http/Controllers/DirectoryController.php @@ -33,7 +33,7 @@ public function index(Request $request): View $site_id = $this->profile->getSiteID($request->data['base']); if (!empty($request->data['base']['data']['profile_group_id'])) { - $profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.profile_group_id')); + $profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.group_id')); } else { $profiles = $this->profile->getProfilesByGroup($site_id); } diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index fb2ca5d0..63f68c0b 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -33,7 +33,7 @@ public function index(Request $request): View $site_id = $this->profile->getSiteID($request->data['base']); // Determine if we are forcing the profiles from custom page data - $forced_profile_group_id = config('profile.profile_group_id'); + $forced_profile_group_id = config('profile.group_id'); // Get the groups for the dropdown $dropdown_groups = $this->profile->getDropdownOfGroups($site_id); diff --git a/app/Repositories/PeopleRepository.php b/app/Repositories/PeopleRepository.php index f78b22a8..510de73c 100644 --- a/app/Repositories/PeopleRepository.php +++ b/app/Repositories/PeopleRepository.php @@ -132,7 +132,7 @@ public function getProfilesByGroupOrder($site_id, $groups) { $profile_listing = $this->getProfiles($site_id); - $group_order = explode(',', $groups); + $group_order = preg_split('/[\s,|]+/', $groups); $profiles['profiles'] = []; @@ -193,7 +193,7 @@ public function getDropdownOfGroups(int $site_id): array // Filter down the groups based on the parent group from the config $profile_groups['data'] = collect($profile_groups['data']) ->filter(function ($item) { - return (int)$item['parent_id'] === config('profile.profile_parent_group_id'); + return (int)$item['parent_id'] === config('profile.parent_group_id'); }) ->toArray(); @@ -386,7 +386,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host = || $referer == $scheme.'://'.$host.$uri || strpos($referer, $host) === false ) { - return config('profile.profile_default_back_url'); + return config('profile.default_back_url'); } return $referer; @@ -397,7 +397,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host = */ public function getSiteID($data) { - return !empty(config('profile.profile_site_id')) ? config('profile.profile_site_id') : $data['site']['people']['site_id']; + return !empty(config('profile.site_id')) ? config('profile.site_id') : $data['site']['people']['site_id']; } /** @@ -418,32 +418,20 @@ public function parseProfileConfig(array $data): void if (Str::startsWith($value, '{')) { $profile_config = json_decode($value, true); - if (!empty($profile_config['site_id'])) { - Config::set('profile.profile_site_id', $profile_config['site_id']); - } - - if (!empty($profile_config['group_id'])) { - Config::set('profile.profile_group_id', $profile_config['group_id']); - } - - if (!empty($profile_config['parent_group_id'])) { - Config::set('profile.profile_parent_group_id', $profile_config['parent_group_id']); - } - - if (!empty($profile_config['default_back_url'])) { - Config::set('profile.profile_default_back_url', $profile_config['default_back_url']); + foreach ($profile_config as $key => $value) { + Config::set('profile.'.$key, $value); } } } // legacy support for profile_group_id if (!empty($data['data']['profile_group_id'])) { - Config::set('profile.profile_group_id', $data['data']['profile_group_id']); + Config::set('profile.group_id', $data['data']['profile_group_id']); } // legacy support for profile_site_id if (!empty($data['data']['profile_site_id'])) { - Config::set('profile.profile_site_id', $data['data']['profile_site_id']); + Config::set('profile.site_id', $data['data']['profile_site_id']); } } } diff --git a/app/Repositories/ProfileRepository.php b/app/Repositories/ProfileRepository.php index 310dd221..e43ceec1 100644 --- a/app/Repositories/ProfileRepository.php +++ b/app/Repositories/ProfileRepository.php @@ -124,7 +124,7 @@ public function getProfilesByGroupOrder($site_id, $groups) { $profile_listing = $this->getProfiles($site_id); - $group_order = explode('|', $groups); + $group_order = preg_split('/[\s,|]+/', $groups); $profiles = []; @@ -196,7 +196,7 @@ public function getDropdownOfGroups(int $site_id): array // Filter down the groups based on the parent group from the config $profile_groups['results'] = collect($profile_groups['results']) ->filter(function ($item) { - return (int) $item['parent_id'] === config('profile.profile_parent_group_id'); + return (int) $item['parent_id'] === config('profile.parent_group_id'); }) ->toArray(); @@ -368,7 +368,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host = || $referer == $scheme.'://'.$host.$uri || strpos($referer, $host) === false ) { - return config('profile.profile_default_back_url'); + return config('profile.default_back_url'); } return $referer; @@ -379,7 +379,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host = */ public function getSiteID($data) { - return !empty(config('profile.profile_site_id')) ? config('profile.profile_site_id') : $data['site']['id']; + return !empty(config('profile.site_id')) ? config('profile.site_id') : $data['site']['id']; } /** @@ -400,32 +400,20 @@ public function parseProfileConfig(array $data): void if (Str::startsWith($value, '{')) { $profile_config = json_decode($value, true); - if (!empty($profile_config['site_id'])) { - Config::set('profile.profile_site_id', $profile_config['site_id']); - } - - if (!empty($profile_config['group_id'])) { - Config::set('profile.profile_group_id', $profile_config['group_id']); - } - - if (!empty($profile_config['parent_group_id'])) { - Config::set('profile.profile_parent_group_id', $profile_config['parent_group_id']); - } - - if (!empty($profile_config['default_back_url'])) { - Config::set('profile.profile_default_back_url', $profile_config['default_back_url']); + foreach ($profile_config as $key => $value) { + Config::set('profile.'.$key, $value); } } } // legacy support for profile_group_id if (!empty($data['data']['profile_group_id'])) { - Config::set('profile.profile_group_id', $data['data']['profile_group_id']); + Config::set('profile.group_id', $data['data']['profile_group_id']); } // legacy support for profile_site_id if (!empty($data['data']['profile_site_id'])) { - Config::set('profile.profile_site_id', $data['data']['profile_site_id']); + Config::set('profile.site_id', $data['data']['profile_site_id']); } } } diff --git a/config/profile.php b/config/profile.php index 2c7ee80d..c02b71ed 100644 --- a/config/profile.php +++ b/config/profile.php @@ -10,7 +10,7 @@ | "Return to Listing" link. | */ - 'profile_default_back_url' => '/profiles', + 'default_back_url' => '/profiles', /* |-------------------------------------------------------------------------- @@ -22,7 +22,7 @@ | groups are added to the root then leave this value as 0. | */ - 'profile_parent_group_id' => 0, + 'parent_group_id' => 0, /* |-------------------------------------------------------------------------- @@ -47,7 +47,7 @@ | This value is a pipe delimited string of group ids. | */ - 'profile_group_id' => null, + 'group_id' => null, /* |-------------------------------------------------------------------------- @@ -59,7 +59,7 @@ | this value as null. | */ - 'profile_site_id' => null, + 'site_id' => null, /* |-------------------------------------------------------------------------- diff --git a/resources/views/profile-listing.blade.php b/resources/views/profile-listing.blade.php index 1cb9c451..26ac2a31 100644 --- a/resources/views/profile-listing.blade.php +++ b/resources/views/profile-listing.blade.php @@ -2,6 +2,10 @@ @section('content') @include('components.page-title', ['title' => $base['page']['title']]) + +
+ {!! $base['page']['content']['main'] !!} +
@if($hide_filtering == false)
diff --git a/styleguide/Pages/ContactTables.php b/styleguide/Pages/ContactTables.php index f7903d53..ba2c27b9 100644 --- a/styleguide/Pages/ContactTables.php +++ b/styleguide/Pages/ContactTables.php @@ -24,12 +24,31 @@ public function getPageData() 'controller' => 'ContactTableController', 'title' => 'Contact tables', 'id' => 101113, - 'content' => ['main' => '

In order to choose which groups show:

-
    -
  1. Add a custom field named "profile_group_id"
  2. -
  3. Add in the IDs of the groups separated by the "," character
  4. -
  5. Groups will be displayed in the order they are entered in the custom field
  6. -
'], + 'content' => ['main' => '

In order to choose which groups show, "group_id" is required. Groups will be displayed in the order they are entered in the custom field

+ + + + + + + + + + + + + +
Page fieldData
profile_data
+
+{
+"site_id":000000,
+"group_id":"1234|5678",
+"parent_group_id":"1234",
+"table_of_contents":"hide",
+"default_back_url":"/profiles/",
+}
+
+
'], ], ]); } diff --git a/styleguide/Pages/ContactTablesNoTOC.php b/styleguide/Pages/ContactTablesNoTOC.php index 54d6553c..2f44e556 100644 --- a/styleguide/Pages/ContactTablesNoTOC.php +++ b/styleguide/Pages/ContactTablesNoTOC.php @@ -25,15 +25,34 @@ public function getPageData() 'controller' => 'ContactTableController', 'title' => 'Contact tables, no table of contents', 'id' => 101114, - 'content' => ['main' => '

In order to choose which groups show:

-
    -
  1. Add a custom field named "profile_group_id"
  2. -
  3. Add in the IDs of the groups separated by the "," character
  4. -
  5. Groups will be displayed in the order they are entered in the custom field
  6. -
-

In order to hide the table of contents:

+ 'content' => ['main' => '

In order to choose which groups show, "group_id" is required. Groups will be displayed in the order they are entered in the custom field

+ + + + + + + + + + + + + +
Page fieldData
profile_data
+
+{
+"site_id":000000,
+"group_id":"1234|5678",
+"parent_group_id":"1234",
+"table_of_contents":"hide",
+"default_back_url":"/profiles/",
+}
+
+
+

In order to hide the table of contents:

    -
  1. Add a custom field to the page named "table_of_contents"
  2. +
  3. Use variable named "table_of_contents"
  4. Set the value to "hide"
'], ], diff --git a/styleguide/Pages/DirectoryOrdered.php b/styleguide/Pages/DirectoryOrdered.php index 5db543f7..fa029ecf 100644 --- a/styleguide/Pages/DirectoryOrdered.php +++ b/styleguide/Pages/DirectoryOrdered.php @@ -17,19 +17,35 @@ public function getPageData() 'site_id' => 1, ], ], - 'data' => [ - 'profile_group_id' => '0,1', - ], 'page' => [ 'controller' => 'DirectoryController', 'title' => 'Directory ordered', 'id' => 101108, - 'content' => ['main' => '

In order to choose which groups show:

-
    -
  1. Add a custom field named "profile_group_id"
  2. -
  3. Add in the IDs of the groups separated by the "," character
  4. -
  5. Groups will be displayed in the order they are entered in the custom field
  6. -
'], + 'content' => ['main' => '

In order to choose which groups show, "group_id" is required. Groups will be displayed in the order they are entered in the custom field

+ + + + + + + + + + + + + +
Page fieldData
profile_data
+
+{
+"site_id":000000,
+"group_id":"1234|5678",
+"parent_group_id":"1234",
+"table_of_contents":"hide",
+"default_back_url":"/profiles/",
+}
+
+
'], ], ]); } diff --git a/styleguide/Pages/Profiles.php b/styleguide/Pages/Profiles.php index cb172c84..97c185d4 100644 --- a/styleguide/Pages/Profiles.php +++ b/styleguide/Pages/Profiles.php @@ -21,6 +21,34 @@ public function getPageData() 'controller' => 'ProfileController', 'title' => 'Profile listing', 'id' => 101105, + 'content' => [ + 'main' => '

Profiles are configurable with in the CMS page custom field. Using a custom field named "profile_data".

+ + + + + + + + + + + + + + +
Page fieldData
profile_data
+
+{
+"site_id":000000,
+"group_id":"1234|5678",
+"parent_group_id":"1234",
+"table_of_contents":"hide",
+"default_back_url":"/profiles/",
+}
+
+
', + ], ], ]); } diff --git a/styleguide/Repositories/PeopleRepository.php b/styleguide/Repositories/PeopleRepository.php index df70d9e1..6a3632b3 100644 --- a/styleguide/Repositories/PeopleRepository.php +++ b/styleguide/Repositories/PeopleRepository.php @@ -70,12 +70,4 @@ public function sortGroupsByDisplayOrder($grouped, $groups) // There is no need to sort the groups in the styleguide since the order is random return $grouped; } - - /** - * {@inheritdoc} - */ - public function parseProfileConfig(array $data): void - { - // There is no need to parse the profile config in the styleguide - } } diff --git a/tests/Unit/Repositories/PeopleRepositoryTest.php b/tests/Unit/Repositories/PeopleRepositoryTest.php index 6a958e81..7d038773 100644 --- a/tests/Unit/Repositories/PeopleRepositoryTest.php +++ b/tests/Unit/Repositories/PeopleRepositoryTest.php @@ -83,18 +83,18 @@ public function getting_back_to_profile_list_url_should_return_url(): void { // The default path if no referer $url = app(PeopleRepository::class)->getBackToProfileListUrl(); - $this->assertTrue($url == config('profile.profile_default_back_url')); + $this->assertTrue($url == config('profile.default_back_url')); // If a referer is passed from a different domain $referer = $this->faker->url(); $url = app(PeopleRepository::class)->getBackToProfileListUrl($referer, 'http', 'wayne.edu', '/'); - $this->assertTrue($url == config('profile.profile_default_back_url')); + $this->assertTrue($url == config('profile.default_back_url')); // If a referer is passed that is the same page we are on $referer = $this->faker->url(); $parsed = parse_url($referer); $url = app(PeopleRepository::class)->getBackToProfileListUrl($referer, $parsed['scheme'], $parsed['host'], $parsed['path']); - $this->assertTrue($url == config('profile.profile_default_back_url')); + $this->assertTrue($url == config('profile.default_back_url')); // If referer is passed from the same domain that the site is on $referer = $this->faker->url(); @@ -404,7 +404,7 @@ public function getting_people_site_id_should_return_the_correct_site_id_based_o ]); // Reset the profile_site_id - Config::set('profile.profile_site_id', null); + Config::set('profile.site_id', null); app(PeopleRepository::class, ['peopleApi' => $peopleApi])->parseProfileConfig($site_config_page); $return_people_site_id = app(PeopleRepository::class, ['peopleApi' => $peopleApi])->getSiteID($site_config_page); @@ -490,9 +490,9 @@ public function get_profile_data_with_json_array(): void app(PeopleRepository::class, ['wsuApi' => $wsuApi])->parseProfileConfig($data); - $this->assertEquals($site_id, config('profile.profile_site_id')); - $this->assertEquals($group_id, config('profile.profile_group_id')); - $this->assertEquals($parent_group_id, config('profile.profile_parent_group_id')); - $this->assertEquals($back_url, config('profile.profile_default_back_url')); + $this->assertEquals($site_id, config('profile.site_id')); + $this->assertEquals($group_id, config('profile.group_id')); + $this->assertEquals($parent_group_id, config('profile.parent_group_id')); + $this->assertEquals($back_url, config('profile.default_back_url')); } } diff --git a/tests/Unit/Repositories/ProfileRepositoryTest.php b/tests/Unit/Repositories/ProfileRepositoryTest.php index 0668ca08..7f529218 100644 --- a/tests/Unit/Repositories/ProfileRepositoryTest.php +++ b/tests/Unit/Repositories/ProfileRepositoryTest.php @@ -83,18 +83,18 @@ public function getting_back_to_profile_list_url_should_return_url(): void { // The default path if no referer $url = app(ProfileRepository::class)->getBackToProfileListUrl(); - $this->assertTrue($url == config('profile.profile_default_back_url')); + $this->assertTrue($url == config('profile.default_back_url')); // If a referer is passed from a different domain $referer = $this->faker->url(); $url = app(ProfileRepository::class)->getBackToProfileListUrl($referer, 'http', 'wayne.edu', '/'); - $this->assertTrue($url == config('profile.profile_default_back_url')); + $this->assertTrue($url == config('profile.default_back_url')); // If a referer is passed that is the same page we are on $referer = $this->faker->url(); $parsed = parse_url($referer); $url = app(ProfileRepository::class)->getBackToProfileListUrl($referer, $parsed['scheme'], $parsed['host'], $parsed['path']); - $this->assertTrue($url == config('profile.profile_default_back_url')); + $this->assertTrue($url == config('profile.default_back_url')); // If referer is passed from the same domain that the site is on $referer = $this->faker->url(); @@ -107,7 +107,7 @@ public function getting_back_to_profile_list_url_should_return_url(): void public function getting_dropdown_of_groups_should_contain_all_the_groups(): void { // Force this config incase it is changed - config(['profile.profile_parent_group_id' => 0]); + config(['profile.parent_group_id' => 0]); // Fake return $return = [ @@ -132,7 +132,7 @@ public function getting_dropdown_of_groups_should_contain_all_the_groups(): void public function getting_dropdown_of_single_group_should_contain_single_group(): void { // Force this config incase it is changed - config(['profile.profile_parent_group_id' => 0]); + config(['profile.parent_group_id' => 0]); // Fake return $return = [ @@ -276,7 +276,7 @@ public function getting_profile_group_ids_should_return_correct_string(): void public function profiles_should_be_grouped(): void { // Force this config incase it is changed - config(['profile.profile_parent_group_id' => 0]); + config(['profile.parent_group_id' => 0]); // Mock the user listing $return_user_listing = app(Profile::class)->create(10); @@ -365,7 +365,8 @@ public function getting_profile_site_id_should_return_the_correct_site_id_based_ $cms_site_id = $site_config_page['site']['id']; // Reset the profile_site_id - Config::set('profile.profile_site_id', null); + Config::set('profile.site_id', null); + app(ProfileRepository::class, ['wsuApi' => $wsuApi])->parseProfileConfig($site_config_page); $return_cms_site_id = app(ProfileRepository::class, ['wsuApi' => $wsuApi])->getSiteID($site_config_page); @@ -458,9 +459,9 @@ public function get_profile_data_with_json_array(): void app(ProfileRepository::class, ['wsuApi' => $wsuApi])->parseProfileConfig($data); - $this->assertEquals($site_id, config('profile.profile_site_id')); - $this->assertEquals($group_id, config('profile.profile_group_id')); - $this->assertEquals($parent_group_id, config('profile.profile_parent_group_id')); - $this->assertEquals($back_url, config('profile.profile_default_back_url')); + $this->assertEquals($site_id, config('profile.site_id')); + $this->assertEquals($group_id, config('profile.group_id')); + $this->assertEquals($parent_group_id, config('profile.parent_group_id')); + $this->assertEquals($back_url, config('profile.default_back_url')); } }