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
@@ -12,40 +12,46 @@
|
||||
namespace IPS\downloads\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\downloads\File;
|
||||
use IPS\Output;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget\Customizable;
|
||||
use IPS\Widget\PermissionCache;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* downloadStats Widget
|
||||
*/
|
||||
class _downloadStats extends \IPS\Widget\PermissionCache
|
||||
class downloadStats extends PermissionCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'downloadStats';
|
||||
public string $key = 'downloadStats';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'downloads';
|
||||
public string $app = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
|
||||
/**
|
||||
* Init the widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
|
||||
parent::init();
|
||||
}
|
||||
@@ -55,13 +61,13 @@ class _downloadStats extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
$stats = \IPS\Db::i()->select( 'COUNT(*) AS totalFiles, SUM(file_comments) AS totalComments, SUM(file_reviews) AS totalReviews', 'downloads_files', array( "file_open=?", 1 ) )->first();
|
||||
$stats['totalAuthors'] = \IPS\Db::i()->select( 'COUNT(DISTINCT file_submitter)', 'downloads_files' )->first();
|
||||
$stats = Db::i()->select( 'COUNT(*) AS totalFiles, SUM(file_comments) AS totalComments, SUM(file_reviews) AS totalReviews', 'downloads_files', array( "file_open=?", 1 ) )->first();
|
||||
$stats['totalAuthors'] = Db::i()->select( 'COUNT(DISTINCT file_submitter)', 'downloads_files' )->first();
|
||||
|
||||
$latestFile = NULL;
|
||||
foreach ( \IPS\downloads\File::getItemsWithPermission( array(), NULL, 1 ) as $latestFile )
|
||||
foreach ( File::getItemsWithPermission( array(), NULL, 1 ) as $latestFile )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -12,50 +12,53 @@
|
||||
namespace IPS\downloads\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Content\WidgetComment;
|
||||
use IPS\Output;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* downloadsCommentFeed Widget
|
||||
*/
|
||||
class _downloadsCommentFeed extends \IPS\Content\WidgetComment
|
||||
class downloadsCommentFeed extends WidgetComment
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'downloadsCommentFeed';
|
||||
public string $key = 'downloadsCommentFeed';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'downloads';
|
||||
public string $app = 'downloads';
|
||||
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected static $class = 'IPS\downloads\File\Comment';
|
||||
protected static string $class = 'IPS\downloads\File\Comment';
|
||||
|
||||
/**
|
||||
* @brief Moderator permission to generate caches on [optional]
|
||||
*/
|
||||
protected $moderatorPermissions = array( 'can_view_hidden_content', 'can_view_hidden_downloads_file_comment' );
|
||||
protected array $moderatorPermissions = array( 'can_view_hidden_content', 'can_view_hidden_downloads_file_comment' );
|
||||
|
||||
/**
|
||||
* Init the widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
@@ -12,50 +12,53 @@
|
||||
namespace IPS\downloads\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Content\WidgetComment;
|
||||
use IPS\Output;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* downloadsReviewFeed Widget
|
||||
*/
|
||||
class _downloadsReviewFeed extends \IPS\Content\WidgetComment
|
||||
class downloadsReviewFeed extends WidgetComment
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'downloadsReviewFeed';
|
||||
public string $key = 'downloadsReviewFeed';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'downloads';
|
||||
public string $app = 'downloads';
|
||||
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected static $class = 'IPS\downloads\File\Review';
|
||||
protected static string $class = 'IPS\downloads\File\Review';
|
||||
|
||||
/**
|
||||
* @brief Moderator permission to generate caches on [optional]
|
||||
*/
|
||||
protected $moderatorPermissions = array( 'can_view_hidden_content', 'can_view_hidden_downloads_file_review' );
|
||||
protected array $moderatorPermissions = array( 'can_view_hidden_content', 'can_view_hidden_downloads_file_review' );
|
||||
|
||||
/**
|
||||
* Init the widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
|
||||
parent::init();
|
||||
}
|
||||
|
||||
@@ -12,45 +12,55 @@
|
||||
namespace IPS\downloads\widgets;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Application;
|
||||
use IPS\Content\Widget;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Radio;
|
||||
use IPS\Output;
|
||||
use IPS\Settings;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Files Entry Feed Widget
|
||||
*/
|
||||
class _fileFeed extends \IPS\Content\Widget
|
||||
class fileFeed extends Widget
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'fileFeed';
|
||||
public string $key = 'fileFeed';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'downloads';
|
||||
public string $app = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
public string $plugin = '';
|
||||
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected static $class = 'IPS\downloads\File';
|
||||
protected static string $class = 'IPS\downloads\File';
|
||||
|
||||
/**
|
||||
* Init the widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
\IPS\downloads\Application::outputCss();
|
||||
parent::init();
|
||||
}
|
||||
@@ -58,14 +68,14 @@ class _fileFeed extends \IPS\Content\Widget
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->idm_nexus_on )
|
||||
if ( Application::appIsEnabled( 'nexus' ) and Settings::i()->idm_nexus_on )
|
||||
{
|
||||
$options = array(
|
||||
'free' => 'file_free',
|
||||
@@ -73,7 +83,7 @@ class _fileFeed extends \IPS\Content\Widget
|
||||
'any' => 'any'
|
||||
);
|
||||
|
||||
$form->add( new \IPS\Helpers\Form\Radio( 'file_cost_type', isset( $this->configuration['file_cost_type'] ) ? $this->configuration['file_cost_type'] : 'any', TRUE, array( 'options' => $options ) ) );
|
||||
$form->add( new Radio( 'file_cost_type', $this->configuration['file_cost_type'] ?? 'any', TRUE, array( 'options' => $options ) ) );
|
||||
}
|
||||
|
||||
return $form;
|
||||
@@ -84,11 +94,11 @@ class _fileFeed extends \IPS\Content\Widget
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function buildWhere()
|
||||
protected function buildWhere(): array
|
||||
{
|
||||
$where = parent::buildWhere();
|
||||
|
||||
if ( \IPS\Application::appIsEnabled( 'nexus' ) and \IPS\Settings::i()->idm_nexus_on )
|
||||
if ( Application::appIsEnabled( 'nexus' ) and Settings::i()->idm_nexus_on )
|
||||
{
|
||||
if( isset( $this->configuration['file_cost_type'] ) )
|
||||
{
|
||||
|
||||
@@ -12,46 +12,59 @@
|
||||
namespace IPS\downloads\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\downloads\Category;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Number;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Patterns\ActiveRecordIterator;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget\Customizable;
|
||||
use IPS\Widget\PermissionCache;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* topDownloads Widget
|
||||
*/
|
||||
class _topDownloads extends \IPS\Widget\PermissionCache
|
||||
class topDownloads extends PermissionCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'topDownloads';
|
||||
public string $key = 'topDownloads';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'downloads';
|
||||
public string $app = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
|
||||
/**
|
||||
* @brief Cache Expiration
|
||||
* @note We allow this cache to be valid for 48 hours
|
||||
*/
|
||||
public $cacheExpiration = 172800;
|
||||
public int $cacheExpiration = 172800;
|
||||
|
||||
/**
|
||||
* Init the widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
|
||||
parent::init();
|
||||
}
|
||||
@@ -59,14 +72,14 @@ class _topDownloads extends \IPS\Widget\PermissionCache
|
||||
/**
|
||||
* 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 ) );
|
||||
$form->add( new Number( 'number_to_show', $this->configuration['number_to_show'] ?? 5, TRUE ) );
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -75,16 +88,16 @@ class _topDownloads extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
$categories = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'perm_type_id', 'core_permission_index', array( 'app=? and perm_type=? and (' . \IPS\Db::i()->findInSet( 'perm_' . \IPS\downloads\Category::$permissionMap['read'], \IPS\Member::loggedIn()->groups ) . ' OR ' . 'perm_' . \IPS\downloads\Category::$permissionMap['read'] . '=? )', 'downloads', 'category', '*' ) ) as $category )
|
||||
foreach( Db::i()->select( 'perm_type_id', 'core_permission_index', array( 'app=? and perm_type=? and (' . Db::i()->findInSet( 'perm_' . Category::$permissionMap['read'], Member::loggedIn()->groups ) . ' OR ' . 'perm_' . Category::$permissionMap['read'] . '=? )', 'downloads', 'category', '*' ) ) as $category )
|
||||
{
|
||||
$categories[] = $category;
|
||||
}
|
||||
|
||||
if( !\count( $categories ) )
|
||||
if( !count( $categories ) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@@ -94,22 +107,22 @@ class _topDownloads extends \IPS\Widget\PermissionCache
|
||||
$where = array( array( 'file_cat IN(' . implode( ',', $categories ) . ')' ) );
|
||||
if ( $interval )
|
||||
{
|
||||
$where[] = array( 'dtime>?', \IPS\DateTime::create()->sub( new \DateInterval( $interval ) )->getTimestamp() );
|
||||
$where[] = array( 'dtime>?', DateTime::create()->sub( new DateInterval( $interval ) )->getTimestamp() );
|
||||
}
|
||||
|
||||
$ids = array();
|
||||
$cases = array();
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'dfid, count(*) AS downloads', 'downloads_downloads', $where, 'downloads DESC', isset( $this->configuration['number_to_show'] ) ? $this->configuration['number_to_show'] : 5, array( 'dfid' ) )->join( 'downloads_files', 'dfid=file_id' ) as $download )
|
||||
foreach( Db::i()->select( 'dfid, count(*) AS downloads', 'downloads_downloads', $where, 'downloads DESC', $this->configuration['number_to_show'] ?? 5, array( 'dfid' ) )->join( 'downloads_files', 'dfid=file_id' ) as $download )
|
||||
{
|
||||
$ids[] = $download['dfid'];
|
||||
$cases[] = "WHEN file_id={$download['dfid']} THEN {$download['downloads']}";
|
||||
}
|
||||
|
||||
if( \count( $ids ) )
|
||||
if( count( $ids ) )
|
||||
{
|
||||
$$time = new \IPS\Patterns\ActiveRecordIterator(
|
||||
\IPS\Db::i()->select(
|
||||
$$time = new ActiveRecordIterator(
|
||||
Db::i()->select(
|
||||
'*, CASE ' . implode( ' ', $cases ) . ' END AS file_downloads',
|
||||
'downloads_files',
|
||||
'file_id IN(' . implode( ',', $ids ) . ')',
|
||||
|
||||
@@ -12,40 +12,51 @@
|
||||
namespace IPS\downloads\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\Output;
|
||||
use IPS\Theme;
|
||||
use IPS\Widget\Customizable;
|
||||
use IPS\Widget\PermissionCache;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* topSubmitters Widget
|
||||
*/
|
||||
class _topSubmitters extends \IPS\Widget\PermissionCache
|
||||
class topSubmitters extends PermissionCache implements Customizable
|
||||
{
|
||||
/**
|
||||
* @brief Widget Key
|
||||
*/
|
||||
public $key = 'topSubmitters';
|
||||
public string $key = 'topSubmitters';
|
||||
|
||||
/**
|
||||
* @brief App
|
||||
*/
|
||||
public $app = 'downloads';
|
||||
public string $app = 'downloads';
|
||||
|
||||
/**
|
||||
* @brief Plugin
|
||||
*/
|
||||
public $plugin = '';
|
||||
|
||||
|
||||
/**
|
||||
* Init the widget
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
public function init(): void
|
||||
{
|
||||
\IPS\Output::i()->cssFiles = array_merge( \IPS\Output::i()->cssFiles, \IPS\Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
Output::i()->cssFiles = array_merge( Output::i()->cssFiles, Theme::i()->css( 'widgets.css', 'downloads', 'front' ) );
|
||||
|
||||
parent::init();
|
||||
}
|
||||
@@ -53,14 +64,14 @@ class _topSubmitters extends \IPS\Widget\PermissionCache
|
||||
/**
|
||||
* 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 ) );
|
||||
$form->add( new Number( 'number_to_show', $this->configuration['number_to_show'] ?? 5, TRUE ) );
|
||||
return $form;
|
||||
}
|
||||
|
||||
@@ -69,7 +80,7 @@ class _topSubmitters extends \IPS\Widget\PermissionCache
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function render()
|
||||
public function render(): string
|
||||
{
|
||||
foreach ( array( 'week' => 'P1W', 'month' => 'P1M', 'year' => 'P1Y', 'all' => NULL ) as $time => $interval )
|
||||
{
|
||||
@@ -77,7 +88,7 @@ class _topSubmitters extends \IPS\Widget\PermissionCache
|
||||
$intervalWhere = NULL;
|
||||
if ( $interval )
|
||||
{
|
||||
$intervalWhere = array( 'file_submitted>?', \IPS\DateTime::create()->sub( new \DateInterval( $interval ) )->getTimestamp() );
|
||||
$intervalWhere = array( 'file_submitted>?', DateTime::create()->sub( new DateInterval( $interval ) )->getTimestamp() );
|
||||
}
|
||||
|
||||
/* Get the submitters ordered by their rating */
|
||||
@@ -86,32 +97,32 @@ class _topSubmitters extends \IPS\Widget\PermissionCache
|
||||
{
|
||||
$where[] = $intervalWhere;
|
||||
}
|
||||
$ratings = iterator_to_array( \IPS\Db::i()->select(
|
||||
$ratings = iterator_to_array( Db::i()->select(
|
||||
'downloads_files.file_submitter, AVG(file_rating) as rating, count(file_id) AS files',
|
||||
'downloads_files',
|
||||
$where,
|
||||
'files DESC, rating DESC',
|
||||
isset( $this->configuration['number_to_show'] ) ? $this->configuration['number_to_show'] : 5, 'file_submitter'
|
||||
$this->configuration['number_to_show'] ?? 5, 'file_submitter'
|
||||
)->setKeyField('file_submitter')->setValueField('rating') );
|
||||
|
||||
${$time} = array();
|
||||
|
||||
if( \count( $ratings ) )
|
||||
if( count( $ratings ) )
|
||||
{
|
||||
/* Get their file counts */
|
||||
$where = array( array( \IPS\Db::i()->in( 'file_submitter', array_keys( $ratings ) ) ) );
|
||||
$where = array( array( Db::i()->in( 'file_submitter', array_keys( $ratings ) ) ) );
|
||||
if ( $interval )
|
||||
{
|
||||
$where[] = $intervalWhere;
|
||||
}
|
||||
|
||||
$fileCounts = iterator_to_array( \IPS\Db::i()->select( 'file_submitter, count(*) AS count', 'downloads_files', $where, NULL, NULL, 'file_submitter' )->setKeyField('file_submitter')->setValueField('count') );
|
||||
$fileCounts = iterator_to_array( Db::i()->select( 'file_submitter, count(*) AS count', 'downloads_files', $where, NULL, NULL, 'file_submitter' )->setKeyField('file_submitter')->setValueField('count') );
|
||||
|
||||
/* Get member data and put it together */
|
||||
foreach( \IPS\Db::i()->select( '*', 'core_members', \IPS\Db::i()->in( 'member_id', array_keys( $ratings ) ) ) as $key => $memberData )
|
||||
foreach( Db::i()->select( '*', 'core_members', Db::i()->in( 'member_id', array_keys( $ratings ) ) ) as $key => $memberData )
|
||||
{
|
||||
${$time}[$key]['member'] = \IPS\Member::constructFromData( $memberData );
|
||||
${$time}[$key]['files'] = isset( $fileCounts[ $memberData['member_id'] ] ) ? $fileCounts[ $memberData['member_id'] ] : 0;
|
||||
${$time}[$key]['member'] = Member::constructFromData( $memberData );
|
||||
${$time}[$key]['files'] = $fileCounts[$memberData['member_id']] ?? 0;
|
||||
${$time}[$key]['rating'] = $ratings[ $memberData['member_id'] ];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user