CRM V2

WPCrm
in package

Class de gestion des users en session avec Wordpress

Tags
category

API

subpackage

Wordpress

author

Jérémy Munsch jeremy.munsch@ldc.fr

license

MIT https://opensource.org/licenses/MIT

link
/

Table of Contents

$api  : CrmApiV2
The user object
$user  : WPCrmUser
The user object
$sessionDestroyed  : bool
The session live status
$sessionKey  : string
The session key name
activateUser()  : bool
Toggle the current user optin value on the current user and the crm
check()  : bool
Check if the user is logged in.
deleteUser()  : bool
Delete current customer from the local database and the crm
forceLogin()  : WPCrmUser|null
Manually login a user If self::$user is already set.
getNewUser()  : WPCrmUser
Generate a new user
getUser()  : WPCrmUser|null
Get the current user return null if the user is not logged in
getUserFromApi()  : WPCrmUser|false
Get the current user return api response code if an error occurs
getUserFromTable()  : array<string|int, mixed>|null
Get a customer from table
getUserFromTableByEmail()  : array<string|int, mixed>|null
Get a customer from table by an email
getUserFromTableByUuid()  : array<string|int, mixed>|null
Get a customer from table by an email
login()  : bool
Try to login with CRM API A session will be started if credentials are valid.
logout()  : void
Destroy the customer from session and therefore logout
saveUser()  : bool
Save current customer to the local database and on crm
setSingleOptin()  : bool
Set the single optin status for an email on the crm
toggleUserOptin()  : bool
Toggle the current user optin value on the current user and the crm
unsetActiveUser()  : void
Remove active user to prevent WPCrm::check to return true
bootSessionIfNeeded()  : void
Boot the php session if needed
deleteUserFromTable()  : int
Save or update the user to the table
getCustomer()  : Customer|null
Get all customer infos
getWpDb()  : object
Get WP 'pdo instance'
initLdcApi()  : CrmApiV2
Get the initialized API object
loginUserWithApi()  : bool
Check customer credentials using the CRM.
makeApiV2Call()  : mixed|false
Make a call using apiV2
query()  : int|bool
Query in DB
saveOrUpdateUserToTable()  : int
Save or update the user to the table
setUser()  : void
Create a user stores it to the session and finally saves it to the database if it does not exists

Properties

$sessionDestroyed

The session live status

private static bool $sessionDestroyed = false

$sessionKey

The session key name

private static string $sessionKey = null

Methods

activateUser()

Toggle the current user optin value on the current user and the crm

public static activateUser() : bool
Tags
throws
ValidationException

If a customer's hashcode could not be validated.

throws
CrmException

If an error occurs on server side or on getting response.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs. Possibles are : - modelNotFound, If this customer hashcode could not be found. - customerAlreadyActive, It the customer is already activated.

Return values
bool —

True if the operation succeeded.

check()

Check if the user is logged in.

public static check() : bool

This means he has an active valid session.

Return values
bool —

deleteUser()

Delete current customer from the local database and the crm

public static deleteUser() : bool
Tags
throws
CrmException

If a critical error occured.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs. Possibles are : - modelNotFound, If this customer hashcode could not be found.

phpcs:ignore

Squiz.Commenting.FunctionCommentThrowTag.WrongNumber

Return values
bool —

true if the operation succeeded

forceLogin()

Manually login a user If self::$user is already set.

public static forceLogin() : WPCrmUser|null
Return values
WPCrmUser|null —

getUser()

Get the current user return null if the user is not logged in

public static getUser() : WPCrmUser|null
Return values
WPCrmUser|null —

getUserFromApi()

Get the current user return api response code if an error occurs

public static getUserFromApi(string $identification) : WPCrmUser|false
Parameters
$identification : string

The customer hashcode or email.

Tags
throws
CrmException

If an error occurs on server side or on getting response.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs.

phpcs:ignore

Squiz.Commenting.FunctionCommentThrowTag.WrongNumber

Return values
WPCrmUser|false —

getUserFromTable()

Get a customer from table

public static getUserFromTable(string $hashcode) : array<string|int, mixed>|null
Parameters
$hashcode : string

The customer hashcode.

Return values
array<string|int, mixed>|null —

Database query result in format specified by $output or null on failure.

getUserFromTableByEmail()

Get a customer from table by an email

public static getUserFromTableByEmail(string $email) : array<string|int, mixed>|null
Parameters
$email : string

The customer email.

Return values
array<string|int, mixed>|null —

