Version 5.0.0 beta 1

This commit is contained in:
Neo committed 2025-12-19 16:27:35 -08:00
1 parent 25ddeb65d6
commit 15c7beabc5
6736 files changed
+627902 -497943

No files matched your search

+40 -28
View File
@@ -11,16 +11,24 @@
namespace IPS\Helpers\Form;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use IPS\Db;
use IPS\Helpers\Form\Member as FormMember;
use IPS\Member;
use function count;
use function defined;
use function is_int;
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;
}
/**
* Form builder helper to allow user-created "groups" of other users
*/
class _SocialGroup extends Member
class SocialGroup extends FormMember
{
/**
* @brief Default Options
@@ -31,7 +39,7 @@ class _SocialGroup extends Member
);
* @endcode
*/
public $childDefaultOptions = array(
public array $childDefaultOptions = array(
'multiple' => NULL,
'owner' => NULL,
);
@@ -39,49 +47,53 @@ class _SocialGroup extends Member
/**
* @brief Group ID, if already set
*/
public $groupId = NULL;
public int|array|null $groupId = NULL;
/**
* @brief Options array
*/
public array $options = array();
/**
* Constructor
*
* @param string $name Name
* @param mixed $defaultValue Default value
* @param bool|NULL $required Required? (NULL for not required, but appears to be so)
* @param array $options Type-specific options
* @param callback $customValidationCode Custom validation code
* @param string $prefix HTML to show before input field
* @param string $suffix HTML to show after input field
* @param string $id The ID to add to the row
* @return void
* @param string $name Name
* @param mixed $defaultValue Default value
* @param bool|null $required Required? (NULL for not required, but appears to be so)
* @param array $options Type-specific options
* @param callable|null $customValidationCode Custom validation code
* @param string|null $prefix HTML to show before input field
* @param string|null $suffix HTML to show after input field
* @param string|null $id The ID to add to the row
*/
public function __construct( $name, $defaultValue=NULL, $required=FALSE, $options=array(), $customValidationCode=NULL, $prefix=NULL, $suffix=NULL, $id=NULL )
public function __construct( string $name, mixed $defaultValue=NULL, ?bool $required=FALSE, array $options=array(), callable $customValidationCode=NULL, string $prefix=NULL, string $suffix=NULL, string $id=NULL )
{
/* Call parent constructor */
parent::__construct( $name, $defaultValue, $required, $options, $customValidationCode, $prefix, $suffix, $id );
/* If we are editing, the value will be a group ID we need to load */
if( \is_int( $this->value ) )
if( is_int( $this->value ) )
{
$this->groupId = $this->value;
$values = array();
foreach( \IPS\Db::i()->select( '*', 'core_sys_social_group_members', array( 'group_id=?', $this->value ) )->setKeyField('member_id')->setValueField('member_id') as $k => $v )
foreach( Db::i()->select( '*', 'core_sys_social_group_members', array( 'group_id=?', $this->value ) )->setKeyField('member_id')->setValueField('member_id') as $k => $v )
{
$values[ $k ] = \IPS\Member::load( $v );
$values[ $k ] = Member::load( $v );
}
$this->value = $values;
}
/* Make sure we have an owner...fall back to logged in member */
if( !$this->options['owner'] )
if( !isset($this->options['owner'] ) )
{
$this->options['owner'] = \IPS\Member::loggedIn();
$this->options['owner'] = Member::loggedIn();
}
else if( !$this->options['owner'] instanceof \IPS\Member AND \is_int( $this->options['owner'] ) )
else if( !$this->options['owner'] instanceof Member AND is_int( $this->options['owner'] ) )
{
$this->options['owner'] = \IPS\Member::load( $this->options['owner'] );
$this->options['owner'] = Member::load( $this->options['owner'] );
}
}
@@ -90,16 +102,16 @@ class _SocialGroup extends Member
*
* @return void
*/
public function saveValue()
public function saveValue() : void
{
/* Delete any existing entries */
if( $this->groupId )
{
\IPS\Db::i()->delete( 'core_sys_social_group_members', array( 'group_id=?', $this->groupId ) );
Db::i()->delete( 'core_sys_social_group_members', array( 'group_id=?', $this->groupId ) );
}
else if( $this->value )
{
$this->groupId = \IPS\Db::i()->insert( 'core_sys_social_groups', array( 'owner_id' => $this->options['owner']->member_id ) );
$this->groupId = Db::i()->insert( 'core_sys_social_groups', array( 'owner_id' => $this->options['owner']->member_id ) );
}
if( $this->value )
@@ -110,14 +122,14 @@ class _SocialGroup extends Member
$inserts[] = array( 'group_id' => $this->groupId, 'member_id' => $member->member_id );
}
if( \count( $inserts ) )
if( count( $inserts ) )
{
\IPS\Db::i()->insert( 'core_sys_social_group_members', $inserts );
Db::i()->insert( 'core_sys_social_group_members', $inserts );
}
}
$this->value = $this->groupId;
\IPS\Db::i()->update( 'core_members', array( 'permission_array' => NULL ) );
Db::i()->update( 'core_members', array( 'permission_array' => NULL ) );
}
}