Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -11,27 +11,45 @@
|
||||
namespace IPS\nexus\extensions\core\ProfileSteps;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\ProfileStepsAbstract;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Editor;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Member\ProfileStep;
|
||||
use IPS\nexus\Customer\CustomField;
|
||||
use IPS\Output;
|
||||
use IPS\Theme;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
use function substr;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Profile fields extension
|
||||
*/
|
||||
class _CustomerFields
|
||||
class CustomerFields extends ProfileStepsAbstract
|
||||
{
|
||||
/**
|
||||
* Available parent actions to complete steps
|
||||
*
|
||||
* @return array array( 'key' => 'lang_string' )
|
||||
*/
|
||||
public static function actions()
|
||||
public static function actions(): array
|
||||
{
|
||||
$return = array();
|
||||
|
||||
if ( \IPS\Db::i()->select( 'COUNT(*)', 'nexus_customer_fields' )->first() )
|
||||
if ( Db::i()->select( 'COUNT(*)', 'nexus_customer_fields' )->first() )
|
||||
{
|
||||
$return['customer_fields'] = 'complete_profile_app__nexus_CustomerFields';
|
||||
}
|
||||
@@ -44,13 +62,13 @@ class _CustomerFields
|
||||
*
|
||||
* @return array array( 'key' => 'lang_string' )
|
||||
*/
|
||||
public static function subActions()
|
||||
public static function subActions(): array
|
||||
{
|
||||
$return = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( '*', 'nexus_customer_fields' ) as $field )
|
||||
foreach( Db::i()->select( '*', 'nexus_customer_fields' ) as $field )
|
||||
{
|
||||
$field = \IPS\nexus\Customer\CustomField::constructFromData( $field );
|
||||
$field = CustomField::constructFromData( $field );
|
||||
$return['customer_fields'][ 'nexus_ccfield_' . $field->_id ] = 'nexus_ccfield_' . $field->_id;
|
||||
}
|
||||
|
||||
@@ -61,9 +79,9 @@ class _CustomerFields
|
||||
* Can the actions have multiple choices?
|
||||
*
|
||||
* @param string $action Action key (basic_profile, etc)
|
||||
* @return boolean
|
||||
* @return bool|null
|
||||
*/
|
||||
public static function actionMultipleChoice( $action )
|
||||
public static function actionMultipleChoice( string $action ): ?bool
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
@@ -74,7 +92,7 @@ class _CustomerFields
|
||||
* @return array
|
||||
* @note This is intended for items which have their own independent settings and dedicated enable pages, such as MFA and Social Login integration
|
||||
*/
|
||||
public static function canBeRequired()
|
||||
public static function canBeRequired(): array
|
||||
{
|
||||
return array( 'customer_fields' );
|
||||
}
|
||||
@@ -82,13 +100,13 @@ class _CustomerFields
|
||||
/**
|
||||
* Has a specific step been completed?
|
||||
*
|
||||
* @param \IPS\Member\ProfileStep $step The step to check
|
||||
* @param \IPS\Member|NULL $member The member to check, or NULL for currently logged in
|
||||
* @param ProfileStep $step The step to check
|
||||
* @param Member|NULL $member The member to check, or NULL for currently logged in
|
||||
* @return bool
|
||||
*/
|
||||
public function completed( \IPS\Member\ProfileStep $step, \IPS\Member $member = NULL )
|
||||
public function completed( ProfileStep $step, Member $member = NULL ): bool
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
|
||||
if ( !$member->member_id )
|
||||
{
|
||||
@@ -96,14 +114,14 @@ class _CustomerFields
|
||||
}
|
||||
try
|
||||
{
|
||||
$profileFields = iterator_to_array( \IPS\Db::i()->select( '*', 'nexus_customers', array( 'member_id=?', $member->member_id ) ) );
|
||||
$profileFields = iterator_to_array( Db::i()->select( '*', 'nexus_customers', array( 'member_id=?', $member->member_id ) ) );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ( ! \count( $profileFields ) )
|
||||
if ( ! count( $profileFields ) )
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -111,13 +129,13 @@ class _CustomerFields
|
||||
$done = 0;
|
||||
foreach( $step->subcompletion_act as $item )
|
||||
{
|
||||
$fieldId = \substr( $item, 14 );
|
||||
$fieldId = substr( $item, 14 );
|
||||
|
||||
foreach( $profileFields AS $key => $value )
|
||||
{
|
||||
if ( $key == 'field_' . $fieldId )
|
||||
{
|
||||
if ( (bool) $value )
|
||||
if ( $value )
|
||||
{
|
||||
$done++;
|
||||
}
|
||||
@@ -125,38 +143,38 @@ class _CustomerFields
|
||||
}
|
||||
}
|
||||
|
||||
return ( $done === \count( $step->subcompletion_act ) );
|
||||
return ( $done === count( $step->subcompletion_act ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Action URL
|
||||
*
|
||||
* @param string $action The action
|
||||
* @param \IPS\Member|NULL $member The member, or NULL for currently logged in
|
||||
* @return \IPS\Http\Url
|
||||
* @param Member|NULL $member The member, or NULL for currently logged in
|
||||
* @return Url|null
|
||||
*/
|
||||
public function url( $action, \IPS\Member $member = NULL )
|
||||
public function url( string $action, Member $member = NULL ): ?Url
|
||||
{
|
||||
return \IPS\Http\Url::internal( "app=core&module=members&controller=profile&do=edit&id={$member->member_id}", 'front', 'edit_profile', $member->members_seo_name );
|
||||
return Url::internal( "app=core&module=members&controller=profile&do=edit&id={$member->member_id}", 'front', 'edit_profile', $member->members_seo_name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Post ACP Save
|
||||
*
|
||||
* @param \IPS\Member\ProfileStep $step The step
|
||||
* @param ProfileStep $step The step
|
||||
* @param array $values Form Values
|
||||
* @return void
|
||||
*/
|
||||
public function postAcpSave( \IPS\Member\ProfileStep $step, array $values )
|
||||
public function postAcpSave( ProfileStep $step, array $values ) : void
|
||||
{
|
||||
$subActions = static::subActions()['customer_fields'];
|
||||
|
||||
/* If we are going to add a profile field to a step, or even require it, we need to make sure the actual field is updated */
|
||||
foreach( $subActions AS $key )
|
||||
{
|
||||
if ( \in_array( $key, $values['step_subcompletion_act'] ) )
|
||||
if ( in_array( $key, $values['step_subcompletion_act'] ) )
|
||||
{
|
||||
$fieldId = \substr( $key, 14 );
|
||||
$fieldId = substr( $key, 14 );
|
||||
$update = array();
|
||||
$update['f_reg_show'] = 1;
|
||||
if ( $step->required )
|
||||
@@ -164,7 +182,7 @@ class _CustomerFields
|
||||
$update['f_reg_require'] = 1;
|
||||
}
|
||||
|
||||
\IPS\Db::i()->update( 'nexus_customer_fields', $update, array( "f_id=?", $fieldId ) );
|
||||
Db::i()->update( 'nexus_customer_fields', $update, array( "f_id=?", $fieldId ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -173,44 +191,42 @@ class _CustomerFields
|
||||
* Format Form Values
|
||||
*
|
||||
* @param array $values The form values
|
||||
* @param \IPS\Member $member The member
|
||||
* @param \IPS\Helpers\Form $form The form object
|
||||
* @param Member $member The member
|
||||
* @param Form $form The form object
|
||||
* @return void
|
||||
*/
|
||||
public static function formatFormValues( $values, &$member, &$form )
|
||||
public static function formatFormValues( array $values, Member $member, Form $form ) : void
|
||||
{
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
|
||||
$profileFields = array();
|
||||
foreach ( \IPS\nexus\Customer\CustomField::roots() as $field )
|
||||
foreach ( CustomField::roots() as $field )
|
||||
{
|
||||
if ( isset( $values[ "nexus_ccfield_{$field->_id}"] ) )
|
||||
{
|
||||
if( $field->required and ( $values[ "nexus_ccfield_{$field->_id}" ] === NULL or !isset( $values[ "nexus_ccfield_{$field->_id}" ] ) ) )
|
||||
{
|
||||
\IPS\Output::i()->error( 'reg_required_fields', '1C223/5', 403, '' );
|
||||
Output::i()->error( 'reg_required_fields', '1C223/5', 403, '' );
|
||||
}
|
||||
|
||||
$helper = $field->buildHelper();
|
||||
$profileFields[ "field_{$field->_id}" ] = $helper::stringValue( $values[ "nexus_ccfield_{$field->_id}" ] );
|
||||
|
||||
if ( $helper instanceof \IPS\Helpers\Form\Editor )
|
||||
if ( $helper instanceof Editor )
|
||||
{
|
||||
$field->claimAttachments( $member->member_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $profileFields ) )
|
||||
if ( count( $profileFields ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
\IPS\Db::i()->select( 'member_id', 'nexus_customers', array( "member_id=?", $member->member_id ) )->first();
|
||||
\IPS\Db::i()->update( 'nexus_customers', $profileFields, array( "member_id=?", $member->member_id ) );
|
||||
Db::i()->select( 'member_id', 'nexus_customers', array( "member_id=?", $member->member_id ) )->first();
|
||||
Db::i()->update( 'nexus_customers', $profileFields, array( "member_id=?", $member->member_id ) );
|
||||
}
|
||||
catch( \Exception $e )
|
||||
catch( Exception )
|
||||
{
|
||||
\IPS\Db::i()->insert( 'nexus_customers', array_merge( array( 'member_id' => $member->member_id ), array_merge( array( 'member_id' => $member->member_id ), $profileFields ) ) );
|
||||
Db::i()->insert( 'nexus_customers', array_merge( array( 'member_id' => $member->member_id ), $profileFields ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,26 +234,26 @@ class _CustomerFields
|
||||
/**
|
||||
* Wizard Steps
|
||||
*
|
||||
* @param \IPS\Member|NULL $member The member completing the wizard, or NULL for currently logged in member
|
||||
* @return array
|
||||
* @param Member|NULL $member The member completing the wizard, or NULL for currently logged in member
|
||||
* @return array|string
|
||||
*/
|
||||
public static function wizard( \IPS\Member $member = NULL )
|
||||
public static function wizard( Member $member = NULL ): array|string
|
||||
{
|
||||
$include = array();
|
||||
$member = $member ?: \IPS\Member::loggedIn();
|
||||
$member = $member ?: Member::loggedIn();
|
||||
$wizards = array();
|
||||
|
||||
foreach( \IPS\Member\ProfileStep::loadAll() AS $step )
|
||||
foreach( ProfileStep::loadAll() AS $step )
|
||||
{
|
||||
if ( $step->completion_act === 'customer_fields' AND ! $step->completed( $member ) )
|
||||
{
|
||||
$wizards[ $step->key ] = function( $data ) use ( $member, $include, $step ) {
|
||||
$form = new \IPS\Helpers\Form( 'customer_profile_fields_' . $step->id, 'profile_complete_next' );
|
||||
$form = new Form( 'customer_profile_fields_' . $step->id, 'profile_complete_next' );
|
||||
|
||||
foreach( $step->subcompletion_act as $item )
|
||||
{
|
||||
$id = \substr( $item, 14 );
|
||||
$field = \IPS\nexus\Customer\CustomField::load( $id );
|
||||
$id = substr( $item, 14 );
|
||||
$field = CustomField::load( $id );
|
||||
$form->add( $field->buildHelper() );
|
||||
}
|
||||
|
||||
@@ -249,47 +265,49 @@ class _CustomerFields
|
||||
return $values;
|
||||
}
|
||||
|
||||
return $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'forms', 'core' ), 'profileCompleteTemplate' ), $step );
|
||||
return $form->customTemplate( array( Theme::i()->getTemplate( 'forms', 'core' ), 'profileCompleteTemplate' ), $step );
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $wizards ) )
|
||||
if ( count( $wizards ) )
|
||||
{
|
||||
return $wizards;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resyncs when something external happens
|
||||
*
|
||||
* @param \IPS\Member\ProfileStep $step The step
|
||||
* @param ProfileStep $step The step
|
||||
* @return void
|
||||
*/
|
||||
public function resync( \IPS\Member\ProfileStep $step )
|
||||
public function resync( ProfileStep $step ) : void
|
||||
{
|
||||
$subActions = array();
|
||||
|
||||
foreach( $step->subcompletion_act as $item )
|
||||
{
|
||||
$fieldId = \substr( $item, 12 );
|
||||
$fieldId = substr( $item, 12 );
|
||||
try
|
||||
{
|
||||
\IPS\nexus\Customer\CustomField::load( $fieldId );
|
||||
CustomField::load( $fieldId );
|
||||
$subActions[] = $item;
|
||||
}
|
||||
catch( \OutOfRangeException $e )
|
||||
catch( OutOfRangeException )
|
||||
{
|
||||
/* No longer exists.. */
|
||||
}
|
||||
}
|
||||
|
||||
if ( \count( $subActions ) and \count( $subActions ) != $step->subcompletion_act )
|
||||
if ( count( $subActions ) and count( $subActions ) != $step->subcompletion_act )
|
||||
{
|
||||
$step->subcompletion_act = $subActions;
|
||||
$step->save();
|
||||
}
|
||||
else if ( ! \count( $subActions ) )
|
||||
else if ( ! count( $subActions ) )
|
||||
{
|
||||
/* No fields left, so delete this */
|
||||
$step->delete();
|
||||
|
||||
Reference in new issue
Block a user