Database query result in format specified by $output or null on failure.

getUserFromTableByUuid()

Get a customer from table by an email

public static getUserFromTableByUuid(string $uuid) : array<string|int, mixed>|null
Parameters
$uuid : string

The customer transaction uuid.

Return values
array<string|int, mixed>|null —

Database query result in format specified by $output or null on failure.

login()

Try to login with CRM API A session will be started if credentials are valid.

public static login(string $email, string $password) : bool
Parameters
$email : string

The customer email.

$password : string

The customer password.

Tags
throws
CrmException

If an error occurs on server side or on getting response.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs. Possibles are : - authFailed, If credentials are not valid. - customerNotActivated, If the account is not activated.

Return values
bool —

logout()

Destroy the customer from session and therefore logout

public static logout() : void
Return values
void —

saveUser()

Save current customer to the local database and on crm

public static saveUser() : bool
Tags
throws
CrmException

If a critical error occured.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs. Possibles are : - validationFailed, If provided data is wrong(CRM side). - modelNotFound, If this customer hashcode could not be found.

phpcs:ignore

Squiz.Commenting.FunctionCommentThrowTag.WrongNumber

Return values
bool —

true if the operation succeeded false otherwise

setSingleOptin()

Set the single optin status for an email on the crm

public static setSingleOptin(string $email, bool $opt_in) : bool
Parameters
$email : string
$opt_in : bool
Tags
throws
ValidationException

If a field email could not be validated.

throws
CrmException

If an error occurs on server side or on getting response.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs. Possibles are : - singleOptinCustomerExists, If a customer exists with this email.

Return values
bool —

true if the operation succeeded false otherwise

toggleUserOptin()

Toggle the current user optin value on the current user and the crm

public static toggleUserOptin() : bool
Tags
throws
CrmException

If a critical error occured.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs. Possibles are : - modelNotFound, If this customer hashcode could not be found.

phpcs:ignore

Squiz.Commenting.FunctionCommentThrowTag.WrongNumber

Return values
bool —

true if the operation succeeded

unsetActiveUser()

Remove active user to prevent WPCrm::check to return true

public static unsetActiveUser() : void
Return values
void —

bootSessionIfNeeded()

Boot the php session if needed

private static bootSessionIfNeeded() : void
Return values
void —

deleteUserFromTable()

Save or update the user to the table

private static deleteUserFromTable() : int
Return values
int —

The number of row removed from the table.

getCustomer()

Get all customer infos

private static getCustomer() : Customer|null
Return values
Customer|null —

getWpDb()

Get WP 'pdo instance'

private static getWpDb() : object
Return values
object —

The $wpdb variable

initLdcApi()

Get the initialized API object

private static initLdcApi() : CrmApiV2
Tags
throws
ErrorException

If php does not have extension curl.

Return values
CrmApiV2 —

loginUserWithApi()

Check customer credentials using the CRM.

private static loginUserWithApi(string $email, string $password) : bool
Parameters
$email : string

The customer email.

$password : string

The customer password.

Tags
throws
CrmException

If an error occurs on server side or on getting response.

throws
ApiErrorException

If any error or \LDC\LDCCRM\Enums\ApiError occurs. Possibles are : - authFailed, If credentials are not valid. - customerNotActivated, If the account is not activated.

Return values
bool —

makeApiV2Call()

Make a call using apiV2

private static makeApiV2Call(object|string $obj, string $method[, array<string|int, mixed> $arguments = [] ]) : mixed|false
Parameters
$obj : object|string

An object or a class name.

$method : string

The method to call.

$arguments : array<string|int, mixed> = []

Arguments to pass.

Tags
throws
ApiErrorException

If any of this exception is thrown.

throws
CrmException

If a critical error occured.

Return values
mixed|false —

query()

Query in DB

private static query(string $query[, array<string|int, mixed> $params = [] ]) : int|bool
Parameters
$query : string

La request avec les variables en points d'interrogation.

$params : array<string|int, mixed> = []

Les paramètres des la requète.

Return values
int|bool —

Boolean true for CREATE, ALTER, TRUNCATE and DROP queries. Number of rows affected/selected for all other queries. Boolean false on error.

saveOrUpdateUserToTable()

Save or update the user to the table

private static saveOrUpdateUserToTable() : int
Return values
int —

The number of row affected on the table.

setUser()

Create a user stores it to the session and finally saves it to the database if it does not exists

private static setUser(Customer $customer) : void
Parameters
$customer : Customer
Return values
void —

Search results