From 889676b1eb18bb83823511ab92c93f7664063d06 Mon Sep 17 00:00:00 2001 From: Hugo Solar Date: Thu, 16 Jul 2020 09:21:15 -0400 Subject: [PATCH] process to hold application when application is voted 'no' --- .../admin/assets/css/admin_styles.css | 2 +- .../admin/user-application-page.php | 93 ++++++++++++------- .../cc-global-network/cc-global-network.php | 6 ++ .../includes/gravityforms-interaction.php | 3 +- themes/cc-commoners-2019/functions.php | 2 +- 5 files changed, 70 insertions(+), 36 deletions(-) diff --git a/plugins/cc-global-network/admin/assets/css/admin_styles.css b/plugins/cc-global-network/admin/assets/css/admin_styles.css index 8a9d009..45e479f 100644 --- a/plugins/cc-global-network/admin/assets/css/admin_styles.css +++ b/plugins/cc-global-network/admin/assets/css/admin_styles.css @@ -226,7 +226,7 @@ table.ccgn-profile tr td.title { font-size: .7rem; } .applicant-columns .ccgn-box .applicant-reason { - width: 15rem; + max-width: 15rem; } .preview-details { margin-bottom: 2rem; diff --git a/plugins/cc-global-network/admin/user-application-page.php b/plugins/cc-global-network/admin/user-application-page.php index 73ec9da..42c1922 100644 --- a/plugins/cc-global-network/admin/user-application-page.php +++ b/plugins/cc-global-network/admin/user-application-page.php @@ -227,31 +227,45 @@ function ccgn_application_mc_review_submit_handler( $entry, $form ) { ); update_user_meta($applicant_id, 'ccgn-user-mc-review', $user_meta); if ( ccgn_current_user_is_membership_council() || ccgn_current_user_is_final_approver() ) { + $was_voted_no = get_user_meta( $applicant_id, 'ccgn-application-voted-no', true ); if ( $entry[ CCGN_GF_MC_REVIEW_RESULT ] == 'Yes' ) { $choose_vouchers_entry = ccgn_application_vouchers($applicant_id); $no_voucher = ''; $first_voucher = ccgn_vouches_for_applicant_by_voucher( $applicant_id, $choose_vouchers_entry[1] ); $second_voucher = ccgn_vouches_for_applicant_by_voucher( $applicant_id, $choose_vouchers_entry[2] ); - - ccgn_registration_user_set_stage( $applicant_id, CCGN_APPLICATION_STATE_UPDATE_VOUCHERS ); - $update_date = date('Y-m-d H:i:s', strtotime('now')); - - if ( $first_voucher[0][CCGN_GF_VOUCH_DO_YOU_VOUCH] == 'No' ) { - $vouch = $first_voucher[0]; - } elseif ( $second_voucher[0][CCGN_GF_VOUCH_DO_YOU_VOUCH] == 'No' ) { - $vouch = $second_voucher[0]; + if ( $was_voted_no['status'] ) { + $no_vote_entry_id = $was_voted_no['entry_id']; + $no_vote_restore = array( + 'status' => false, + 'entry_id' => false, + 'date' => date('Y-m-d H:i:s', strtotime('now')) + ); + update_user_meta($applicant_id, 'ccgn-application-voted-no', $no_vote_restore); + if (!empty($no_vote_entry_id)) { + GFAPI::delete_entry( $no_vote_entry_id ); + } + ccgn_registration_user_set_stage( $applicant_id, CCGN_APPLICATION_STATE_VOUCHING ); + } else { + ccgn_registration_user_set_stage( $applicant_id, CCGN_APPLICATION_STATE_UPDATE_VOUCHERS ); + $update_date = date('Y-m-d H:i:s', strtotime('now')); + + if ( $first_voucher[0][CCGN_GF_VOUCH_DO_YOU_VOUCH] == 'No' ) { + $vouch = $first_voucher[0]; + } elseif ( $second_voucher[0][CCGN_GF_VOUCH_DO_YOU_VOUCH] == 'No' ) { + $vouch = $second_voucher[0]; + } + $vouch[CCGN_GF_VOUCH_DO_YOU_VOUCH] = CCGN_GF_VOUCH_DO_YOU_VOUCH_REMOVED; + GFAPI::update_entry($vouch); + ccgn_set_entry_update_date($vouch, $update_date); + // Update the date on the Choose Vouchers form, resetting the timescale + // for updating voucher choices + ccgn_set_entry_update_date( $choose_vouchers_entry, $update_date ); + ccgn_registration_email_to_applicant ( + $applicant_id, + 'ccgn-email-mc-review-update-vouchers', + $entry[ CCGN_GF_MC_REVIEW_NOTE ] + ); } - $vouch[CCGN_GF_VOUCH_DO_YOU_VOUCH] = CCGN_GF_VOUCH_DO_YOU_VOUCH_REMOVED; - GFAPI::update_entry($vouch); - ccgn_set_entry_update_date($vouch, $update_date); - // Update the date on the Choose Vouchers form, resetting the timescale - // for updating voucher choices - ccgn_set_entry_update_date( $choose_vouchers_entry, $update_date ); - ccgn_registration_email_to_applicant ( - $applicant_id, - 'ccgn-email-mc-review-update-vouchers', - $entry[ CCGN_GF_MC_REVIEW_NOTE ] - ); } elseif ( $entry[ CCGN_GF_MC_REVIEW_RESULT ] == 'No' ) { ccgn_decline_and_notify_applicant( $applicant_id ); } @@ -263,8 +277,9 @@ function ccgn_application_mc_review_submit_handler( $entry, $form ) { // Handle vote form results function ccgn_application_users_page_vote_form_submit_handler ( $entry, - $form ) { - if ( $form[ 'title' ] == CCGN_GF_VOTE ) { + $form ) { + $applicant_id = $entry[ '4' ]; + if (!empty($applicant_id)) { if (! ( ccgn_current_user_is_membership_council() || ccgn_current_user_is_final_approver() ) ) { echo 'Must be Membership Council member.'; @@ -277,16 +292,25 @@ function ccgn_application_users_page_vote_form_submit_handler ( $entry, echo 'Cannot Vote on Application you are a Voucher for.'; exit; } - $applicant_id = $entry[ CCGN_GF_VOTE_APPLICANT_ID ]; $stage = ccgn_registration_user_get_stage( $applicant_id); if ( $stage != CCGN_APPLICATION_STATE_VOUCHING ) { echo 'User already post-approved (or updating vouchers)'; return; } + if ($entry[CCGN_GF_VOTE_APPROVE_MEMBERSHIP_APPLICATION] == 'No') { + _ccgn_registration_user_set_stage( $applicant_id, CCGN_APPLICATION_STATE_REVIEW ); + $user_vote_no = array( + 'status' => true, + 'entry_id' => $entry['id'], + 'date' => date('Y-m-d H:i:s', strtotime('now')) + ); + update_user_meta($applicant_id, 'ccgn-application-voted-no', $user_vote_no ); + } } } function ccgn_application_users_page_vote_form ( $applicant_id ) { + if ( ccgn_vouching_request_exists( $applicant_id, get_current_user_id() ) ) { echo _('You have been asked to Vouch for this application, you therefore cannot Vote on it as well.'); @@ -547,7 +571,8 @@ function ccgn_application_users_page_render_state ( $applicant_id, $state ) { } elseif ( $state == '' ) { echo _('

New User.

'); echo _("

They haven't completed an application yet.

"); - } elseif ( $state == CCGN_APPLICATION_STATE_REVIEW ) { + } + if ( $state == CCGN_APPLICATION_STATE_REVIEW ) { echo _('

To be reviewed by Membership Comitee.

'); echo _("

This application needs to be reviewed by the Membership Comitee.

"); ccgn_application_mc_review_form($applicant_id); @@ -647,16 +672,18 @@ function ccgn_application_users_page_render_details ( $applicant_id, $state ) { $who_asked = ''; if (empty($asked_info['user_id'])) { $log_user = ccgn_ask_clarification_log_get_id($applicant_id); - foreach ($log_user as $entry) { - $asked_meta = get_user_meta($entry['voucher_id'], 'ccgn_need_to_clarify_vouch_reason_applicant_status', true); - if (($asked_meta['status'] == 1) && ($entry['voucher_id'] == $voucher['id'])) { - $user_is_asked_for_clarification = 1; - $asked_class = 'asked-box'; - $who_asked = (!empty($asked_info['ask_user'])) ? get_user_by('ID',$asked_info['ask_user'])->display_name : $entry['ask_user_name']; - } else if (($asked_meta['status'] == 0) && ($entry['voucher_id'] == $voucher['id'])) { - $user_is_asked_for_clarification = 2; - $asked_class = 'asked-box-answered'; - $who_asked = (!empty($asked_info['ask_user'])) ? get_user_by('ID',$asked_info['ask_user'])->display_name : $entry['ask_user_name']; + if (!empty($log_user)) { + foreach ($log_user as $entry) { + $asked_meta = get_user_meta($entry['voucher_id'], 'ccgn_need_to_clarify_vouch_reason_applicant_status', true); + if (($asked_meta['status'] == 1) && ($entry['voucher_id'] == $voucher['id'])) { + $user_is_asked_for_clarification = 1; + $asked_class = 'asked-box'; + $who_asked = (!empty($asked_info['ask_user'])) ? get_user_by('ID',$asked_info['ask_user'])->display_name : $entry['ask_user_name']; + } else if (($asked_meta['status'] == 0) && ($entry['voucher_id'] == $voucher['id'])) { + $user_is_asked_for_clarification = 2; + $asked_class = 'asked-box-answered'; + $who_asked = (!empty($asked_info['ask_user'])) ? get_user_by('ID',$asked_info['ask_user'])->display_name : $entry['ask_user_name']; + } } } diff --git a/plugins/cc-global-network/cc-global-network.php b/plugins/cc-global-network/cc-global-network.php index ea1fed9..8bdb585 100644 --- a/plugins/cc-global-network/cc-global-network.php +++ b/plugins/cc-global-network/cc-global-network.php @@ -316,6 +316,12 @@ function ccgn_sanitize_user_not_strict($user, $raw_user, $strict) 10, 2 ); + add_action( + 'gform_after_submission_43', + 'ccgn_application_users_page_vote_form_submit_handler', + 10, + 2 + ); add_action( 'gform_after_submission', 'ccgn_application_users_page_legal_approval_form_submit_handler', diff --git a/plugins/cc-global-network/includes/gravityforms-interaction.php b/plugins/cc-global-network/includes/gravityforms-interaction.php index a7e5d1b..e436dc1 100644 --- a/plugins/cc-global-network/includes/gravityforms-interaction.php +++ b/plugins/cc-global-network/includes/gravityforms-interaction.php @@ -965,7 +965,8 @@ function ccgn_application_vouches_counts($applicant_id) function ccgn_application_can_be_voted($applicant_id) { $vouches = ccgn_application_vouches_counts($applicant_id); - if ($vouches['yes'] >= 2) { + $votes = ccgn_application_votes_counts( $applicant_id ); + if ( ($vouches['yes'] >= 2) && ($votes['yes'] < 5) ) { return true; } else { return false; diff --git a/themes/cc-commoners-2019/functions.php b/themes/cc-commoners-2019/functions.php index b263e45..adee2f5 100644 --- a/themes/cc-commoners-2019/functions.php +++ b/themes/cc-commoners-2019/functions.php @@ -276,4 +276,4 @@ function enqueue_scripts(){ * Instantiate the class object * */ -$_s = site::get_instance(); \ No newline at end of file +$_s = site::get_instance();