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,35 +11,46 @@
|
||||
namespace IPS\core\modules\admin\activitystats;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\core\Statistics\Chart;
|
||||
use IPS\Dispatcher;
|
||||
use IPS\Dispatcher\Controller;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use IPS\Output;
|
||||
use IPS\Request;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* reactions
|
||||
*/
|
||||
class _reactions extends \IPS\Dispatcher\Controller
|
||||
class reactions extends Controller
|
||||
{
|
||||
/**
|
||||
* @brief Has been CSRF-protected
|
||||
*/
|
||||
public static $csrfProtected = TRUE;
|
||||
public static bool $csrfProtected = TRUE;
|
||||
|
||||
/**
|
||||
* @brief Allow MySQL RW separation for efficiency
|
||||
*/
|
||||
public static $allowRWSeparation = TRUE;
|
||||
public static bool $allowRWSeparation = TRUE;
|
||||
|
||||
/**
|
||||
* Execute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function execute()
|
||||
public function execute() : void
|
||||
{
|
||||
\IPS\Dispatcher::i()->checkAcpPermission( 'reactionsstats_manage' );
|
||||
Dispatcher::i()->checkAcpPermission( 'reactionsstats_manage' );
|
||||
parent::execute();
|
||||
}
|
||||
|
||||
@@ -48,7 +59,7 @@ class _reactions extends \IPS\Dispatcher\Controller
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function manage()
|
||||
protected function manage() : void
|
||||
{
|
||||
$tabs = array(
|
||||
'type' => 'stats_reactions_by_type',
|
||||
@@ -57,152 +68,19 @@ class _reactions extends \IPS\Dispatcher\Controller
|
||||
'givers' => 'stats_reactions_top_givers',
|
||||
'getters' => 'stats_reactions_top_receivers',
|
||||
);
|
||||
\IPS\Request::i()->tab ??= 'type';
|
||||
$activeTab = ( array_key_exists( \IPS\Request::i()->tab, $tabs ) ) ? \IPS\Request::i()->tab : 'type';
|
||||
|
||||
if ( $activeTab === 'type' OR $activeTab === 'app' )
|
||||
Request::i()->tab ??= 'type';
|
||||
$activeTab = ( array_key_exists( Request::i()->tab, $tabs ) ) ? Request::i()->tab : 'type';
|
||||
$chart = Chart::loadFromExtension( 'core', ( $activeTab === 'type' ) ? 'Reactions' : 'ReactionsApp' )->getChart( Url::internal( "app=core&module=activitystats&controller=reactions&tab=" . $activeTab ) );
|
||||
|
||||
if ( Request::i()->isAjax() )
|
||||
{
|
||||
$chart = \IPS\core\Statistics\Chart::loadFromExtension( 'core', ( $activeTab === 'type' ) ? 'Reactions' : 'ReactionsApp' )->getChart( \IPS\Http\Url::internal( "app=core&module=activitystats&controller=reactions&tab=" . $activeTab ) );
|
||||
Output::i()->output = (string) $chart;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( $activeTab == 'givers' OR $activeTab == 'getters' )
|
||||
{
|
||||
$start = NULL;
|
||||
$end = NULL;
|
||||
|
||||
$defaults = array( 'start' => \IPS\DateTime::create()->setDate( date('Y'), date('m'), 1 ), 'end' => new \IPS\DateTime );
|
||||
|
||||
if( isset( \IPS\Request::i()->repDateStart ) AND isset( \IPS\Request::i()->repDateEnd ) )
|
||||
{
|
||||
$defaults = array( 'start' => \IPS\DateTime::ts( \IPS\Request::i()->repDateStart ), 'end' => \IPS\DateTime::ts( \IPS\Request::i()->repDateEnd ) );
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form( $activeTab, 'continue' );
|
||||
$form->add( new \IPS\Helpers\Form\DateRange( 'date', $defaults, TRUE ) );
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
/* Determine start and end time */
|
||||
$startTime = $values['date']['start']->getTimestamp();
|
||||
$endTime = $values['date']['end']->getTimestamp();
|
||||
|
||||
$start = $values['date']['start']->html();
|
||||
$end = $values['date']['end']->html();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Determine start and end time */
|
||||
$startTime = $defaults['start']->getTimestamp();
|
||||
$endTime = $defaults['end']->getTimestamp();
|
||||
|
||||
$start = $defaults['start']->html();
|
||||
$end = $defaults['end']->html();
|
||||
}
|
||||
|
||||
$where = array( array( 'rep_date BETWEEN ? AND ?', $startTime, $endTime ) );
|
||||
}
|
||||
|
||||
/* Database table helpers don't support grouping, so we will manually fetch the results and then let the table helper display */
|
||||
$contentWhere = array();
|
||||
$idToRatingMap = array();
|
||||
|
||||
if( $activeTab == 'list' )
|
||||
{
|
||||
$query = \IPS\Db::i()->select( 'MAX(id) as id, SUM(rep_rating) as rating', 'core_reputation_index', NULL, 'rating DESC', array( 0, 20 ), array( 'app', 'type', 'type_id' ) );
|
||||
}
|
||||
elseif( $activeTab == 'givers' )
|
||||
{
|
||||
$query = \IPS\Db::i()->select( 'MAX(id) as id, SUM(rep_rating) as rating', 'core_reputation_index', $where, 'rating DESC', array( 0, 20 ), array( 'member_id' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$query = \IPS\Db::i()->select( 'MAX(id) as id, SUM(rep_rating) as rating', 'core_reputation_index', $where, 'rating DESC', array( 0, 20 ), array( 'member_received' ) );
|
||||
}
|
||||
|
||||
foreach( $query as $reputation )
|
||||
{
|
||||
$contentWhere[] = $reputation['id'];
|
||||
$idToRatingMap[ $reputation['id'] ] = $reputation['rating'];
|
||||
}
|
||||
|
||||
/* Create the table */
|
||||
$chart = new \IPS\Helpers\Table\Db( 'core_reputation_index', \IPS\Http\Url::internal( 'app=core&module=activitystats&controller=reactions&type=list' ), array( \IPS\Db::i()->in( 'id', $contentWhere ) ) );
|
||||
$chart->quickSearch = NULL;
|
||||
|
||||
/* Columns we need */
|
||||
if( $activeTab == 'list' )
|
||||
{
|
||||
$chart->langPrefix = 'reactstats_';
|
||||
$chart->include = array( 'type_id', 'rep_date', 'member_id', 'rating' );
|
||||
$chart->mainColumn = 'type_id';
|
||||
}
|
||||
else
|
||||
{
|
||||
$chart->langPrefix = 'reactstatsm_';
|
||||
$column = ( $activeTab == 'givers' ) ? 'member_id' : 'member_received';
|
||||
$chart->include = array( $column, 'rep_date', 'rating' );
|
||||
$chart->mainColumn = $column;
|
||||
|
||||
$chart->baseUrl = $chart->baseUrl->setQueryString( array( 'repDateStart' => $startTime, 'repDateEnd' => $endTime, 'tab' => $activeTab ) );
|
||||
}
|
||||
|
||||
$chart->noSort = array( 'member_id', 'type_id', 'rep_date', 'rating' );
|
||||
|
||||
$chart->sortBy = $chart->sortBy ?: 'rating';
|
||||
$chart->sortDirection = $chart->sortDirection ?: 'desc';
|
||||
|
||||
/* Custom parsers */
|
||||
$chart->parsers = array(
|
||||
'rep_date' => function( $val, $row )
|
||||
{
|
||||
return \IPS\DateTime::ts( $val )->localeDate();
|
||||
},
|
||||
'member_id' => function( $val, $row )
|
||||
{
|
||||
return \IPS\Member::load( $val )->link();
|
||||
},
|
||||
'member_received' => function( $val, $row )
|
||||
{
|
||||
return \IPS\Member::load( $val )->link();
|
||||
},
|
||||
'rating' => function( $val, $row ) use ( $idToRatingMap )
|
||||
{
|
||||
/* Return the reputation total */
|
||||
return $idToRatingMap[ $row['id'] ];
|
||||
},
|
||||
'type_id' => function( $val, $row )
|
||||
{
|
||||
$class = $row['rep_class'];
|
||||
|
||||
try
|
||||
{
|
||||
$item = $class::load( $row['type_id'] );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'activitystats' )->contentCell( $item );
|
||||
}
|
||||
catch ( \Throwable $e )
|
||||
{
|
||||
return \IPS\Member::loggedIn()->language()->addToStack( 'unavailable' );
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if( $activeTab == 'givers' OR $activeTab == 'getters' )
|
||||
{
|
||||
$formHtml = $form->customTemplate( array( \IPS\Theme::i()->getTemplate( 'stats' ), 'filtersFormTemplate' ) );
|
||||
$chart = \IPS\Theme::i()->getTemplate( 'activitystats', 'core' )->repWrapper( $formHtml, \count( $contentWhere ), (string) $chart );
|
||||
}
|
||||
|
||||
if ( \IPS\Request::i()->isAjax() )
|
||||
{
|
||||
\IPS\Output::i()->output = (string) $chart;
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Output::i()->title = \IPS\Member::loggedIn()->language()->addToStack('menu__core_activitystats_reactions');
|
||||
\IPS\Output::i()->output = \IPS\Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, \IPS\Http\Url::internal( "app=core&module=activitystats&controller=reactions" ), 'tab', '', 'ipsPad' );
|
||||
Output::i()->title = Member::loggedIn()->language()->addToStack('menu__core_activitystats_reactions');
|
||||
Output::i()->output = Theme::i()->getTemplate( 'global', 'core' )->tabs( $tabs, $activeTab, (string) $chart, Url::internal( "app=core&module=activitystats&controller=reactions" ), 'tab', '', 'i-padding_3' );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user