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,43 +11,53 @@
|
||||
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\PermissionCache;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* topContributors Widget
|
||||
*/
|
||||
class _topContributors extends \IPS\Widget\PermissionCache
|
||||
class topContributors extends PermissionCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'topContributors';
|
||||
public string $key = 'topContributors';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'core';
|
||||
public string $app = 'core';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
|
||||
/**
|
||||
* Specify widget configuration
|
||||
*
|
||||
* @param null|\IPS\Helpers\Form $form Form object
|
||||
* @return \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;
|
||||
}
|
||||
|
||||
@@ -56,14 +66,14 @@ class _topContributors extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @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... */
|
||||
$topContributorsThisWeek = array();
|
||||
foreach ( \IPS\Db::i()->select( array( 'member_received', 'rep_rating' ), 'core_reputation_index', array( 'member_received>0 AND rep_date>?', \IPS\DateTime::create()->sub( new \DateInterval( 'P1W' ) )->getTimestamp() ) ) as $rep )
|
||||
foreach ( Db::i()->select( array( 'member_received', 'rep_rating' ), 'core_reputation_index', array( 'member_received>0 AND rep_date>?', DateTime::create()->sub( new DateInterval( 'P1W' ) )->getTimestamp() ) ) as $rep )
|
||||
{
|
||||
if ( !isset( $topContributorsThisWeek[ $rep['member_received'] ] ) )
|
||||
{
|
||||
@@ -75,14 +85,14 @@ class _topContributors extends \IPS\Widget\PermissionCache
|
||||
}
|
||||
}
|
||||
arsort( $topContributorsThisWeek );
|
||||
$topContributorsThisWeek = \array_slice( $topContributorsThisWeek, 0, $limit, TRUE );
|
||||
$topContributorsThisWeek = array_slice( $topContributorsThisWeek, 0, $limit, TRUE );
|
||||
|
||||
/* Load their data */
|
||||
if( \count( $topContributorsThisWeek ) )
|
||||
if( count( $topContributorsThisWeek ) )
|
||||
{
|
||||
foreach ( \IPS\Db::i()->select( '*', 'core_members', \IPS\Db::i()->in( 'member_id', array_keys( $topContributorsThisWeek ) ) ) as $member )
|
||||
foreach ( Db::i()->select( '*', 'core_members', Db::i()->in( 'member_id', array_keys( $topContributorsThisWeek ) ) ) as $member )
|
||||
{
|
||||
\IPS\Member::constructFromData( $member );
|
||||
Member::constructFromData( $member );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user