Skip to content

Commit

Permalink
fixed phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairraeen committed Jun 27, 2024
1 parent 54e06fd commit 4839764
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 45 deletions.
181 changes: 143 additions & 38 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,55 +804,160 @@ public function qsm_check_database_structure() {

// List of tables and their columns
$tables = [
$quiz_table_name => [
'quiz_id', 'quiz_name', 'message_before', 'message_after', 'message_comment', 'message_end_template',
'user_email_template', 'admin_email_template', 'submit_button_text', 'name_field_text', 'business_field_text',
'email_field_text', 'phone_field_text', 'comment_field_text', 'email_from_text', 'question_answer_template',
'leaderboard_template', 'quiz_system', 'randomness_order', 'loggedin_user_contact', 'show_score', 'send_user_email',
'send_admin_email', 'contact_info_location', 'user_name', 'user_comp', 'user_email', 'user_phone', 'admin_email',
'comment_section', 'question_from_total', 'total_user_tries', 'total_user_tries_text', 'certificate_template',
'social_media', 'social_media_text', 'pagination', 'pagination_text', 'timer_limit', 'quiz_stye', 'question_numbering',
'quiz_settings', 'theme_selected', 'last_activity', 'require_log_in', 'require_log_in_text', 'limit_total_entries',
'limit_total_entries_text', 'scheduled_timeframe', 'scheduled_timeframe_text', 'disable_answer_onselect', 'ajax_show_correct',
'quiz_views', 'quiz_taken', 'deleted', 'quiz_author_id'
$quiz_table_name => [
'quiz_id',
'quiz_name',
'message_before',
'message_after',
'message_comment',
'message_end_template',
'user_email_template',
'admin_email_template',
'submit_button_text',
'name_field_text',
'business_field_text',
'email_field_text',
'phone_field_text',
'comment_field_text',
'email_from_text',
'question_answer_template',
'leaderboard_template',
'quiz_system',
'randomness_order',
'loggedin_user_contact',
'show_score',
'send_user_email',
'send_admin_email',
'contact_info_location',
'user_name',
'user_comp',
'user_email',
'user_phone',
'admin_email',
'comment_section',
'question_from_total',
'total_user_tries',
'total_user_tries_text',
'certificate_template',
'social_media',
'social_media_text',
'pagination',
'pagination_text',
'timer_limit',
'quiz_stye',
'question_numbering',
'quiz_settings',
'theme_selected',
'last_activity',
'require_log_in',
'require_log_in_text',
'limit_total_entries',
'limit_total_entries_text',
'scheduled_timeframe',
'scheduled_timeframe_text',
'disable_answer_onselect',
'ajax_show_correct',
'quiz_views',
'quiz_taken',
'deleted',
'quiz_author_id',
],
$question_table_name => [
'question_id', 'quiz_id', 'question_name', 'answer_array', 'answer_one', 'answer_one_points', 'answer_two',
'answer_two_points', 'answer_three', 'answer_three_points', 'answer_four', 'answer_four_points', 'answer_five',
'answer_five_points', 'answer_six', 'answer_six_points', 'correct_answer', 'question_answer_info', 'comments',
'hints', 'question_order', 'question_type', 'question_type_new', 'question_settings', 'category', 'deleted',
'deleted_question_bank'
$question_table_name => [
'question_id',
'quiz_id',
'question_name',
'answer_array',
'answer_one',
'answer_one_points',
'answer_two',
'answer_two_points',
'answer_three',
'answer_three_points',
'answer_four',
'answer_four_points',
'answer_five',
'answer_five_points',
'answer_six',
'answer_six_points',
'correct_answer',
'question_answer_info',
'comments',
'hints',
'question_order',
'question_type',
'question_type_new',
'question_settings',
'category',
'deleted',
'deleted_question_bank',
],
$results_table_name => [
'result_id', 'quiz_id', 'quiz_name', 'quiz_system', 'point_score', 'correct_score', 'correct', 'total', 'name',
'business', 'email', 'phone', 'user', 'user_ip', 'time_taken', 'time_taken_real', 'quiz_results', 'deleted',
'unique_id', 'form_type', 'page_name', 'page_url'
$results_table_name => [
'result_id',
'quiz_id',
'quiz_name',
'quiz_system',
'point_score',
'correct_score',
'correct',
'total',
'name',
'business',
'email',
'phone',
'user',
'user_ip',
'time_taken',
'time_taken_real',
'quiz_results',
'deleted',
'unique_id',
'form_type',
'page_name',
'page_url',
],
$audit_table_name => [
'trail_id', 'action_user', 'action', 'quiz_id', 'quiz_name', 'form_data', 'time'
$audit_table_name => [
'trail_id',
'action_user',
'action',
'quiz_id',
'quiz_name',
'form_data',
'time',
],
$themes_table_name => [
'id', 'theme', 'theme_name', 'default_settings', 'theme_active'
$themes_table_name => [
'id',
'theme',
'theme_name',
'default_settings',
'theme_active',
],
$quiz_themes_settings_table_name => [
'id', 'theme_id', 'quiz_id', 'quiz_theme_settings', 'active_theme'
'id',
'theme_id',
'quiz_id',
'quiz_theme_settings',
'active_theme',
],
$question_terms_table_name => [
'id',
'question_id',
'quiz_id',
'term_id',
'taxonomy',
],
$question_terms_table_name => [
'id', 'question_id', 'quiz_id', 'term_id', 'taxonomy'
]
];

// Check all tables
$errors = [];
foreach ($tables as $table_name => $columns) {
foreach ( $tables as $table_name => $columns ) {
$error = $this->qsm_check_table_structure($table_name, $columns);
if ($error) {
if ( $error ) {
$errors[] = $error;
}
}

if (!empty($errors)) {
foreach ($errors as $error) {
if ( ! empty($errors) ) {
foreach ( $errors as $error ) {
echo esc_html($error) . "<br>";
}
} else {
Expand All @@ -869,20 +974,20 @@ public function qsm_check_database_structure() {
* @param array $expected_columns
* @return string|null
*/
public function qsm_check_table_structure($table_name, $expected_columns) {
public function qsm_check_table_structure( $table_name, $expected_columns ) {
global $wpdb;
$columns = $wpdb->get_results("SHOW COLUMNS FROM $table_name");
if (!$columns) {
if ( ! $columns ) {
return esc_html__("Table ", "quiz-master-next") . $table_name . esc_html__(" does not exist.", "quiz-master-next");
}
$existing_columns = array_column($columns, 'Field');
$missing_columns = [];
foreach ($expected_columns as $column) {
if (!in_array($column, $existing_columns)) {
foreach ( $expected_columns as $column ) {
if ( ! in_array($column, $existing_columns, true) ) {
$missing_columns[] = $column;
}
}
if (!empty($missing_columns)) {
if ( ! empty($missing_columns) ) {
return esc_html__("Table ", "quiz-master-next") . $table_name . esc_html__(" is missing columns: ", "quiz-master-next") . implode(', ', $missing_columns);
}
return null;
Expand Down
14 changes: 7 additions & 7 deletions php/template-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function qsm_variable_single_answer( $content, $mlw_quiz_array ) {
$ser_answer = $wpdb->get_row( $wpdb->prepare( "SELECT question_settings FROM {$wpdb->prefix}mlw_questions WHERE question_id = %d", $question_id ), ARRAY_A );
$question_settings = qmn_sanitize_input_data( $ser_answer['question_settings'] );
$answerstr = "";
if ( isset($answers['user_answer']) && is_array($answers['user_answer']) ) {
if ( isset( $answers['user_answer'] ) && is_array( $answers['user_answer'] ) ) {
if ( 13 === intval( $answers['question_type'] ) ) {
$answerstr .= $answers['points'];
}elseif ( 12 === intval( $answers['question_type'] ) ) {
Expand Down Expand Up @@ -515,20 +515,20 @@ function qsm_all_contact_fields_variable( $content, $results ) {
if ( isset( $results['contact'] ) && ( is_array( $results['contact'] ) || is_object( $results['contact'] ) ) ) {
foreach ( $results['contact'] as $results_contact ) {
$options = qsm_get_options_of_contact_fields($contact_form, $results_contact['label'], $results_contact['type'] );
$isRadioOrSelect = in_array($results_contact['type'], ['radio', 'select']);
$hasOptions = !empty(trim($options));
$isRadioOrSelect = in_array($results_contact['type'], [ 'radio', 'select' ]);
$hasOptions = ! empty(trim($options));

if (($isRadioOrSelect && $hasOptions) || !$isRadioOrSelect) {
if ( ($isRadioOrSelect && $hasOptions) || ! $isRadioOrSelect ) {
$return .= $results_contact['label'] . ': ' . $results_contact['value'] . '<br>';
}
}
}
$content = str_replace( '%CONTACT_ALL%', $return, $content );
return $content;
}
function qsm_get_options_of_contact_fields($data, $label, $type) {
foreach ($data as $item) {
if ($item['label'] === $label && $item['type'] === $type) {
function qsm_get_options_of_contact_fields( $data, $label, $type ) {
foreach ( $data as $item ) {
if ( $item['label'] === $label && $item['type'] === $type ) {
return $item['options'];
}
}
Expand Down

0 comments on commit 4839764

Please sign in to comment.