Repository navigation
Creator LMS Integration added #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
987e853
feat: creator lms integration init
RishadAlam e3eda6a
refactor: creator LMS sanitize codes
RishadAlam 36e105c
Change asset copy command to build command
RishadAlam a61a69e
chore: remove plugin_header from plugin check
RishadAlam 284cc59
fix: creator LMS Missing Translators Comment wp plugin check
RishadAlam d38ed3d
refactor: build and wp plugin check file
RishadAlam 0725d1b
refactor: keap store logs
RishadAlam 0a3fefd
fix: keap redundant generate field map
RishadAlam b5f9aad
fix: constant contact redundant generate field map
RishadAlam aab76f6
Merge branch 'main' into feat/creator-lms
RishadAlam 04d0a9e
refactor: react router imports
RishadAlam 5ae10ea
Merge branch 'main' into feat/creator-lms
RishadAlam 1f262aa
Merge branch 'main' into feat/creator-lms
RishadAlam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Creator LMS Integration | ||
| */ | ||
|
|
||
| namespace BitApps\Integrations\Actions\CreatorLms; | ||
|
|
||
| use WP_Error; | ||
|
|
||
| /** | ||
| * Provide functionality for Creator LMS integration | ||
| */ | ||
| class CreatorLmsController | ||
| { | ||
| public static function isExists() | ||
| { | ||
| if (!class_exists('CreatorLms') || !\function_exists('crlms_get_course')) { | ||
| wp_send_json_error( | ||
| __( | ||
| 'Creator LMS is not activated or not installed', | ||
| 'bit-integrations' | ||
| ), | ||
| 400 | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| public static function creatorLmsAuthorize() | ||
| { | ||
| self::isExists(); | ||
| wp_send_json_success(true); | ||
| } | ||
|
|
||
| public function execute($integrationData, $fieldValues) | ||
| { | ||
| $integrationDetails = $integrationData->flow_details; | ||
| $integId = $integrationData->id; | ||
| $fieldMap = $integrationDetails->field_map; | ||
| $utilities = isset($integrationDetails->utilities) ? $integrationDetails->utilities : []; | ||
|
|
||
| if (empty($fieldMap)) { | ||
| return new WP_Error('field_map_empty', __('Field map is empty', 'bit-integrations')); | ||
| } | ||
|
|
||
| $recordApiHelper = new RecordApiHelper($integrationDetails, $integId); | ||
|
|
||
| return $recordApiHelper->execute($fieldValues, $fieldMap, $utilities); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| <?php | ||
|
|
||
| /** | ||
| * Creator LMS Record Api | ||
| */ | ||
|
|
||
| namespace BitApps\Integrations\Actions\CreatorLms; | ||
|
|
||
| use BitApps\Integrations\Config; | ||
| use BitApps\Integrations\Core\Util\Common; | ||
| use BitApps\Integrations\Core\Util\Hooks; | ||
| use BitApps\Integrations\Log\LogHandler; | ||
|
|
||
| /** | ||
| * Provide functionality for Record insert, update | ||
| */ | ||
| class RecordApiHelper | ||
| { | ||
| private $_integrationID; | ||
|
|
||
| private $_integrationDetails; | ||
|
|
||
| public function __construct($integrationDetails, $integId) | ||
| { | ||
| $this->_integrationDetails = $integrationDetails; | ||
| $this->_integrationID = $integId; | ||
| } | ||
|
|
||
| public function execute($fieldValues, $fieldMap, $utilities) | ||
| { | ||
| if (!class_exists('CreatorLms') || !\function_exists('crlms_get_course')) { | ||
| return [ | ||
| 'success' => false, | ||
| 'message' => __('Creator LMS is not installed or activated', 'bit-integrations') | ||
| ]; | ||
| } | ||
|
|
||
| $fieldData = $this->generateReqDataFromFieldMap($fieldMap, $fieldValues); | ||
| $mainAction = $this->_integrationDetails->mainAction ?? 'create_student'; | ||
|
|
||
| $defaultResponse = [ | ||
| 'success' => false, | ||
| 'message' => wp_sprintf(__('%s plugin is not installed or activated', 'bit-integrations'), 'Bit Integrations Pro') | ||
| ]; | ||
|
|
||
| switch ($mainAction) { | ||
| case 'create_student': | ||
| $response = Hooks::apply(Config::withPrefix('creator_lms_create_student'), $defaultResponse, $fieldData); | ||
| $type = 'student'; | ||
| $actionType = 'create_student'; | ||
|
|
||
| break; | ||
| case 'update_student_data': | ||
| $response = Hooks::apply(Config::withPrefix('creator_lms_update_student_data'), $defaultResponse, $fieldData); | ||
| $type = 'student'; | ||
| $actionType = 'update_student_data'; | ||
|
|
||
| break; | ||
| case 'enroll_user_in_course': | ||
| $response = Hooks::apply(Config::withPrefix('creator_lms_enroll_user_in_course'), $defaultResponse, $fieldData); | ||
| $type = 'enrollment'; | ||
| $actionType = 'enroll_user_in_course'; | ||
|
|
||
| break; | ||
| case 'create_course': | ||
| $response = Hooks::apply(Config::withPrefix('creator_lms_create_course'), $defaultResponse, $fieldData, $this->_integrationDetails); | ||
| $type = 'course'; | ||
| $actionType = 'create_course'; | ||
|
|
||
| break; | ||
| case 'mark_lesson_completed': | ||
| $response = Hooks::apply(Config::withPrefix('creator_lms_mark_lesson_completed'), $defaultResponse, $fieldData); | ||
| $type = 'lesson'; | ||
| $actionType = 'mark_lesson_completed'; | ||
|
|
||
| break; | ||
| default: | ||
| $response = ['success' => false, 'message' => __('Invalid action', 'bit-integrations')]; | ||
| $type = 'CreatorLms'; | ||
| $actionType = 'unknown'; | ||
|
|
||
| break; | ||
| } | ||
|
|
||
| $responseType = isset($response['success']) && $response['success'] ? 'success' : 'error'; | ||
| LogHandler::save($this->_integrationID, ['type' => $type, 'type_name' => $actionType], $responseType, $response); | ||
|
|
||
| return $response; | ||
| } | ||
|
|
||
| private function generateReqDataFromFieldMap($fieldMap, $fieldValues) | ||
| { | ||
| $dataFinal = []; | ||
| foreach ($fieldMap as $item) { | ||
| $triggerValue = $item->formField; | ||
| $actionValue = $item->creatorLmsField; | ||
|
|
||
| $dataFinal[$actionValue] = $triggerValue === 'custom' && isset($item->customValue) | ||
| ? Common::replaceFieldWithValue($item->customValue, $fieldValues) | ||
| : $fieldValues[$triggerValue] ?? ''; | ||
| } | ||
|
|
||
| return $dataFinal; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <?php | ||
|
|
||
| if (!defined('ABSPATH')) { | ||
| exit; | ||
| } | ||
|
|
||
| use BitApps\Integrations\Actions\CreatorLms\CreatorLmsController; | ||
| use BitApps\Integrations\Core\Util\Route; | ||
|
|
||
| Route::post('creator_lms_authorize', [CreatorLmsController::class, 'creatorLmsAuthorize']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
frontend/src/components/AllIntegrations/CreatorLms/CreatorLms.jsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { useState } from 'react' | ||
| import 'react-multiple-select-dropdown-lite/dist/index.css' | ||
| import { useNavigate, useParams } from 'react-router-dom' | ||
| import BackIcn from '../../../Icons/BackIcn' | ||
| import { __ } from '../../../Utils/i18nwrap' | ||
| import SnackMsg from '../../Utilities/SnackMsg' | ||
| import { saveIntegConfig } from '../IntegrationHelpers/IntegrationHelpers' | ||
| import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree' | ||
| import CreatorLmsAuthorization from './CreatorLmsAuthorization' | ||
| import { checkMappedFields } from './CreatorLmsCommonFunc' | ||
| import CreatorLmsIntegLayout from './CreatorLmsIntegLayout' | ||
|
|
||
| export default function CreatorLms({ formFields, setFlow, flow, allIntegURL }) { | ||
| const navigate = useNavigate() | ||
| const { formID } = useParams() | ||
| const [isLoading, setIsLoading] = useState(false) | ||
| const [step, setStep] = useState(1) | ||
| const [snack, setSnackbar] = useState({ show: false }) | ||
| const [creatorLmsConf, setCreatorLmsConf] = useState({ | ||
| name: 'Creator LMS', | ||
| type: 'CreatorLms', | ||
| field_map: [{ formField: '', creatorLmsField: '' }], | ||
| actions: {}, | ||
| mainAction: '' | ||
| }) | ||
|
|
||
| const nextPage = val => { | ||
| setTimeout(() => { | ||
| document.getElementById('btcd-settings-wrp').scrollTop = 0 | ||
| }, 300) | ||
|
|
||
| if (val === 3) { | ||
| if (!checkMappedFields(creatorLmsConf)) { | ||
| setSnackbar({ | ||
| show: true, | ||
| msg: __('Please map all required fields to continue.', 'bit-integrations') | ||
| }) | ||
| return | ||
| } | ||
|
|
||
| if (creatorLmsConf.name !== '' && creatorLmsConf.field_map.length > 0) { | ||
| setStep(val) | ||
| } | ||
| } else { | ||
| setStep(val) | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| <div> | ||
| <SnackMsg snack={snack} setSnackbar={setSnackbar} /> | ||
| <div className="txt-center mt-2">{/* <Steps step={3} active={step} /> */}</div> | ||
|
|
||
| {/* STEP 1 */} | ||
| <CreatorLmsAuthorization | ||
| formID={formID} | ||
| creatorLmsConf={creatorLmsConf} | ||
| setCreatorLmsConf={setCreatorLmsConf} | ||
| step={step} | ||
| nextPage={nextPage} | ||
| isLoading={isLoading} | ||
| setIsLoading={setIsLoading} | ||
| setSnackbar={setSnackbar} | ||
| /> | ||
|
|
||
| {/* STEP 2 */} | ||
| <div | ||
| className="btcd-stp-page" | ||
| style={{ | ||
| width: step === 2 && 900, | ||
| height: step === 2 && 'auto', | ||
| minHeight: step === 2 && `${500}px` | ||
| }}> | ||
| <CreatorLmsIntegLayout | ||
| formID={formID} | ||
| formFields={formFields} | ||
| creatorLmsConf={creatorLmsConf} | ||
| setCreatorLmsConf={setCreatorLmsConf} | ||
| setSnackbar={setSnackbar} | ||
| setIsLoading={setIsLoading} | ||
| isLoading={isLoading} | ||
| /> | ||
| <br /> | ||
| <br /> | ||
| <br /> | ||
|
RishadAlam marked this conversation as resolved.
|
||
| <button | ||
| onClick={() => nextPage(3)} | ||
| disabled={!checkMappedFields(creatorLmsConf)} | ||
| className="btn f-right btcd-btn-lg purple sh-sm flx" | ||
| type="button"> | ||
| {__('Next', 'bit-integrations')} | ||
| <BackIcn className="ml-1 rev-icn" /> | ||
| </button> | ||
| </div> | ||
|
|
||
| {/* STEP 3 */} | ||
| <IntegrationStepThree | ||
| step={step} | ||
| saveConfig={() => | ||
| saveIntegConfig(flow, setFlow, allIntegURL, creatorLmsConf, navigate, '', '', setIsLoading) | ||
| } | ||
| isLoading={isLoading} | ||
| /> | ||
| </div> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.