Skip to content

Commit 814c287

Browse files
committed
add option to track institutional agreements
1 parent f3d4b65 commit 814c287

File tree

5 files changed

+78
-1
lines changed

5 files changed

+78
-1
lines changed

plugins/cc-global-network/admin/user-application-page.php

+50
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,55 @@ function ccgn_application_mc_review_form ( $applicant_id ) {
215215
);
216216
}
217217
}
218+
function ccgn_application_institutional_agreement_form ( $applicant_id, $state ) {
219+
if ( ccgn_current_user_is_legal_team() && ($state == CCGN_APPLICATION_STATE_LEGAL ) ) {
220+
echo '<h2>Institutional Agreement</h2>';
221+
$institutional_agreement_meta = get_user_meta($applicant_id, 'ccgn-institutional-agreement', true);
222+
if (!empty($institutional_agreement_meta) && ($institutional_agreement_meta['status'] == 'sent-agreement')) {
223+
$now = new DateTime('now');
224+
$agreement_date = new DateTime($institutional_agreement_meta['date']);
225+
echo '<p>Agreement sent: '.date('Y-m-d',strtotime($institutional_agreement_meta['date'])).' ('.$agreement_date->diff($now)->days.' days ago)';
226+
}
227+
$existing_entry = ccgn_entries_referring_to_user (
228+
$applicant_id,
229+
CCGN_GF_INSTITUTIONAL_AGREEMENT,
230+
CCGN_GF_INSTITUTIONAL_AGREEMENT_ID
231+
)[0];
232+
gravity_form(
233+
CCGN_GF_INSTITUTIONAL_AGREEMENT,
234+
false,
235+
false,
236+
false,
237+
array(
238+
CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX_PARAMETER
239+
=> $existing_entry[
240+
CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX
241+
],
242+
CCGN_GF_INSTITUTIONAL_AGREEMENT_ID_PARAMETER
243+
=> $applicant_id
244+
)
245+
);
246+
}
247+
}
248+
function ccgn_application_institutional_agreement_submit_handler( $entry, $form ) {
249+
if ( $form[ 'title' ] == CCGN_GF_INSTITUTIONAL_AGREEMENT ) {
250+
$applicant_id = $entry[ CCGN_GF_INSTITUTIONAL_AGREEMENT_ID ];
251+
if ($entry[ CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX ] == 'yes') {
252+
//The institutional agreement has been sent
253+
$institutional_agreement_meta = array(
254+
'status' => 'sent-agreement',
255+
'date' => date('Y-m-d H:i:s', strtotime('now')),
256+
);
257+
update_user_meta($applicant_id, 'ccgn-institutional-agreement', $institutional_agreement_meta);
258+
} else {
259+
$institutional_agreement_meta = array(
260+
'status' => 'agreement-not-sent',
261+
'date' => date('Y-m-d H:i:s', strtotime('now')),
262+
);
263+
update_user_meta($applicant_id, 'ccgn-institutional-agreement', $institutional_agreement_meta);
264+
}
265+
}
266+
}
218267
function ccgn_application_mc_review_submit_handler( $entry, $form ) {
219268
if ( $form[ 'title' ] == CCGN_GF_MC_REVIEW ) {
220269
$applicant_id = $entry[ CCGN_GF_MC_REVIEW_APPLICANT_ID ];
@@ -811,6 +860,7 @@ function ccgn_application_users_page () {
811860
ccgn_application_users_page_render_details( $applicant_id, $state );
812861
ccgn_application_users_page_render_state( $applicant_id, $state );
813862
if ( ccgn_user_is_institutional_applicant( $applicant_id ) ) {
863+
ccgn_application_institutional_agreement_form( $applicant_id, $state );
814864
ccgn_application_format_legal_approval( $applicant_id, $state );
815865
}
816866
}

plugins/cc-global-network/cc-global-network.php

+7
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ function ccgn_sanitize_user_not_strict($user, $raw_user, $strict)
255255
2
256256
);
257257

258+
add_action(
259+
'gform_after_submission',
260+
'ccgn_application_institutional_agreement_submit_handler',
261+
10,
262+
2
263+
);
264+
258265
////////////////////////////////////////////////////////////////////////////////
259266
// Forms for existing members
260267
////////////////////////////////////////////////////////////////////////////////

plugins/cc-global-network/cron/remove-marked-users.php

+13-1
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,30 @@ function ccgn_check_accounts_to_be_removed()
4545
CCGN_APPLICATION_STATE_DELETE,
4646
CCGN_APPLICATION_STATE_DIDNT_UPDATE_VOUCHERS,
4747
CCGN_APPLICATION_STATE_CHARTER,
48-
CCGN_APPLICATION_STATE_DETAILS
48+
CCGN_APPLICATION_STATE_DETAILS,
49+
CCGN_APPLICATION_STATE_LEGAL
4950
);
5051
$now = new DateTime('now');
5152
foreach ($states_to_delete as $state) {
5253
$applicants = ccgn_applicant_ids_with_state( $state );
5354
foreach ($applicants as $applicant_id) {
55+
if ( $state == CCGN_APPLICATION_STATE_LEGAL) {
56+
$stage = get_user_meta($applicant_id, 'ccgn-institutional-agreement', true);
57+
if (!empty($stage) && ($stage['status'] == 'sent-agreement')) {
58+
$agreement_date = new DateTime($stage['date']);
59+
$days_in_state = $agreement_date->diff($now)->days;
60+
if ($days_in_state > CCGN_REMOVE_APPLICATION_AFTER_DAYS) {
61+
ccgn_close_and_remove_retention_data_applicant($applicant_id);
62+
}
63+
}
64+
} else {
5465
$status_date = get_user_meta($applicant_id, 'ccgn-application-state-date', true);
5566
$state_date = new DateTime($status_date);
5667
$days_in_state = $state_date->diff($now)->days;
5768
if ($days_in_state > CCGN_REMOVE_APPLICATION_AFTER_DAYS) {
5869
ccgn_close_and_remove_retention_data_applicant($applicant_id);
5970
}
71+
}
6072
}
6173
}
6274
}

