'fluentcrm_profile_extended', 'title' => __('Community', 'fluent-community'), 'handler' => 'route', 'query' => [ 'handler' => 'fluent_community' ], ]; return $sections; } public function getProfileSection($sections, Subscriber $contact) { $userId = $contact->getWpUserId(); $sections['heading'] = 'FluentCommunity Profile'; if (!$userId) { $sections['content_html'] = '
' . __('Sorry! the contact does not have a FluentCommunity profile or not a registered site user.', 'fluent-community') . '
'; return $sections; } $content = ''; $xprofile = XProfile::where('user_id', $userId)->first(); if ($xprofile) { $content .= '' . __('View Community Profile', 'fluent-community') . ''; } $courseEnabled = Helper::isFeatureEnabled('course_module'); $dateFormat = get_option('date_format') . ' ' . get_option('time_format'); $userSpaces = Space::with('space_pivot') ->whereHas('space_pivot', function ($query) use ($userId) { $query->where('user_id', $userId); }) ->orderBy('title', 'ASC') ->get(); $content .= '' . __('No spaces found for this contact.', 'fluent-community') . '
'; } if ($courseEnabled) { $tableBuilder = new TableBuilder(); $userCourses = \FluentCommunity\Modules\Course\Services\CourseHelper::getUserCourses($userId); // this will return Collection of Course objects $content .= '' . __('No courses found for this contact.', 'fluent-community') . '
'; } } $spaceCourses = \FluentCommunity\App\Models\BaseSpace::withoutGlobalScopes() ->select('title', 'id', 'type', 'slug') ->whereIn('type', ['course', 'community']) ->whereDoesntHave('space_pivot', function ($query) use ($userId) { $query->where('user_id', $userId); }) ->orderBy('title', 'ASC') ->get(); $options = []; foreach ($spaceCourses as $spaceCourse) { $type = $spaceCourse->type; if ($type == 'course') { $type = 'Course'; } else if ($type == 'community') { $type = 'Space'; } $options[] = [ 'id' => $spaceCourse->id, 'label' => $spaceCourse->title . ' (' . $type . ') - ' . $spaceCourse->slug ]; } $removeSpaceCourses = \FluentCommunity\App\Models\BaseSpace::withoutGlobalScopes() ->select('title', 'id', 'type', 'slug') ->whereIn('type', ['course', 'community']) ->whereHas('space_pivot', function ($query) use ($userId) { $query->where('user_id', $userId); }) ->orderBy('title', 'ASC') ->get(); $removeOptions = []; foreach ($removeSpaceCourses as $spaceCourse) { $type = $spaceCourse->type; if ($type == 'course') { $type = 'Course'; } else if ($type == 'community') { $type = 'Space'; } $removeOptions[] = [ 'id' => $spaceCourse->id, 'label' => $spaceCourse->title . ' (' . $type . ') - ' . $spaceCourse->slug ]; } $sections['crud'] = [ 'btn_label' => __('Manage Space/Course', 'fluent-community'), 'form_heading' => __('Manage Space/Course Accesses', 'fluent-community'), 'fields' => [ 'base_space_ids' => [ 'type' => 'input-option', 'multiple' => true, 'placeholder' => $options ? __('Select Space or Course', 'fluent-community') : __('No Space or Course available', 'fluent-community'), 'label' => __('Add to Space or Course', 'fluent-community'), 'options' => $options ], 'remove_space_ids' => [ 'type' => 'input-option', 'multiple' => true, 'placeholder' => __('Select Space or Course', 'fluent-community'), 'label' => __('Remove from Space or Course', 'fluent-community'), 'options' => $removeOptions ] ] ]; $sections['content_html'] = $content; return $sections; } public function saveProfileSection($response, $data, Subscriber $subscriber) { $spaceIds = Arr::get($data, 'base_space_ids', []); $removeSpaceIds = Arr::get($data, 'remove_space_ids', []); if (!$spaceIds && !$removeSpaceIds) { throw new \Exception(esc_html__('No Space or Course selected', 'fluent-community')); } $userId = $subscriber->getWpUserId(); if (!$userId) { throw new \Exception(esc_html__('No user found for this contact', 'fluent-community')); } foreach ($removeSpaceIds as $removeSpaceId) { $space = BaseSpace::withoutGlobalScopes()->find($removeSpaceId); if ($space) { Helper::removeFromSpace($space, $userId); } } foreach ($spaceIds as $spaceId) { $space = BaseSpace::withoutGlobalScopes()->find($spaceId); if ($space) { Helper::addToSpace($space, $userId); } } return true; } }