Skip to content
Open
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* Quiz And Survey Master Integration
*/

namespace BitApps\Integrations\Actions\QuizAndSurveyMaster;

use WP_Error;

class QuizAndSurveyMasterController
{
public static function isExists()
{
if (!\defined('QSM_PLUGIN_PATH')) {
wp_send_json_error(
__(
'Quiz And Survey Master is not activated or not installed',
'bit-integrations'
),
400
);
}
}

public static function quizAndSurveyMasterAuthorize()
{
self::isExists();

wp_send_json_success(true);
}

public function refreshThemes()
{
self::isExists();

global $wpdb;

$themes = array_map(
function ($theme) {
return (object) [
'value' => (string) $theme->id,
'label' => (string) $theme->theme_name,
];
},
$wpdb->get_results("SELECT id, theme_name FROM {$wpdb->prefix}mlw_themes") ?: []
);

wp_send_json_success(['themes' => $themes], 200);
}

public function refreshQuestionTypes()
{
self::isExists();

global $mlwQuizMasterNext;

$questionTypes = [];

if (isset($mlwQuizMasterNext->pluginHelper->question_types)) {
foreach ($mlwQuizMasterNext->pluginHelper->question_types as $slug => $type) {
$questionTypes[] = (object) [
'value' => (string) $slug,
'label' => (string) ($type['name'] ?? $slug),
];
}
}

wp_send_json_success(['questionTypes' => $questionTypes], 200);
}

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);
}
}
130 changes: 130 additions & 0 deletions backend/Actions/QuizAndSurveyMaster/RecordApiHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/**
* Quiz And Survey Master Record Api
*/

namespace BitApps\Integrations\Actions\QuizAndSurveyMaster;

use BitApps\Integrations\Config;
use BitApps\Integrations\Core\Util\Common;
use BitApps\Integrations\Core\Util\Hooks;
use BitApps\Integrations\Log\LogHandler;

class RecordApiHelper
{
private $_integrationID;

private $_integrationDetails;

public function __construct($integrationDetails, $integId)
{
$this->_integrationDetails = $integrationDetails;
$this->_integrationID = $integId;
}

public function execute($fieldValues, $fieldMap, $utilities)
{
if (!\defined('QSM_PLUGIN_PATH')) {
return [
'success' => false,
'message' => __('Quiz And Survey Master is not installed or activated', 'bit-integrations')
];
}

$fieldData = static::generateReqDataFromFieldMap($fieldMap, $fieldValues);

$mainAction = $this->_integrationDetails->mainAction ?? '';

$defaultResponse = [
'success' => false,
// translators: %s: Plugin name
'message' => wp_sprintf(__('%s plugin is not installed or activate', 'bit-integrations'), 'Bit Integrations Pro')
];

switch ($mainAction) {
case 'create_quiz':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_create_quiz'), $defaultResponse, $fieldData, $utilities);
$type = 'quiz';

break;

case 'update_quiz_name':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_update_quiz_name'), $defaultResponse, $fieldData);
$type = 'quiz';

break;

case 'duplicate_quiz':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_duplicate_quiz'), $defaultResponse, $fieldData, $utilities);
$type = 'quiz';

break;

case 'delete_quiz':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_delete_quiz'), $defaultResponse, $fieldData, $utilities);
$type = 'quiz';

break;

case 'create_question':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_create_question'), $defaultResponse, $fieldData, $utilities, $this->_integrationDetails);
$type = 'question';

break;

case 'update_question':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_update_question'), $defaultResponse, $fieldData, $utilities, $this->_integrationDetails);
$type = 'question';

break;

case 'delete_question':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_delete_question'), $defaultResponse, $fieldData);
$type = 'question';

break;

case 'delete_result':
$response = Hooks::apply(Config::withPrefix('quiz_and_survey_master_delete_result'), $defaultResponse, $fieldData, $utilities);
$type = 'result';

break;

default:
$response = [
'success' => false,
'message' => __('No Quiz And Survey Master action selected', 'bit-integrations')
];
$type = 'quiz';

break;
}

$responseType = isset($response['success']) && $response['success'] ? 'success' : 'error';

LogHandler::save($this->_integrationID, ['type' => $type, 'type_name' => $mainAction], $responseType, $response);

return $response;
}

protected static function generateReqDataFromFieldMap($fieldMap, $fieldValues)
{
$dataFinal = [];

foreach ($fieldMap as $item) {
$triggerValue = $item->formField;
$actionValue = $item->quizAndSurveyMasterField;

if (empty($actionValue)) {
continue;
}

$dataFinal[$actionValue] = $triggerValue === 'custom' && isset($item->customValue)
? Common::replaceFieldWithValue($item->customValue, $fieldValues)
: $fieldValues[$triggerValue] ?? '';
}

return $dataFinal;
}
}
12 changes: 12 additions & 0 deletions backend/Actions/QuizAndSurveyMaster/Routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