plugins/cc-global-network/includes/application-state.php

+2
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ function ccgn_applicant_type_desc ( $user_id ) {
108108
define( 'CCGN_APPLICATION_STATE_REVIEW', 'to-be-reviewed' );
109109
// This state applies to the new data retention policy, which should retain the data for no more than 30 days
110110
define('CCGN_APPLICATION_STATE_DELETE', 'to-be-deleted' );
111+
//legal is waiting for institutional agreement 30 days countdown to be deleted
112+
define('CCGN_APPLICATION_STATE_INSTITUTIONAL_AGREEMENT', 'waiting-institutional-agreement' );
111113

112114
define(
113115
'CCGN_APPLICATION_STATE_CAN_BE_PRE_APPROVED',

plugins/cc-global-network/includes/gravityforms-interaction.php

+6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
define('CCGN_GF_VOUCH', 'Vouch For Applicant');
3333
define('CCGN_GF_MC_REVIEW', 'MC user review');
34+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT', 'Institutional Agreement');
3435

3536
// Admin approval of applicant
3637

@@ -208,6 +209,11 @@
208209
define('CCGN_GF_MC_REVIEW_NOTE_PARAMETER', 'mc-review-note');
209210
define('CCGN_GF_MC_REVIEW_APPLICANT_ID_PARAMETER', 'applicant_id');
210211

212+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX', '1.1');
213+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_CHECKBOX_PARAMETER', 'institutional_agreement_sent');
214+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_ID', '2');
215+
define('CCGN_GF_INSTITUTIONAL_AGREEMENT_ID_PARAMETER', 'applicant_id');
216+
211217
// Field values that we need to check
212218

213219
define('CCGN_GF_VOUCH_DO_YOU_VOUCH_YES', 'Yes');

0 commit comments

Comments
 (0)