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,53 +11,51 @@
|
||||
namespace IPS\core\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Member;
|
||||
use IPS\Widget\Customizable;
|
||||
use IPS\Widget\StaticCache;
|
||||
use function array_slice;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* mostSolved Widget
|
||||
*/
|
||||
class _mostSolved extends \IPS\Widget\StaticCache
|
||||
class mostSolved extends StaticCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'mostSolved';
|
||||
public string $key = 'mostSolved';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'core';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
/**
|
||||
* Initialise this widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
}
|
||||
public string $app = 'core';
|
||||
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param null|\IPS\Helpers\Form $form Form object
|
||||
* @return null|\IPS\Helpers\Form
|
||||
* @param null|Form $form Form object
|
||||
* @return Form
|
||||
*/
|
||||
public function configuration( &$form=null )
|
||||
public function configuration( Form &$form=null ): Form
|
||||
{
|
||||
$form = parent::configuration( $form );
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Number( 'number_to_show', isset( $this->configuration['number_to_show'] ) ? $this->configuration['number_to_show'] : 5, TRUE, array( 'max' => 25 ) ) );
|
||||
$form->add( new Number( 'number_to_show', $this->configuration['number_to_show'] ?? 5, TRUE, array( 'max' => 25 ) ) );
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -66,14 +64,14 @@ class _mostSolved extends \IPS\Widget\StaticCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
/* How many? */
|
||||
$limit = isset( $this->configuration['number_to_show'] ) ? $this->configuration['number_to_show'] : 5;
|
||||
$limit = $this->configuration['number_to_show'] ?? 5;
|
||||
|
||||
/* Work out who has got the most reputation this week... */
|
||||
$topSolvedThisWeek = array();
|
||||
foreach ( \IPS\Db::i()->select( 'member_id', 'core_solved_index', array( 'member_id > 0 AND solved_date>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1W' ) )->getTimestamp() ) ) as $memberId )
|
||||
foreach ( Db::i()->select( 'member_id', 'core_solved_index', array( 'member_id > 0 AND solved_date>? AND type=? AND hidden=0', DateTime::create()->sub( new DateInterval( 'P1W' ) )->getTimestamp(), 'solved' ) ) as $memberId )
|
||||
{
|
||||
if ( !isset( $topSolvedThisWeek[ $memberId ] ) )
|
||||
{
|
||||
@@ -85,14 +83,14 @@ class _mostSolved extends \IPS\Widget\StaticCache
|
||||
}
|
||||
}
|
||||
arsort( $topSolvedThisWeek );
|
||||
$topSolvedThisWeek = \array_slice( $topSolvedThisWeek, 0, $limit, TRUE );
|
||||
$topSolvedThisWeek = array_slice( $topSolvedThisWeek, 0, $limit, TRUE );
|
||||
|
||||
/* Load their data */
|
||||
if( \count( $topSolvedThisWeek ) )
|
||||
if( count( $topSolvedThisWeek ) )
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_members', \IPS\Db::i()->in( 'member_id', array_keys( $topSolvedThisWeek ) ) ) as $member )
|
||||
foreach ( Db::i()->select( '*', 'core_members', Db::i()->in( 'member_id', array_keys( $topSolvedThisWeek ) ) ) as $member )
|
||||
{
|
||||
\IPS\Member::constructFromData( $member );
|
||||
Member::constructFromData( $member );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user