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,78 +11,96 @@
|
||||
namespace IPS\Member;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\Data\Store;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\CheckboxSet;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Settings;
|
||||
use OutOfRangeException;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Group promotion node model
|
||||
*/
|
||||
class _GroupPromotion extends \IPS\Node\Model
|
||||
class GroupPromotion extends Model
|
||||
{
|
||||
/**
|
||||
* @brief Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_group_promotions';
|
||||
public static ?string $databaseTable = 'core_group_promotions';
|
||||
|
||||
/**
|
||||
* @brief Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'promote_';
|
||||
public static string $databasePrefix = 'promote_';
|
||||
|
||||
/**
|
||||
* @brief Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Map
|
||||
*/
|
||||
protected static $multitonMap = array();
|
||||
protected static array $multitonMap = array();
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'grouppromotions';
|
||||
public static string $nodeTitle = 'grouppromotions';
|
||||
|
||||
/**
|
||||
* @brief [Node] Sortable
|
||||
*/
|
||||
public static $nodeSortable = TRUE;
|
||||
public static bool $nodeSortable = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] Positon Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'position';
|
||||
public static ?string $databaseColumnOrder = 'position';
|
||||
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'g_promotion_';
|
||||
public static ?string $titleLangPrefix = 'g_promotion_';
|
||||
|
||||
/**
|
||||
* @brief [Node] Enabled/Disabled Column
|
||||
*/
|
||||
public static $databaseColumnEnabledDisabled = 'enabled';
|
||||
public static ?string $databaseColumnEnabledDisabled = 'enabled';
|
||||
|
||||
/**
|
||||
* Form
|
||||
*
|
||||
* @param \IPS\Helpers\Form $form The form
|
||||
* @param Form $form The form
|
||||
* @return void
|
||||
*/
|
||||
public function form( &$form )
|
||||
public function form( Form &$form ) : void
|
||||
{
|
||||
$form->addHeader( 'generic_gp_details' );
|
||||
$form->add( new \IPS\Helpers\Form\Translatable( 'promote_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'g_promotion_' . $this->id : NULL ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'promote_enabled', $this->id ? $this->enabled : 1, TRUE ) );
|
||||
$form->add( new Translatable( 'promote_title', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? 'g_promotion_' . $this->id : NULL ) ) ) );
|
||||
$form->add( new YesNo( 'promote_enabled', $this->id ? $this->enabled : 1, TRUE ) );
|
||||
|
||||
/* Loop over our member filters */
|
||||
$form->addHeader( 'generic_gp_filters' );
|
||||
@@ -93,9 +111,9 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
/* We take an extra step with groups to disable invalid options */
|
||||
$options['core_Group']['disabled_groups'] = $this->getDisabledGroups();
|
||||
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
foreach ( Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'getSettingField' ) AND $extension->availableIn( 'group_promotions' ) AND method_exists( $extension, 'matches' ) )
|
||||
if( $extension->availableIn( 'group_promotions' ) )
|
||||
{
|
||||
/* See if we need a new form header - one per app */
|
||||
$_key = explode( '_', $key );
|
||||
@@ -117,17 +135,17 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
$form->addHeader( 'generic_gp_actions' );
|
||||
$groups = array_combine( array_keys( \IPS\Member\Group::groups( TRUE, FALSE ) ), array_map( function( $_group ) { return (string) $_group; }, \IPS\Member\Group::groups( TRUE, FALSE ) ) );
|
||||
$groups = array_combine( array_keys( Group::groups( TRUE, FALSE ) ), array_map( function($_group ) { return (string) $_group; }, Group::groups( TRUE, FALSE ) ) );
|
||||
$primary = array( 0 => 'do_not_change_group' ) + $groups;
|
||||
|
||||
/* And then allow the admin to choose which groups to promote to */
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'promote_group_primary', $this->id ? $this->_actions['primary_group'] : 0, FALSE,
|
||||
$form->add( new Radio( 'promote_group_primary', $this->id ? $this->_actions['primary_group'] : 0, FALSE,
|
||||
array( 'options' => $primary ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'promote_group_secondary', $this->id ? $this->_actions['secondary_group'] : array(), FALSE,
|
||||
$form->add( new CheckboxSet( 'promote_group_secondary', $this->id ? $this->_actions['secondary_group'] : array(), FALSE,
|
||||
array( 'options' => $groups, 'multiple' => true ) ) );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\CheckboxSet( 'demote_group_secondary', $this->id ? $this->_actions['secondary_remove'] : array(), FALSE,
|
||||
$form->add( new CheckboxSet( 'demote_group_secondary', $this->id ? $this->_actions['secondary_remove'] : array(), FALSE,
|
||||
array( 'options' => $groups, 'multiple' => true ) ) );
|
||||
}
|
||||
|
||||
@@ -136,11 +154,11 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getDisabledGroups()
|
||||
protected function getDisabledGroups(): array
|
||||
{
|
||||
$return = array( \IPS\Settings::i()->guest_group );
|
||||
$return = array( Settings::i()->guest_group );
|
||||
|
||||
foreach( \IPS\Member\Group::groups() as $group )
|
||||
foreach(Group::groups() as $group )
|
||||
{
|
||||
if( $group->g_promote_exclude )
|
||||
{
|
||||
@@ -157,7 +175,7 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return array
|
||||
*/
|
||||
public function formatFormValues( $values )
|
||||
public function formatFormValues( array $values ): array
|
||||
{
|
||||
if ( !$this->id )
|
||||
{
|
||||
@@ -165,15 +183,15 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
}
|
||||
|
||||
/* Save the title */
|
||||
\IPS\Lang::saveCustom( 'core', 'g_promotion_' . $this->id, $values['promote_title'] );
|
||||
Lang::saveCustom( 'core', 'g_promotion_' . $this->id, $values['promote_title'] );
|
||||
|
||||
/* Json-encode the rules */
|
||||
$_options = array();
|
||||
|
||||
/* Loop over bulk mail extensions to format the options */
|
||||
foreach ( \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
foreach ( Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' ) as $key => $extension )
|
||||
{
|
||||
if( method_exists( $extension, 'save' ) AND $extension->availableIn( 'group_promotions' ) )
|
||||
if( $extension->availableIn( 'group_promotions' ) )
|
||||
{
|
||||
/* Grab our fields and add to the form */
|
||||
$_value = $extension->save( $values );
|
||||
@@ -197,7 +215,7 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
/* Now we have to remove any fields that aren't valid... */
|
||||
foreach( $values as $k => $v )
|
||||
{
|
||||
if( !\in_array( $k, array( 'promote_enabled', 'promote_filters', 'promote_actions', 'promote_position' ) ) )
|
||||
if( !in_array( $k, array( 'promote_enabled', 'promote_filters', 'promote_actions', 'promote_position' ) ) )
|
||||
{
|
||||
unset( $values[ $k ] );
|
||||
}
|
||||
@@ -211,7 +229,7 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get__filters()
|
||||
public function get__filters(): array
|
||||
{
|
||||
return json_decode( $this->filters, TRUE );
|
||||
}
|
||||
@@ -221,7 +239,7 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get__actions()
|
||||
public function get__actions(): array
|
||||
{
|
||||
return json_decode( $this->actions, TRUE );
|
||||
}
|
||||
@@ -230,14 +248,14 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
* Fetch All Root Nodes
|
||||
*
|
||||
* @param string|NULL $permissionCheck The permission key to check for or NULl to not check permissions
|
||||
* @param \IPS\Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param Member|NULL $member The member to check permissions for or NULL for the currently logged in member
|
||||
* @param mixed $where Additional WHERE clause
|
||||
* @param array|NULL $limit Limit/offset to use, or NULL for no limit (default)
|
||||
* @return array
|
||||
*/
|
||||
public static function roots( $permissionCheck='view', $member=NULL, $where=array(), $limit=NULL )
|
||||
public static function roots( ?string $permissionCheck='view', Member $member=NULL, mixed $where=array(), array $limit=NULL ): array
|
||||
{
|
||||
if ( !\count( $where ) )
|
||||
if ( !count( $where ) )
|
||||
{
|
||||
$return = array();
|
||||
foreach( static::getStore() AS $node )
|
||||
@@ -259,49 +277,49 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
* @return array
|
||||
* @note Note that all records are returned, even disabled promotion rules. Enable status needs to be checked in userland code when appropriate.
|
||||
*/
|
||||
public static function getStore()
|
||||
public static function getStore(): array
|
||||
{
|
||||
if ( !isset( \IPS\Data\Store::i()->group_promotions ) )
|
||||
if ( !isset( Store::i()->group_promotions ) )
|
||||
{
|
||||
\IPS\Data\Store::i()->group_promotions = iterator_to_array( \IPS\Db::i()->select( '*', static::$databaseTable, NULL, "promote_position ASC" )->setKeyField( 'promote_id' ) );
|
||||
Store::i()->group_promotions = iterator_to_array( Db::i()->select( '*', static::$databaseTable, NULL, "promote_position ASC" )->setKeyField( 'promote_id' ) );
|
||||
}
|
||||
|
||||
return \IPS\Data\Store::i()->group_promotions;
|
||||
return Store::i()->group_promotions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Caches
|
||||
* @note Defined cache keys will be cleared automatically as needed
|
||||
*/
|
||||
protected $caches = array( 'group_promotions' );
|
||||
protected array $caches = array( 'group_promotions' );
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Attempt to load from cache
|
||||
* @note If this is set to TRUE you MUST define a getStore() method to return the objects from cache
|
||||
*/
|
||||
protected static $loadFromCache = TRUE;
|
||||
protected static bool $loadFromCache = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Cache extensions so we only need to load them once
|
||||
*/
|
||||
protected static $extensions = NULL;
|
||||
protected static ?array $extensions = NULL;
|
||||
|
||||
/**
|
||||
* @brief Flag to indicate whether or not to check secondary groups
|
||||
*/
|
||||
public $memberFilterCheckSecondaryGroups = FALSE;
|
||||
public bool $memberFilterCheckSecondaryGroups = FALSE;
|
||||
|
||||
/**
|
||||
* Check if a member matches the rule
|
||||
*
|
||||
* @param \IPS\Member $member Member to check
|
||||
* @param Member $member Member to check
|
||||
* @return bool
|
||||
*/
|
||||
public function matches( \IPS\Member $member )
|
||||
public function matches( Member $member ): bool
|
||||
{
|
||||
if( static::$extensions === NULL )
|
||||
{
|
||||
static::$extensions = \IPS\Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
|
||||
static::$extensions = Application::allExtensions( 'core', 'MemberFilter', TRUE, 'core' );
|
||||
}
|
||||
|
||||
/* Did we check any matches? - It's possible that some rules are available */
|
||||
@@ -332,7 +350,7 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
*
|
||||
* @return string|NULL
|
||||
*/
|
||||
public function get__description()
|
||||
public function get__description(): ?string
|
||||
{
|
||||
$action = $this->_actions;
|
||||
$showWarning = FALSE;
|
||||
@@ -341,22 +359,22 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
{
|
||||
try
|
||||
{
|
||||
$group = \IPS\Member\Group::load( $action['primary_group'] );
|
||||
$group = Group::load( $action['primary_group'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
$showWarning = TRUE;
|
||||
}
|
||||
}
|
||||
if ( \count( $action['secondary_group'] ) )
|
||||
if ( count( $action['secondary_group'] ) )
|
||||
{
|
||||
foreach ( $action['secondary_group'] as $key => $group )
|
||||
{
|
||||
try
|
||||
{
|
||||
$group = \IPS\Member\Group::load( $group );
|
||||
$group = Group::load( $group );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
$showWarning = TRUE;
|
||||
}
|
||||
@@ -365,7 +383,9 @@ class _GroupPromotion extends \IPS\Node\Model
|
||||
|
||||
if ( $showWarning )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'grouppromotion_warning' );
|
||||
return Member::loggedIn()->language()->addToStack( 'grouppromotion_warning' );
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user