created functions to handle all state changes
This commit is contained in:
290
plugins/cipf_plugin/php/profs_states.php
Normal file
290
plugins/cipf_plugin/php/profs_states.php
Normal file
@@ -0,0 +1,290 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* [/] etat compte ('etat_compte') :
|
||||
* 1. new . 'nouveau prof' -> ok : [1: a l'inscription - ok]
|
||||
* 2. to_pay . 'doit payer' -> ko : [1: apres premier form - ok], [2: apres form qui suit carte expiree - ok], [3: apres paiement immediat echoue - ko], [4: apres virement echoue - ko]
|
||||
* 3. valid . 'carte valide' ->
|
||||
* 4. waiting_invalid . 'en attente invalide' ->
|
||||
* 5. waiting_valid . 'en attente valide' ->
|
||||
* 6. expired . 'carte expiree' ->
|
||||
*
|
||||
* [/] etat carte ('etat_carte') :
|
||||
* - 'Commande'
|
||||
* - 'Renouvellement'
|
||||
*
|
||||
* [ ] activation du compte ('compte-actif') :
|
||||
* - 'Actif' -> equivalent a etat compte [3] carte valide
|
||||
* - 'Inactif' -> equivalent a etat compte [2] doit payer
|
||||
*
|
||||
* [/] etat paiement ('etat_paiement') :
|
||||
* - 'en_cours'
|
||||
* - 'reussi'
|
||||
* - 'echec'
|
||||
* - 'aucun'
|
||||
*
|
||||
* [/] type paiement ('paiement') :
|
||||
* - 'Paypal'
|
||||
* - 'Virement'
|
||||
*
|
||||
* [/] numero de carte ('numero_de_la_carte')
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* global 'setter' and 'izzer' for this file
|
||||
*
|
||||
*/
|
||||
function is_acf_state_CIPF($user_id = null, $acf_field, $state_name) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
$acf_state = get_field($acf_field['_name'], $acf_id);
|
||||
|
||||
if ($acf_state === $acf_field[$state_name]) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function set_acf_state_CIPF($user_id = null, $acf_field, $state_name) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
update_field($acf_field['_name'], $acf_field[$state_name], $acf_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* etat compte ('etat_compte') :
|
||||
* 1. new . 'nouveau prof' -> ok : [1: a l'inscription - ok]
|
||||
* 2. to_pay . 'doit payer' -> ko : [1: apres premier form - ok], [2: apres form qui suit carte expiree - ok], [3: apres paiement immediat echoue - ko], [4: apres virement echoue - ko]
|
||||
* 3. valid . 'carte valide' ->
|
||||
* 4. waiting_invalid . 'en attente invalide' ->
|
||||
* 5. waiting_valid . 'en attente valide' ->
|
||||
* 6. expired . 'carte expiree' ->
|
||||
*
|
||||
* receives the name of the state, and compare it to the current state
|
||||
* either use the is_acf_card_state_CIPF() function directly,
|
||||
* or one of the specific functions
|
||||
*
|
||||
*/
|
||||
function is_account_state_CIPF($user_id = null, $state_name) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
|
||||
return is_acf_state_CIPF($user_id, $acf_account_state, $state_name);
|
||||
}
|
||||
function is_account_new_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_account_state_CIPF($user_id, 'new');
|
||||
}
|
||||
function is_account_to_pay_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_account_state_CIPF($user_id, 'to_pay');
|
||||
}
|
||||
function is_account_valid_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_account_state_CIPF($user_id, 'valid');
|
||||
}
|
||||
function is_account_waiting_invalid_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_account_state_CIPF($user_id, 'waiting_invalid');
|
||||
}
|
||||
function is_account_waiting_valid_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_account_state_CIPF($user_id, 'waiting_valid');
|
||||
}
|
||||
function is_account_expired_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_account_state_CIPF($user_id, 'expired');
|
||||
}
|
||||
/*
|
||||
* setters :
|
||||
*/
|
||||
function set_account_state_CIPF($user_id = null, $state_name) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
|
||||
set_acf_state_CIPF($user_id, $acf_account_state, $state_name);
|
||||
}
|
||||
function set_account_new_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_account_state_CIPF($user_id, 'new');
|
||||
}
|
||||
function set_account_to_pay_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_account_state_CIPF($user_id, 'to_pay');
|
||||
}
|
||||
function set_account_valid_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_account_state_CIPF($user_id, 'valid');
|
||||
}
|
||||
function set_account_waiting_invalid_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_account_state_CIPF($user_id, 'waiting_invalid');
|
||||
}
|
||||
function set_account_waiting_valid_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_account_state_CIPF($user_id, 'waiting_valid');
|
||||
}
|
||||
function set_account_expired_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_account_state_CIPF($user_id, 'expired');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* etat carte ('etat_carte') :
|
||||
* - 'Commande'
|
||||
* - 'Renouvellement'
|
||||
*
|
||||
*/
|
||||
function is_card_new_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
return is_acf_state_CIPF($user_id, $acf_card_state, 'new');
|
||||
}
|
||||
function is_card_renew_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
return is_acf_state_CIPF($user_id, $acf_card_state, 'renew');
|
||||
}
|
||||
function set_card_new_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
set_acf_state_CIPF($user_id, $acf_card_state, 'new');
|
||||
}
|
||||
function set_card_renew_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
set_acf_state_CIPF($user_id, $acf_card_state, 'renew');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* type paiement ('paiement') :
|
||||
* - 'paypal'=>'Paypal'
|
||||
* - 'transfert'=>'Virement'
|
||||
*
|
||||
*/
|
||||
function is_payment_method_paypal_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
return is_acf_state_CIPF($user_id, $acf_card_payment_method, 'paypal');
|
||||
}
|
||||
function is_payment_method_transfert_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_method = PLGNTLS_class::ACF_CARD_PAYMENT_METHOD;
|
||||
return is_acf_state_CIPF($user_id, $acf_card_payment_method, 'transfert');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* etat paiement ('etat_paiement') :
|
||||
* - 'en_cours'
|
||||
* - 'reussi'
|
||||
* - 'echec'
|
||||
* - 'aucun'
|
||||
*
|
||||
* 'started'=>'en_cours', 'success'=>'reussi', 'failure'=>'echec', 'nothing'=>'aucun'
|
||||
*
|
||||
*/
|
||||
function is_payment_state_CIPF($user_id = null, $type) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_state = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
||||
return is_acf_state_CIPF($user_id, $acf_card_payment_state, $type);
|
||||
}
|
||||
function is_payment_started($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_payment_state_CIPF($user_id, 'started');
|
||||
}
|
||||
function is_payment_success($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_payment_state_CIPF($user_id, 'success');
|
||||
}
|
||||
function is_payment_failure($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_payment_state_CIPF($user_id, 'failure');
|
||||
}
|
||||
function is_payment_nothing($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
return is_payment_state_CIPF($user_id, 'nothing');
|
||||
}
|
||||
/*
|
||||
* setters
|
||||
*/
|
||||
function set_payment_state_CIPF($user_id = null, $type) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_payment_state = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
||||
set_acf_state_CIPF($user_id, $acf_card_payment_state, $type);
|
||||
}
|
||||
function set_payment_started($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_payment_state_CIPF($user_id, 'started');
|
||||
}
|
||||
function set_payment_success($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_payment_state_CIPF($user_id, 'success');
|
||||
}
|
||||
function set_payment_failure($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_payment_state_CIPF($user_id, 'failure');
|
||||
}
|
||||
function set_payment_nothing($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
set_payment_state_CIPF($user_id, 'nothing');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
function set_card_number_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_card_number = PLGNTLS_class::ACF_CARD_NUMBER;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
|
||||
$card_id = $date_now->format('Ymd') . $user_id;
|
||||
update_field($acf_card_number['_name'], $card_id, $acf_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user