if (!defined('ABSPATH')) {
exit;
}

use BitApps\Integrations\Actions\QuizAndSurveyMaster\QuizAndSurveyMasterController;
use BitApps\Integrations\Core\Util\Route;

Route::post('quiz_and_survey_master_authorize', [QuizAndSurveyMasterController::class, 'quizAndSurveyMasterAuthorize']);
Route::post('refresh_quiz_and_survey_master_themes', [QuizAndSurveyMasterController::class, 'refreshThemes']);
Route::post('refresh_quiz_and_survey_master_question_types', [QuizAndSurveyMasterController::class, 'refreshQuestionTypes']);
1 change: 1 addition & 0 deletions backend/Core/Util/AllTriggersName.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public static function allTriggersName()
'ProfileGrid' => ['name' => 'ProfileGrid', 'isPro' => true, 'is_active' => false],
'ProfilePress' => ['name' => 'ProfilePress', 'isPro' => true, 'is_active' => false],
'QuillForms' => ['name' => 'Quill Forms', 'isPro' => true, 'is_active' => false],
'QuizAndSurveyMaster' => ['name' => 'Quiz And Survey Master (QSM)', 'isPro' => true, 'is_active' => false],
'Rafflepress' => ['name' => 'Rafflepress', 'isPro' => true, 'is_active' => false],
'PeepSo' => ['name' => 'PeepSo', 'isPro' => true, 'is_active' => false],
'Registration' => ['name' => 'WP User Registration', 'isPro' => true, 'is_active' => false],
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/AllIntegrations/EditInteg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const EditBookly = lazy(() => import('./Bookly/EditBookly'))
const EditSureContact = lazy(() => import('./SureContact/EditSureContact'))
const EditBrilliantDirectories = lazy(() => import('./BrilliantDirectories/EditBrilliantDirectories'))
const EditFluentCart = lazy(() => import('./FluentCart/EditFluentCart'))
const EditQuizAndSurveyMaster = lazy(() => import('./QuizAndSurveyMaster/EditQuizAndSurveyMaster'))
const EditPointics = lazy(() => import('./Pointics/EditPointics'))
const EditSenseiLMS = lazy(() => import('./SenseiLMS/EditSenseiLMS'))
const EditConvertForce = lazy(() => import('./ConvertForce/EditConvertForce'))
Expand Down Expand Up @@ -669,6 +670,8 @@ const IntegType = memo(({ allIntegURL, flow }) => {
return <EditBrilliantDirectories allIntegURL={allIntegURL} />
case 'FluentCart':
return <EditFluentCart allIntegURL={allIntegURL} />
case 'QuizAndSurveyMaster':
return <EditQuizAndSurveyMaster allIntegURL={allIntegURL} />
case 'Pointics':
return <EditPointics allIntegURL={allIntegURL} />
case 'SenseiLMS':
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/components/AllIntegrations/IntegInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ const BrilliantDirectoriesAuthorization = lazy(
() => import('./BrilliantDirectories/BrilliantDirectoriesAuthorization')
)
const FluentCartAuthorization = lazy(() => import('./FluentCart/FluentCartAuthorization'))
const QuizAndSurveyMasterAuthorization = lazy(
() => import('./QuizAndSurveyMaster/QuizAndSurveyMasterAuthorization')
)
const PointicsAuthorization = lazy(() => import('./Pointics/PointicsAuthorization'))
const SenseiLMSAuthorization = lazy(() => import('./SenseiLMS/SenseiLMSAuthorization'))
const ConvertForceAuthorization = lazy(() => import('./ConvertForce/ConvertForceAuthorization'))
Expand Down Expand Up @@ -697,6 +700,10 @@ const IntegrationInfo = memo(({ integrationConf, location, editUrl }) => {
)
case 'FluentCart':
return <FluentCartAuthorization fluentCartConf={integrationConf} step={1} isInfo />
case 'QuizAndSurveyMaster':
return (
<QuizAndSurveyMasterAuthorization quizAndSurveyMasterConf={integrationConf} step={1} isInfo />
)
case 'Pointics':
return <PointicsAuthorization pointicsConf={integrationConf} step={1} isInfo />
case 'SenseiLMS':
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/components/AllIntegrations/NewInteg.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ const Bookly = lazy(() => import('./Bookly/Bookly'))
const SureContact = lazy(() => import('./SureContact/SureContact'))
const BrilliantDirectories = lazy(() => import('./BrilliantDirectories/BrilliantDirectories'))
const FluentCart = lazy(() => import('./FluentCart/FluentCart'))
const QuizAndSurveyMaster = lazy(() => import('./QuizAndSurveyMaster/QuizAndSurveyMaster'))
const Pointics = lazy(() => import('./Pointics/Pointics'))
const SenseiLMS = lazy(() => import('./SenseiLMS/SenseiLMS'))
const ConvertForce = lazy(() => import('./ConvertForce/ConvertForce'))
Expand Down Expand Up @@ -1813,6 +1814,15 @@ const NewIntegs = memo(({ integUrlName, allIntegURL, flow, setFlow }) => {
setFlow={setFlow}
/>
)
case 'QuizAndSurveyMaster':
return (
<QuizAndSurveyMaster
allIntegURL={allIntegURL}
formFields={flow?.triggerData?.fields}
flow={flow}
setFlow={setFlow}
/>
)
case 'Pointics':
return (
<Pointics
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { useState } from 'react'
import { useNavigate, useParams } from 'react-router'
import { useRecoilState, useRecoilValue } from 'recoil'
import { $actionConf, $formFields, $newFlow } from '../../../GlobalStates'
import { __ } from '../../../Utils/i18nwrap'
import SnackMsg from '../../Utilities/SnackMsg'
import { saveActionConf } from '../IntegrationHelpers/IntegrationHelpers'
import IntegrationStepThree from '../IntegrationHelpers/IntegrationStepThree'
import SetEditIntegComponents from '../IntegrationHelpers/SetEditIntegComponents'
import { checkMappedFields, handleInput } from './QuizAndSurveyMasterCommonFunc'
import QuizAndSurveyMasterIntegLayout from './QuizAndSurveyMasterIntegLayout'

export default function EditQuizAndSurveyMaster({ allIntegURL }) {
const navigate = useNavigate()
const { id, formID } = useParams()

const [quizAndSurveyMasterConf, setQuizAndSurveyMasterConf] = useRecoilState($actionConf)
const [flow, setFlow] = useRecoilState($newFlow)
const formFields = useRecoilValue($formFields)
const [isLoading, setIsLoading] = useState(false)
const [snack, setSnackbar] = useState({ show: false })

return (
<div style={{ width: 900 }}>
<SnackMsg snack={snack} setSnackbar={setSnackbar} />

<div className="flx mt-3">
<b className="wdt-200 d-in-b">{__('Integration Name:', 'bit-integrations')}</b>
<input
className="btcd-paper-inp w-5"
onChange={e => handleInput(e, quizAndSurveyMasterConf, setQuizAndSurveyMasterConf)}
name="name"
value={quizAndSurveyMasterConf.name}
type="text"
placeholder={__('Integration Name...', 'bit-integrations')}
/>
</div>
<br />

<SetEditIntegComponents entity={flow.triggered_entity} setSnackbar={setSnackbar} />

<QuizAndSurveyMasterIntegLayout
formID={formID}
formFields={formFields}
quizAndSurveyMasterConf={quizAndSurveyMasterConf}
setQuizAndSurveyMasterConf={setQuizAndSurveyMasterConf}
setSnackbar={setSnackbar}
setIsLoading={setIsLoading}
isLoading={isLoading}
/>

<IntegrationStepThree
edit
saveConfig={() =>
saveActionConf({
flow,
setFlow,
allIntegURL,
conf: quizAndSurveyMasterConf,
navigate,
id,
edit: 1,
setIsLoading,
setSnackbar
})
}
disabled={!checkMappedFields(quizAndSurveyMasterConf)}
isLoading={isLoading}
dataConf={quizAndSurveyMasterConf}
setDataConf={setQuizAndSurveyMasterConf}
formFields={formFields}
/>
<br />
</div>
)
}
Loading
Loading