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,56 +11,71 @@
|
||||
namespace IPS\core\Warnings;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\File;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Custom;
|
||||
use IPS\Helpers\Form\Editor;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Helpers\Form\Translatable;
|
||||
use IPS\Helpers\Form\YesNo;
|
||||
use IPS\Lang;
|
||||
use IPS\Member;
|
||||
use IPS\Node\Model;
|
||||
use IPS\Theme;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Warning Reason Node
|
||||
*/
|
||||
class _Reason extends \IPS\Node\Model
|
||||
class Reason extends Model
|
||||
{
|
||||
/**
|
||||
* @brief [ActiveRecord] Multiton Store
|
||||
*/
|
||||
protected static $multitons;
|
||||
protected static array $multitons;
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Table
|
||||
*/
|
||||
public static $databaseTable = 'core_members_warn_reasons';
|
||||
public static ?string $databaseTable = 'core_members_warn_reasons';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] Database Prefix
|
||||
*/
|
||||
public static $databasePrefix = 'wr_';
|
||||
public static string $databasePrefix = 'wr_';
|
||||
|
||||
/**
|
||||
* @brief [ActiveRecord] ID Database Column
|
||||
*/
|
||||
public static $databaseColumnId = 'id';
|
||||
public static string $databaseColumnId = 'id';
|
||||
|
||||
/**
|
||||
* @brief [Node] Order Database Column
|
||||
*/
|
||||
public static $databaseColumnOrder = 'order';
|
||||
public static ?string $databaseColumnOrder = 'order';
|
||||
|
||||
/**
|
||||
* @brief [Node] Node Title
|
||||
*/
|
||||
public static $nodeTitle = 'warn_reasons';
|
||||
public static string $nodeTitle = 'warn_reasons';
|
||||
|
||||
/**
|
||||
* @brief [Node] Show forms modally?
|
||||
*/
|
||||
public static $modalForms = TRUE;
|
||||
public static bool $modalForms = TRUE;
|
||||
|
||||
/**
|
||||
* @brief [Node] ACP Restrictions
|
||||
*/
|
||||
protected static $restrictions = array(
|
||||
protected static ?array $restrictions = array(
|
||||
'app' => 'core',
|
||||
'module' => 'moderation',
|
||||
'prefix' => 'reasons_',
|
||||
@@ -69,30 +84,30 @@ class _Reason extends \IPS\Node\Model
|
||||
/**
|
||||
* @brief [Node] Title prefix. If specified, will look for a language key with "{$key}_title" as the key
|
||||
*/
|
||||
public static $titleLangPrefix = 'core_warn_reason_';
|
||||
public static ?string $titleLangPrefix = 'core_warn_reason_';
|
||||
|
||||
/**
|
||||
* [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\Translatable( 'wr_name', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? "core_warn_reason_{$this->id}" : NULL ) ) ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'wr_points', $this->id ? $this->points : 0, TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'wr_points_override', $this->id ? $this->points_override : TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Custom( 'wr_remove', $this->id ? array( $this->remove, $this->remove_unit ) : NULL, FALSE, array(
|
||||
$form->add( new Translatable( 'wr_name', NULL, TRUE, array( 'app' => 'core', 'key' => ( $this->id ? "core_warn_reason_{$this->id}" : NULL ) ) ) );
|
||||
$form->add( new Number( 'wr_points', $this->id ? $this->points : 0, TRUE ) );
|
||||
$form->add( new YesNo( 'wr_points_override', $this->id ? $this->points_override : TRUE ) );
|
||||
$form->add( new Custom( 'wr_remove', $this->id ? array( $this->remove, $this->remove_unit ) : NULL, FALSE, array(
|
||||
'getHtml' => function( $element )
|
||||
{
|
||||
return \IPS\Theme::i()->getTemplate( 'members' )->warningTime( $element->name, $element->value, 'after', 'never' );
|
||||
return Theme::i()->getTemplate( 'members' )->warningTime( $element->name, $element->value, 'after', 'never' );
|
||||
}
|
||||
, 'unlimited' => -1, 'unlimitedLang' => 'never'
|
||||
) ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'wr_remove_override', $this->id ? $this->remove_override : TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'wr_cheev_point_reduction', $this->cheev_point_reduction ? $this->cheev_point_reduction : 0 ) );
|
||||
$form->add( new \IPS\Helpers\Form\YesNo( 'wr_cheev_override', $this->id ? $this->remove_override : TRUE ) );
|
||||
$form->add( new \IPS\Helpers\Form\Editor( 'wr_notes', $this->id ? $this->notes : NULL, FALSE, array( 'app' => 'core', 'key' => 'Modcp', 'autoSaveKey' => "warn-member-default", 'attachIds' => ( $this->id ? array( $this->id, NULL, 'warndefault' ) : NULL ), 'minimize' => 'warn_member_note_placeholder' ) ) );
|
||||
$form->add( new YesNo( 'wr_remove_override', $this->id ? $this->remove_override : TRUE ) );
|
||||
$form->add( new Number( 'wr_cheev_point_reduction', $this->cheev_point_reduction ? $this->cheev_point_reduction : 0 ) );
|
||||
$form->add( new YesNo( 'wr_cheev_override', $this->id ? $this->remove_override : TRUE ) );
|
||||
$form->add( new Editor( 'wr_notes', $this->id ? $this->notes : NULL, FALSE, array( 'app' => 'core', 'key' => 'Modcp', 'autoSaveKey' => "warn-member-default", 'attachIds' => ( $this->id ? array( $this->id, NULL, 'warndefault' ) : NULL ), 'minimize' => 'warn_member_note_placeholder' ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,7 +116,7 @@ class _Reason 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['wr_remove'] ) )
|
||||
{
|
||||
@@ -125,7 +140,7 @@ class _Reason extends \IPS\Node\Model
|
||||
|
||||
if( isset( $values['wr_name'] ) )
|
||||
{
|
||||
\IPS\Lang::saveCustom( 'core', "core_warn_reason_{$this->id}", $values['wr_name'] );
|
||||
Lang::saveCustom( 'core', "core_warn_reason_{$this->id}", $values['wr_name'] );
|
||||
unset( $values['wr_name'] );
|
||||
}
|
||||
|
||||
@@ -147,9 +162,9 @@ class _Reason extends \IPS\Node\Model
|
||||
* @param array $values Values from the form
|
||||
* @return void
|
||||
*/
|
||||
public function postSaveForm( $values )
|
||||
public function postSaveForm( array $values ) : void
|
||||
{
|
||||
\IPS\File::claimAttachments( "warn-member-default", $this->id, NULL, 'warndefault' );
|
||||
File::claimAttachments( "warn-member-default", $this->id, NULL, 'warndefault' );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,7 +172,7 @@ class _Reason extends \IPS\Node\Model
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canAdd()
|
||||
public function canAdd(): bool
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
@@ -165,19 +180,20 @@ class _Reason extends \IPS\Node\Model
|
||||
/**
|
||||
* [ActiveRecord] Delete Record
|
||||
*
|
||||
* @return void
|
||||
* @return void
|
||||
*/
|
||||
public function delete()
|
||||
public function delete(): void
|
||||
{
|
||||
\IPS\File::unclaimAttachments( "warn-member-default", $this->id, NULL, 'warndefault' );
|
||||
\IPS\Db::i()->update( 'core_members_warn_logs', array( 'wl_reason' => 0 ), array( "wl_reason=?", $this->id ) );
|
||||
return parent::delete();
|
||||
File::unclaimAttachments( "warn-member-default", $this->id, NULL, 'warndefault' );
|
||||
Db::i()->update( 'core_members_warn_logs', array( 'wl_reason' => 0 ), array( "wl_reason=?", $this->id ) );
|
||||
|
||||
parent::delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get output for API
|
||||
*
|
||||
* @param \IPS\Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @param Member|NULL $authorizedMember The member making the API request or NULL for API Key / client_credentials
|
||||
* @return array
|
||||
* @apiresponse int id ID number
|
||||
* @apiresponse string name Warn reason name
|
||||
@@ -188,7 +204,7 @@ class _Reason extends \IPS\Node\Model
|
||||
* @apiresponse string|null removePoints Time frame as a date interval when points will automatically be removed, or null if points do not automatically remove
|
||||
* @apiresponse bool pointsAutoRemove Whether points are automatically removed or not
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
public function apiOutput( Member $authorizedMember = NULL ): array
|
||||
{
|
||||
return array(
|
||||
'id' => $this->id,
|
||||
@@ -196,7 +212,7 @@ class _Reason extends \IPS\Node\Model
|
||||
'defaultNotes' => $this->notes,
|
||||
'points' => (int) $this->points,
|
||||
'pointsOverride' => (bool) $this->points_override,
|
||||
'pointsAutoRemove' => ( $this->remove AND $this->remove == -1 ) ? FALSE : TRUE,
|
||||
'pointsAutoRemove' => !( $this->remove AND $this->remove == -1 ),
|
||||
'removePoints' => ( $this->remove AND $this->remove != -1 ) ? 'P' . ( ( $this->remove_unit == 'h' ) ? 'T' : '' ) . $this->remove . mb_strtoupper( $this->remove_unit ) : NULL,
|
||||
'removeOverride' => (bool) $this->remove_override
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user