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

@@ -11,71 +11,92 @@
namespace IPS\core\StaffDirectory;
/* To prevent PHP errors (extending class does not exist) revealing path */
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
use DomainException;
use IPS\Db;
use IPS\File;
use IPS\Helpers\Form;
use IPS\Helpers\Form\Member as FormMember;
use IPS\Helpers\Form\Radio;
use IPS\Helpers\Form\Select;
use IPS\Helpers\Form\Translatable;
use IPS\Lang;
use IPS\Member;
use IPS\Member\Group;
use IPS\Node\Model;
use IPS\Request;
use IPS\Settings;
use LogicException;
use OutOfRangeException;
use UnderflowException;
use function count;
use function defined;
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;
}
/**
* Staff Directory User Node
*/
class _User extends \IPS\Node\Model
class User extends Model
{
/**
* @brief [ActiveRecord] Multiton Store
*/
protected static $multitons;
protected static array $multitons;
/**
* @brief [ActiveRecord] Database Table
*/
public static $databaseTable = 'core_leaders';
public static ?string $databaseTable = 'core_leaders';
/**
* @brief [ActiveRecord] Database Prefix
*/
public static $databasePrefix = 'leader_';
public static string $databasePrefix = 'leader_';
/**
* @brief [ActiveRecord] ID Database Column
*/
public static $databaseColumnId = 'id';
public static string $databaseColumnId = 'id';
/**
* @brief [ActiveRecord] Database ID Fields
*/
protected static $databaseIdFields = array( 'leader_type_id' );
protected static array $databaseIdFields = array( 'leader_type_id' );
/**
* @brief [ActiveRecord] Multiton Map
*/
protected static $multitonMap = array();
protected static array $multitonMap = array();
/**
* @brief [Node] Parent Node ID Database Column
*/
public static $parentNodeColumnId = 'group_id';
public static string $parentNodeColumnId = 'group_id';
/**
* @brief [Node] Parent Node Class
*/
public static $parentNodeClass = 'IPS\core\StaffDirectory\Group';
public static string $parentNodeClass = 'IPS\core\StaffDirectory\Group';
/**
* @brief [Node] Order Database Column
*/
public static $databaseColumnOrder = 'position';
public static ?string $databaseColumnOrder = 'position';
/**
* @brief [Node] Node Title
*/
public static $nodeTitle = 'staff_directory';
public static string $nodeTitle = 'staff_directory';
/**
* @brief [Node] ACP Restrictions
*/
protected static $restrictions = array(
protected static ?array $restrictions = array(
'app' => 'core',
'module' => 'staff',
'prefix' => 'leaders_',
@@ -87,7 +108,7 @@ class _User extends \IPS\Node\Model
* @param int|null $group [Optional] Group to return users from
* @return array
*/
public static function staff( $group=NULL )
public static function staff( ?int $group=NULL ) : array
{
if( $group === NULL )
{
@@ -110,12 +131,12 @@ class _User extends \IPS\Node\Model
/**
* [Node] Add/Edit 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->add( new \IPS\Helpers\Form\Radio( 'leader_type', $this->type ?: 'm', TRUE, array(
$form->add( new Radio( 'leader_type', $this->type ?: 'm', TRUE, array(
'options' => array( 'm' => 'leader_type_member', 'g' => 'leader_type_group' ),
'toggles' => array(
'm' => array( 'leader_id_member', 'leader_name_toggle', 'leader_title_toggle', 'leader_custom_bio_id' ),
@@ -123,18 +144,18 @@ class _User extends \IPS\Node\Model
),
) ) );
$form->add( new \IPS\Helpers\Form\Select( 'leader_id_group', $this->type === 'g' ? $this->type_id : NULL, FALSE, array( 'options' => \IPS\Member\Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'leader_id_group' ) );
$form->add( new \IPS\Helpers\Form\Member( 'leader_id_member', ( $this->type === 'm' AND !$this->_new ) ? \IPS\Member::load( $this->type_id )->name : NULL, FALSE, array(), function( $val )
$form->add( new Select( 'leader_id_group', $this->type === 'g' ? $this->type_id : NULL, FALSE, array( 'options' => Group::groups( TRUE, FALSE ), 'parse' => 'normal' ), NULL, NULL, NULL, 'leader_id_group' ) );
$form->add( new FormMember( 'leader_id_member', ( $this->type === 'm' AND !$this->_new ) ? Member::load( $this->type_id )->name : NULL, FALSE, array(), function( $val )
{
if ( !$val and \IPS\Request::i()->leader_type === 'm' )
if ( !$val and Request::i()->leader_type === 'm' )
{
throw new \DomainException('form_required');
throw new DomainException('form_required');
}
}, NULL, NULL, 'leader_id_member' ) );
$form->add( new \IPS\Helpers\Form\Radio( 'leader_use_custom_name', ( \IPS\Member::loggedIn()->language()->checkKeyExists("core_staff_directory_name_{$this->id}") ) ? 1 : 0, FALSE, array( 'options' => array( 0 => 'leader_custom_name_default', 1 => 'leader_custom_name_custom' ), 'toggles' => array( 1 => array( 'leader_custom_name' ) ) ), NULL, NULL, NULL, 'leader_name_toggle' ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'leader_custom_name', NULL, FALSE, array( 'app' => 'core', 'key' => ( $this->id ? "core_staff_directory_name_{$this->id}" : NULL ) ), NULL, NULL, NULL, 'leader_custom_name' ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'leader_custom_title', NULL, FALSE, array( 'app' => 'core', 'key' => ( $this->id ? "core_staff_directory_title_{$this->id}" : NULL ) ), NULL, NULL, NULL, 'leader_custom_title' ) );
$form->add( new \IPS\Helpers\Form\Translatable( 'leader_custom_bio', NULL, FALSE, array(
$form->add( new Radio( 'leader_use_custom_name', ( Member::loggedIn()->language()->checkKeyExists("core_staff_directory_name_{$this->id}") ) ? 1 : 0, FALSE, array( 'options' => array( 0 => 'leader_custom_name_default', 1 => 'leader_custom_name_custom' ), 'toggles' => array( 1 => array( 'leader_custom_name' ) ) ), NULL, NULL, NULL, 'leader_name_toggle' ) );
$form->add( new Translatable( 'leader_custom_name', NULL, FALSE, array( 'app' => 'core', 'key' => ( $this->id ? "core_staff_directory_name_{$this->id}" : NULL ) ), NULL, NULL, NULL, 'leader_custom_name' ) );
$form->add( new Translatable( 'leader_custom_title', NULL, FALSE, array( 'app' => 'core', 'key' => ( $this->id ? "core_staff_directory_title_{$this->id}" : NULL ) ), NULL, NULL, NULL, 'leader_custom_title' ) );
$form->add( new Translatable( 'leader_custom_bio', NULL, FALSE, array(
'app' => 'core',
'key' => ( $this->id ) ? "core_staff_directory_bio_{$this->id}" : NULL,
'editor' => array(
@@ -152,21 +173,21 @@ class _User extends \IPS\Node\Model
* @param array $values Values from the form
* @return array
*/
public function formatFormValues( $values )
public function formatFormValues( array $values ): array
{
if( isset( $values['leader_type'] ) )
{
try
{
if( \IPS\Db::i()->select( '*', 'core_leaders', array( 'leader_type=? AND leader_type_id=?', $values['leader_type'], $values['leader_type'] === 'm' ? $values['leader_id_member']->member_id : $values['leader_id_group'] ) )->first() )
if( Db::i()->select( '*', 'core_leaders', array( 'leader_type=? AND leader_type_id=?', $values['leader_type'], $values['leader_type'] === 'm' ? $values['leader_id_member']->member_id : $values['leader_id_group'] ) )->first() )
{
if( !$this->id OR ( $this->id AND $this->type != $values['leader_type'] OR $this->type_id != ( $values['leader_type'] === 'm' ? $values['leader_id_member']->member_id : $values['leader_id_group'] ) ) )
{
throw new \LogicException( \IPS\Member::loggedIn()->language()->addToStack("only_one_leader") );
throw new LogicException( Member::loggedIn()->language()->addToStack("only_one_leader") );
}
}
}
catch( \UnderflowException $e ){}
catch( UnderflowException $e ){}
}
if( isset( $values['leader_type'] ) AND ( isset( $values['leader_id_member'] ) OR $values['leader_id_group'] ) )
@@ -181,13 +202,13 @@ class _User extends \IPS\Node\Model
if ( !$this->id )
{
$this->save();
\IPS\File::claimAttachments( 'leader-new', $this->id, NULL, NULL, TRUE );
File::claimAttachments( 'leader-new', $this->id, NULL, NULL, TRUE );
$values['position'] = ( \IPS\Db::i()->select( 'MAX(leader_position)', 'core_leaders' )->first() + 1 );
$values['position'] = ( Db::i()->select( 'MAX(leader_position)', 'core_leaders' )->first() + 1 );
}
else
{
\IPS\File::claimAttachments( "leader-{$this->id}", $this->id, NULL, NULL, TRUE );
File::claimAttachments( "leader-{$this->id}", $this->id, NULL, NULL, TRUE );
}
$toUnset = array();
@@ -197,17 +218,17 @@ class _User extends \IPS\Node\Model
$toUnset[] = 'leader_use_custom_name';
$toUnset[] = 'leader_custom_name';
\IPS\Lang::deleteCustom( 'core', "core_staff_directory_name_{$this->id}" );
Lang::deleteCustom( 'core', "core_staff_directory_name_{$this->id}" );
}
if( isset( $values['leader_custom_name'] ) AND isset( $values['leader_use_custom_name'] ) AND $values['leader_use_custom_name'] )
{
\IPS\Lang::saveCustom( 'core', "core_staff_directory_name_{$this->id}", $values['leader_custom_name'] );
Lang::saveCustom( 'core', "core_staff_directory_name_{$this->id}", $values['leader_custom_name'] );
}
if( isset( $values['leader_custom_title'] ) )
{
\IPS\Lang::saveCustom( 'core', "core_staff_directory_title_{$this->id}", $values['leader_custom_title'] );
Lang::saveCustom( 'core', "core_staff_directory_title_{$this->id}", $values['leader_custom_title'] );
unset( $values['leader_custom_title'] );
}
@@ -216,11 +237,11 @@ class _User extends \IPS\Node\Model
$toUnset[] = 'leader_custom_bio';
if ( isset ( $values['leader_custom_bio'] ) )
{
\IPS\Lang::saveCustom( 'core', "core_staff_directory_bio_{$this->id}", $values['leader_custom_bio'] );
Lang::saveCustom( 'core', "core_staff_directory_bio_{$this->id}", $values['leader_custom_bio'] );
}
}
if( \count( $toUnset ) )
if( count( $toUnset ) )
{
foreach( $toUnset as $_key )
{
@@ -236,7 +257,7 @@ class _User extends \IPS\Node\Model
*
* @return string
*/
protected function get__title()
protected function get__title(): string
{
if ( !$this->id )
{
@@ -245,29 +266,29 @@ class _User extends \IPS\Node\Model
if ( $this->type === 'm' )
{
if( \IPS\Member::loggedIn()->language()->checkKeyExists("core_staff_directory_name_{$this->id}") and \IPS\Member::loggedIn()->language()->get("core_staff_directory_name_{$this->id}") )
if( Member::loggedIn()->language()->checkKeyExists("core_staff_directory_name_{$this->id}") and Member::loggedIn()->language()->get("core_staff_directory_name_{$this->id}") )
{
return \IPS\Member::loggedIn()->language()->addToStack( "core_staff_directory_name_{$this->id}", FALSE, array( 'escape' => TRUE ) );
return Member::loggedIn()->language()->addToStack( "core_staff_directory_name_{$this->id}", FALSE, array( 'escape' => TRUE ) );
}
$member = \IPS\Member::load( $this->type_id );
$member = Member::load( $this->type_id );
if( $member->member_id )
{
return $member->name;
}
return \IPS\Member::loggedIn()->language()->addToStack('deleted_member');
return Member::loggedIn()->language()->addToStack('deleted_member');
}
else
{
try
{
return \IPS\Member\Group::load( $this->type_id )->name;
return Group::load( $this->type_id )->name;
}
catch( \OutOfRangeException $e )
catch( OutOfRangeException $e )
{
return \IPS\Member::loggedIn()->language()->addToStack('deleted_group');
return Member::loggedIn()->language()->addToStack('deleted_group');
}
}
}
@@ -277,7 +298,7 @@ class _User extends \IPS\Node\Model
*
* @return string
*/
protected function get__icon()
protected function get__icon(): mixed
{
return $this->type === 'm' ? 'fa-user' : 'fa-group';
}
@@ -285,18 +306,18 @@ class _User extends \IPS\Node\Model
/**
* @brief Member
*/
public $member;
public ?Member $member = null;
/**
* Get member data for user
*
* @return \IPS\Member
* @return Member
*/
public function member()
public function member() : Member
{
if ( $this->member === NULL )
{
$this->member = \IPS\Member::load( $this->type_id );
$this->member = Member::load( $this->type_id );
}
return $this->member;
@@ -307,7 +328,7 @@ class _User extends \IPS\Node\Model
*
* @return bool
*/
public function canAdd()
public function canAdd(): bool
{
return FALSE;
}
@@ -317,7 +338,7 @@ class _User extends \IPS\Node\Model
*
* @return bool
*/
public function canCopy()
public function canCopy(): bool
{
return FALSE;
}
@@ -327,7 +348,7 @@ class _User extends \IPS\Node\Model
*
* @return bool
*/
public function canManagePermissions()
public function canManagePermissions(): bool
{
return FALSE;
}
@@ -335,11 +356,11 @@ class _User extends \IPS\Node\Model
/**
* Delete
*
* @return void
* @return void
*/
public function delete()
public function delete(): void
{
\IPS\File::unclaimAttachments( 'core_Staffdirectory', $this->id );
File::unclaimAttachments( 'core_Staffdirectory', $this->id );
parent::delete();
static::updateEmptySetting();
}
@@ -347,9 +368,9 @@ class _User extends \IPS\Node\Model
/**
* Save Changed Columns
*
* @return void
* @return void
*/
public function save()
public function save(): void
{
parent::save();
static::updateEmptySetting( FALSE );
@@ -361,14 +382,13 @@ class _User extends \IPS\Node\Model
* @param bool|NULL $value If we already know the value (because we've just set it), will save a query
* @return void
*/
public static function updateEmptySetting( $value = NULL )
public static function updateEmptySetting( ?bool $value = NULL ) : void
{
if ( $value == NULL )
{
/* @note SELECT_FROM_WRITE_SERVER Added in fa59a59 to account for a race condition */
$value = !( (bool) \IPS\Db::i()->select( 'COUNT(*)', 'core_leaders', NULL, NULL, NULL, NULL, NULL, \IPS\Db::SELECT_FROM_WRITE_SERVER )->first() );
$value = !( Db::i()->select( 'COUNT(*)', 'core_leaders', NULL, NULL, NULL, NULL, NULL, Db::SELECT_FROM_WRITE_SERVER )->first() );
}
\IPS\Settings::i()->changeValues( array( 'staff_directory_empty' => $value ) );
Settings::i()->changeValues( array( 'staff_directory_empty' => $value ) );
}
}