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,29 +11,41 @@
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Helpers\Chart;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use UnderflowException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _PercentageSolved extends \IPS\core\Statistics\Chart
|
||||
class PercentageSolved extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_solved_percentage';
|
||||
public ?string $controller = 'forums_stats_solved_percentage';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
/* Determine minimum date */
|
||||
$minimumDate = NULL;
|
||||
@@ -41,20 +53,20 @@ class _PercentageSolved extends \IPS\core\Statistics\Chart
|
||||
/* We can't retrieve any stats prior to the new tracking being implemented */
|
||||
try
|
||||
{
|
||||
$oldestLog = \IPS\Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
$oldestLog = Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
|
||||
if( !$minimumDate OR $oldestLog < $minimumDate->getTimestamp() )
|
||||
{
|
||||
$minimumDate = \IPS\DateTime::ts( $oldestLog );
|
||||
$minimumDate = DateTime::ts( $oldestLog );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* We have nothing tracked, set minimum date to today */
|
||||
$minimumDate = \IPS\DateTime::create();
|
||||
$minimumDate = DateTime::create();
|
||||
}
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'core_statistics', 'time', '', array(
|
||||
$chart = new Database( $url, 'core_statistics', 'time', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array('gridlines' => array('color' => '#f5f5f5')),
|
||||
@@ -68,11 +80,11 @@ class _PercentageSolved extends \IPS\core\Statistics\Chart
|
||||
);
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->description = \IPS\Member::loggedIn()->language()->addToStack( 'solved_stats_chart_desc' );
|
||||
$chart->description = Member::loggedIn()->language()->addToStack( 'solved_stats_chart_desc' );
|
||||
$chart->availableTypes = array('AreaChart', 'ColumnChart', 'BarChart');
|
||||
$chart->enableHourly = FALSE;
|
||||
$chart->groupBy = 'value_1';
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('forums_solved_stats_percentage');
|
||||
$chart->title = Member::loggedIn()->language()->addToStack('forums_solved_stats_percentage');
|
||||
$chart->where[] = array( "type=?", 'solved' );
|
||||
|
||||
foreach( $validForumIds = $this->getValidForumIds() as $forumId => $forum )
|
||||
@@ -88,17 +100,17 @@ class _PercentageSolved extends \IPS\core\Statistics\Chart
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getValidForumIds()
|
||||
protected function getValidForumIds() : array
|
||||
{
|
||||
$validForumIds = [];
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'value_1', 'core_statistics', [ 'type=?', 'solved' ], NULL, NULL, 'value_1' ) as $forumId )
|
||||
foreach( Db::i()->select( 'value_1', 'core_statistics', [ 'type=?', 'solved' ], NULL, NULL, 'value_1' ) as $forumId )
|
||||
{
|
||||
try
|
||||
{
|
||||
$validForumIds[ $forumId ] = \IPS\forums\Forum::load( $forumId );
|
||||
$validForumIds[ $forumId ] = Forum::load( $forumId );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
return $validForumIds;
|
||||
|
||||
@@ -11,31 +11,39 @@
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Chart;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _Posts extends \IPS\core\Statistics\Chart
|
||||
class Posts extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_posts_total';
|
||||
public ?string $controller = 'forums_stats_posts_total';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'forums_posts', 'post_date', '', array(
|
||||
$chart = new Database( $url, 'forums_posts', 'post_date', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'colors' => array( '#10967e' ),
|
||||
@@ -45,9 +53,9 @@ class _Posts extends \IPS\core\Statistics\Chart
|
||||
) );
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->where = array( array( \IPS\Db::i()->in( 'queued', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack( 'stats_new_posts' ), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_posts_title' );
|
||||
$chart->where = array( array( Db::i()->in( 'queued', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->addSeries( Member::loggedIn()->language()->addToStack( 'stats_new_posts' ), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_posts_title' );
|
||||
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
return $chart;
|
||||
|
||||
@@ -11,31 +11,43 @@
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* 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\Chart;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _PostsByForum extends \IPS\core\Statistics\Chart
|
||||
class PostsByForum extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_posts_byforum';
|
||||
public ?string $controller = 'forums_stats_posts_byforum';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'forums_posts', 'post_date', '', array(
|
||||
$chart = new Database( $url, 'forums_posts', 'post_date', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
|
||||
@@ -46,15 +58,15 @@ class _PostsByForum extends \IPS\core\Statistics\Chart
|
||||
),
|
||||
'ColumnChart',
|
||||
'monthly',
|
||||
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P90D') ), 'end' => new \IPS\DateTime ),
|
||||
array( 'start' => ( new DateTime )->sub( new DateInterval('P90D') ), 'end' => new DateTime ),
|
||||
array(),
|
||||
'byforum'
|
||||
);
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_posts_title_byforum' );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_posts_title_byforum' );
|
||||
$chart->availableTypes = array( 'ColumnChart' );
|
||||
$chart->where = array( array( \IPS\Db::i()->in( 'queued', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->where = array( array( Db::i()->in( 'queued', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->groupBy = 'forum_id';
|
||||
$chart->joins = array( array( 'forums_topics', 'forums_topics.tid=forums_posts.topic_id' ) );
|
||||
|
||||
@@ -62,33 +74,33 @@ class _PostsByForum extends \IPS\core\Statistics\Chart
|
||||
|
||||
$chart->customFiltersForm = array(
|
||||
'form' => array(
|
||||
new \IPS\Helpers\Form\Node( 'chart_forums', $customValues, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
new Node( 'chart_forums', $customValues, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
{
|
||||
return $forum->sub_can_post and !$forum->redirect_url;
|
||||
} ), NULL, NULL, NULL, 'chart_forums' )
|
||||
),
|
||||
'where' => function( $values )
|
||||
{
|
||||
$forumIds = \is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
return \IPS\Db::i()->in( 'forums_topics.forum_id', $forumIds );
|
||||
$forumIds = is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
return Db::i()->in( 'forums_topics.forum_id', $forumIds );
|
||||
},
|
||||
'groupBy' => 'forum_id',
|
||||
'series' => function( $values )
|
||||
{
|
||||
$series = array();
|
||||
$forumIds = \is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
$forumIds = is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
foreach( $forumIds as $id )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_forum_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'forums_forum_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
}
|
||||
return $series;
|
||||
},
|
||||
'defaultSeries' => function()
|
||||
{
|
||||
$series = array();
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_forums', array( 'posts>? AND club_id IS NULL', 0 ), 'last_post desc', array( 0, 50 ) ) as $forum )
|
||||
foreach( Db::i()->select( '*', 'forums_forums', array( 'posts>? AND club_id IS NULL', 0 ), 'topics desc', array( 0, 50 ) ) as $forum )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
}
|
||||
|
||||
return $series;
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Statistics Chart Extension
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @subpackage Forums
|
||||
* @since 26 Jan 2023
|
||||
*/
|
||||
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _Questions extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_questions';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'forums_question_ratings', 'date', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
|
||||
'lineWidth' => 1,
|
||||
'areaOpacity' => 0.4
|
||||
) );
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('stats_question_ratings_title');
|
||||
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
$chart->groupBy = 'rating';
|
||||
|
||||
foreach( array( 1, -1 ) as $v )
|
||||
{
|
||||
$label = ( $v == -1 ) ? 'negative' : 'positive';
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack('stats_question_ratings_' . $label ), 'number', 'COUNT(*)', TRUE, $label );
|
||||
}
|
||||
|
||||
return $chart;
|
||||
}
|
||||
}
|
||||
@@ -11,29 +11,44 @@
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Helpers\Chart;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use UnderflowException;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
class SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_solved_solved';
|
||||
public ?string $controller = 'forums_stats_solved_solved';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
/* Determine minimum date */
|
||||
$minimumDate = NULL;
|
||||
@@ -41,20 +56,20 @@ class _SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
/* We can't retrieve any stats prior to the new tracking being implemented */
|
||||
try
|
||||
{
|
||||
$oldestLog = \IPS\Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
$oldestLog = Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
|
||||
if( !$minimumDate OR $oldestLog < $minimumDate->getTimestamp() )
|
||||
{
|
||||
$minimumDate = \IPS\DateTime::ts( $oldestLog );
|
||||
$minimumDate = DateTime::ts( $oldestLog );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* We have nothing tracked, set minimum date to today */
|
||||
$minimumDate = \IPS\DateTime::create();
|
||||
$minimumDate = DateTime::create();
|
||||
}
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'core_solved_index', 'solved_date', '', array(
|
||||
$chart = new Database( $url, 'core_solved_index', 'solved_date', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
|
||||
@@ -65,15 +80,16 @@ class _SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
),
|
||||
'LineChart',
|
||||
'monthly',
|
||||
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P90D') ), 'end' => new \IPS\DateTime ),
|
||||
array( 'start' => ( new DateTime )->sub( new DateInterval('P90D') ), 'end' => new DateTime ),
|
||||
array(),
|
||||
'solved'
|
||||
);
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->joins = array( array( 'forums_topics', array( 'comment_class=? and core_solved_index.item_id=forums_topics.tid', 'IPS\forums\Topic\Post' ) ) );
|
||||
$chart->where = array( array( \IPS\Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ), array( \IPS\Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_topics_title_solved' );
|
||||
$chart->where = array( array( Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ), array( Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->where[] = array( 'type=?', 'solved' );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_topics_title_solved' );
|
||||
$chart->availableTypes = array( 'LineChart', 'ColumnChart' );
|
||||
|
||||
$chart->groupBy = 'forum_id';
|
||||
@@ -81,17 +97,17 @@ class _SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
|
||||
$chart->customFiltersForm = array(
|
||||
'form' => array(
|
||||
new \IPS\Helpers\Form\Node( 'chart_forums', $customValues, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
new Node( 'chart_forums', $customValues, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
{
|
||||
return $forum->sub_can_post and !$forum->redirect_url;
|
||||
} ), NULL, NULL, NULL, 'chart_forums' )
|
||||
),
|
||||
'where' => function( $values )
|
||||
{
|
||||
$forumIds = \is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
$forumIds = is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
if ( count( $forumIds ) )
|
||||
{
|
||||
return \IPS\Db::i()->in( 'forum_id', $forumIds );
|
||||
return Db::i()->in( 'forum_id', $forumIds );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -102,19 +118,19 @@ class _SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
'series' => function( $values )
|
||||
{
|
||||
$series = array();
|
||||
$forumIds = array_filter( \is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] ) );
|
||||
$forumIds = array_filter( is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] ) );
|
||||
if ( count( $forumIds ) )
|
||||
{
|
||||
foreach( $forumIds as $id )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_forum_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'forums_forum_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_forums', array( 'topics>? and ( forums_bitoptions & ? or forums_bitoptions & ? or forums_bitoptions & ? )', 0, 4, 8, 16 ), 'last_post desc', array( 0, 50 ) ) as $forum )
|
||||
foreach( Db::i()->select( '*', 'forums_forums', array( 'topics>? and ( forums_bitoptions & ? or forums_bitoptions & ? or forums_bitoptions & ? )', 0, 4, 8, 16 ), 'topics desc', array( 0, 50 ) ) as $forum )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
}
|
||||
}
|
||||
return $series;
|
||||
@@ -122,9 +138,9 @@ class _SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
'defaultSeries' => function()
|
||||
{
|
||||
$series = array();
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_forums', array( 'topics>? and ( forums_bitoptions & ? or forums_bitoptions & ? or forums_bitoptions & ? )', 0, 4, 8, 16 ), 'last_post desc', array( 0, 50 ) ) as $forum )
|
||||
foreach( Db::i()->select( '*', 'forums_forums', array( 'topics>? and ( forums_bitoptions & ? or forums_bitoptions & ? or forums_bitoptions & ? )', 0, 4, 8, 16 ), 'topics desc', array( 0, 50 ) ) as $forum )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
}
|
||||
|
||||
return $series;
|
||||
@@ -139,17 +155,17 @@ class _SolvedByForum extends \IPS\core\Statistics\Chart
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getValidForumIds()
|
||||
protected function getValidForumIds() : array
|
||||
{
|
||||
$validForumIds = [];
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'value_1', 'core_statistics', [ 'type=?', 'solved' ], NULL, NULL, 'value_1' ) as $forumId )
|
||||
foreach( Db::i()->select( 'value_1', 'core_statistics', [ 'type=?', 'solved' ], NULL, NULL, 'value_1' ) as $forumId )
|
||||
{
|
||||
try
|
||||
{
|
||||
$validForumIds[ $forumId ] = \IPS\forums\Forum::load( $forumId );
|
||||
$validForumIds[ $forumId ] = Forum::load( $forumId );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
return $validForumIds;
|
||||
|
||||
@@ -14,42 +14,41 @@ use IPS\core\Statistics\Chart as ParentClass;
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Chart;
|
||||
use IPS\Helpers\Chart\Database as DbChart;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Http\Url;
|
||||
use IPS\DateTime as IPSDateTime;
|
||||
use IPS\Member;
|
||||
use IPS\Helpers\Form\Select;
|
||||
use IPS\Member\Group;
|
||||
|
||||
use UnderflowException;
|
||||
use DateInterval;
|
||||
use Exception;
|
||||
|
||||
use function defined;
|
||||
use function header;
|
||||
use function is_array;
|
||||
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _SolvedByGroup extends ParentClass
|
||||
class SolvedByGroup extends ParentClass
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_solved_groups';
|
||||
public ?string $controller = 'forums_stats_solved_groups';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
@@ -59,20 +58,20 @@ class _SolvedByGroup extends ParentClass
|
||||
/* We can't retrieve any stats prior to the new tracking being implemented */
|
||||
try
|
||||
{
|
||||
$oldestLog = \IPS\Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
$oldestLog = Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
|
||||
if( !$minimumDate OR $oldestLog < $minimumDate->getTimestamp() )
|
||||
{
|
||||
$minimumDate = \IPS\DateTime::ts( $oldestLog );
|
||||
$minimumDate = IPSDateTime::ts( $oldestLog );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* We have nothing tracked, set minimum date to today */
|
||||
$minimumDate = \IPS\DateTime::create();
|
||||
$minimumDate = IPSDateTime::create();
|
||||
}
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'core_solved_index', 'solved_date', '', array(
|
||||
$chart = new DbChart( $url, 'core_solved_index', 'solved_date', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
|
||||
@@ -83,7 +82,7 @@ class _SolvedByGroup extends ParentClass
|
||||
),
|
||||
'LineChart',
|
||||
'monthly',
|
||||
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P90D') ), 'end' => new \IPS\DateTime ),
|
||||
array( 'start' => ( new IPSDateTime )->sub( new DateInterval('P90D') ), 'end' => new IPSDateTime ),
|
||||
array(),
|
||||
'solved'
|
||||
);
|
||||
@@ -91,7 +90,7 @@ class _SolvedByGroup extends ParentClass
|
||||
|
||||
$chart->joins = array( array( 'forums_posts', array( 'comment_class=? and core_solved_index.comment_id=forums_posts.pid', 'IPS\forums\Topic\Post' ) ), array( 'core_members', array( "core_members.member_id=forums_posts.author_id" ) ) );
|
||||
$chart->where = array( array( 'queued=?', 0 ) );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_topics_tab_groups' );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_topics_tab_groups' );
|
||||
$chart->availableTypes = array( 'LineChart', 'ColumnChart' );
|
||||
|
||||
$chart->groupBy = 'member_group_id';
|
||||
@@ -99,14 +98,14 @@ class _SolvedByGroup extends ParentClass
|
||||
|
||||
$chart->customFiltersForm = array(
|
||||
'form' => array(
|
||||
new \IPS\Helpers\Form\Select( 'chart_groups', $customValues, FALSE, array( 'options' => $this->_getGroups(), 'zeroVal' => 'any', 'multiple' => TRUE ), NULL, NULL, NULL, 'chart_groups' )
|
||||
new Select( 'chart_groups', $customValues, FALSE, array( 'options' => $this->_getGroups(), 'zeroVal' => 'any', 'multiple' => TRUE ), NULL, NULL, NULL, 'chart_groups' )
|
||||
),
|
||||
'where' => function( $values )
|
||||
{
|
||||
$groups = \is_array( $values['chart_groups'] ) ? array_values( $values['chart_groups'] ) : explode( ',', $values['chart_groups'] );
|
||||
$groups = is_array( $values['chart_groups'] ) ? array_values( $values['chart_groups'] ) : explode( ',', $values['chart_groups'] );
|
||||
if ( count( $groups ) )
|
||||
{
|
||||
return \IPS\Db::i()->in( 'member_group_id', $groups );
|
||||
return Db::i()->in( 'member_group_id', $groups );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -117,19 +116,19 @@ class _SolvedByGroup extends ParentClass
|
||||
'series' => function( $values )
|
||||
{
|
||||
$series = array();
|
||||
$groups = array_filter( \is_array( $values['chart_groups'] ) ? array_values( $values['chart_groups'] ) : explode( ',', $values['chart_groups'] ) );
|
||||
$groups = array_filter( is_array( $values['chart_groups'] ) ? array_values( $values['chart_groups'] ) : explode( ',', $values['chart_groups'] ) );
|
||||
if ( count( $groups ) )
|
||||
{
|
||||
foreach( $groups as $id )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'core_group_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'core_group_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( $this->_getGroups() AS $id => $group )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'core_group_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'core_group_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
}
|
||||
}
|
||||
return $series;
|
||||
@@ -139,7 +138,7 @@ class _SolvedByGroup extends ParentClass
|
||||
$series = array();
|
||||
foreach( $this->_getGroups() AS $id => $group )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'core_group_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'core_group_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
}
|
||||
return $series;
|
||||
}
|
||||
@@ -156,7 +155,7 @@ class _SolvedByGroup extends ParentClass
|
||||
protected function _getGroups(): array
|
||||
{
|
||||
$return = array();
|
||||
foreach( \IPS\Member\Group::groups( TRUE, FALSE ) AS $group )
|
||||
foreach( Group::groups( TRUE, FALSE ) AS $group )
|
||||
{
|
||||
$return[ $group->g_id ] = $group->name;
|
||||
}
|
||||
|
||||
@@ -11,29 +11,41 @@
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\Helpers\Chart;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use UnderflowException;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _TimeSolved extends \IPS\core\Statistics\Chart
|
||||
class TimeSolved extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_solved_time';
|
||||
public ?string $controller = 'forums_stats_solved_time';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
/* Determine minimum date */
|
||||
$minimumDate = NULL;
|
||||
@@ -41,20 +53,20 @@ class _TimeSolved extends \IPS\core\Statistics\Chart
|
||||
/* We can't retrieve any stats prior to the new tracking being implemented */
|
||||
try
|
||||
{
|
||||
$oldestLog = \IPS\Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
$oldestLog = Db::i()->select( 'MIN(time)', 'core_statistics', array( 'type=?', 'solved' ) )->first();
|
||||
|
||||
if( !$minimumDate OR $oldestLog < $minimumDate->getTimestamp() )
|
||||
if( $oldestLog !== null and ( !$minimumDate OR $oldestLog < $minimumDate->getTimestamp() ) )
|
||||
{
|
||||
$minimumDate = \IPS\DateTime::ts( $oldestLog );
|
||||
$minimumDate = DateTime::ts( $oldestLog );
|
||||
}
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
catch( UnderflowException $e )
|
||||
{
|
||||
/* We have nothing tracked, set minimum date to today */
|
||||
$minimumDate = \IPS\DateTime::create();
|
||||
$minimumDate = DateTime::create();
|
||||
}
|
||||
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'core_statistics', 'time', '', array(
|
||||
$chart = new Database( $url, 'core_statistics', 'time', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array('gridlines' => array('color' => '#f5f5f5')),
|
||||
@@ -68,11 +80,11 @@ class _TimeSolved extends \IPS\core\Statistics\Chart
|
||||
);
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->description = \IPS\Member::loggedIn()->language()->addToStack( 'solved_stats_chart_desc' );
|
||||
$chart->description = Member::loggedIn()->language()->addToStack( 'solved_stats_chart_desc' );
|
||||
$chart->availableTypes = array('AreaChart', 'ColumnChart', 'BarChart');
|
||||
$chart->enableHourly = FALSE;
|
||||
$chart->groupBy = 'value_1';
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack('forums_solved_stats_time');
|
||||
$chart->title = Member::loggedIn()->language()->addToStack('forums_solved_stats_time');
|
||||
$chart->where[] = array( "type=?", 'solved' );
|
||||
|
||||
foreach( $validForumIds = $this->getValidForumIds() as $forumId => $forum )
|
||||
@@ -88,18 +100,18 @@ class _TimeSolved extends \IPS\core\Statistics\Chart
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getValidForumIds()
|
||||
protected function getValidForumIds() : array
|
||||
{
|
||||
$validForumIds = [];
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'value_1', 'core_statistics', [ 'value_4 IS NOT NULL and type=?', 'solved' ], NULL, [ 0,100 ], 'value_1' ) as $forumId )
|
||||
|
||||
foreach( Db::i()->select( 'value_1', 'core_statistics', [ 'value_4 IS NOT NULL and type=?', 'solved' ], NULL, [ 0,100 ], 'value_1' ) as $forumId )
|
||||
{
|
||||
try
|
||||
{
|
||||
/* @var $forumId int */
|
||||
$validForumIds[ $forumId ] = \IPS\forums\Forum::load( $forumId );
|
||||
$validForumIds[ $forumId ] = Forum::load( $forumId );
|
||||
}
|
||||
catch( \Exception $e ) { }
|
||||
catch( Exception $e ) { }
|
||||
}
|
||||
|
||||
return $validForumIds;
|
||||
|
||||
@@ -11,31 +11,39 @@
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use IPS\Db;
|
||||
use IPS\Helpers\Chart;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _Topics extends \IPS\core\Statistics\Chart
|
||||
class Topics extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_topics_total';
|
||||
public ?string $controller = 'forums_stats_topics_total';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'forums_topics', 'start_date', '', array(
|
||||
$chart = new Database( $url, 'forums_topics', 'start_date', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'colors' => array( '#10967e' ),
|
||||
@@ -47,9 +55,9 @@ class _Topics extends \IPS\core\Statistics\Chart
|
||||
);
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->where = array( array( \IPS\Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ), array( \IPS\Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->addSeries( \IPS\Member::loggedIn()->language()->addToStack( 'stats_new_topics' ), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_topics_title' );
|
||||
$chart->where = array( array( Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ), array( Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->addSeries( Member::loggedIn()->language()->addToStack( 'stats_new_topics' ), 'number', 'COUNT(*)', FALSE );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_topics_title' );
|
||||
$chart->availableTypes = array( 'AreaChart', 'ColumnChart', 'BarChart' );
|
||||
|
||||
return $chart;
|
||||
|
||||
@@ -11,31 +11,43 @@
|
||||
namespace IPS\forums\extensions\core\Statistics;
|
||||
|
||||
/* 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\Chart;
|
||||
use IPS\Helpers\Chart\Database;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Http\Url;
|
||||
use IPS\Member;
|
||||
use function defined;
|
||||
use function is_array;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Statistics Chart Extension
|
||||
*/
|
||||
class _TopicsByForum extends \IPS\core\Statistics\Chart
|
||||
class TopicsByForum extends \IPS\core\Statistics\Chart
|
||||
{
|
||||
/**
|
||||
* @brief Controller
|
||||
*/
|
||||
public $controller = 'forums_stats_topics_byforum';
|
||||
public ?string $controller = 'forums_stats_topics_byforum';
|
||||
|
||||
/**
|
||||
* Render Chart
|
||||
*
|
||||
* @param \IPS\Http\Url $url URL the chart is being shown on.
|
||||
* @return \IPS\Helpers\Chart
|
||||
* @param Url $url URL the chart is being shown on.
|
||||
* @return Chart
|
||||
*/
|
||||
public function getChart( \IPS\Http\Url $url ): \IPS\Helpers\Chart
|
||||
public function getChart( Url $url ): Chart
|
||||
{
|
||||
$chart = new \IPS\Helpers\Chart\Database( $url, 'forums_topics', 'start_date', '', array(
|
||||
$chart = new Database( $url, 'forums_topics', 'start_date', '', array(
|
||||
'isStacked' => FALSE,
|
||||
'backgroundColor' => '#ffffff',
|
||||
'hAxis' => array( 'gridlines' => array( 'color' => '#f5f5f5' ) ),
|
||||
@@ -46,14 +58,14 @@ class _TopicsByForum extends \IPS\core\Statistics\Chart
|
||||
),
|
||||
'ColumnChart',
|
||||
'monthly',
|
||||
array( 'start' => ( new \IPS\DateTime )->sub( new \DateInterval('P90D') ), 'end' => new \IPS\DateTime ),
|
||||
array( 'start' => ( new DateTime )->sub( new DateInterval('P90D') ), 'end' => new DateTime ),
|
||||
array(),
|
||||
'byforum'
|
||||
);
|
||||
$chart->setExtension( $this );
|
||||
|
||||
$chart->where = array( array( \IPS\Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ), array( \IPS\Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->title = \IPS\Member::loggedIn()->language()->addToStack( 'stats_topics_title_byforum' );
|
||||
$chart->where = array( array( Db::i()->in( 'state', array( 'link', 'merged' ), TRUE ) ), array( Db::i()->in( 'approved', array( -2, -3 ), TRUE ) ) );
|
||||
$chart->title = Member::loggedIn()->language()->addToStack( 'stats_topics_title_byforum' );
|
||||
$chart->availableTypes = array( 'ColumnChart' );
|
||||
|
||||
$chart->groupBy = 'forum_id';
|
||||
@@ -61,33 +73,33 @@ class _TopicsByForum extends \IPS\core\Statistics\Chart
|
||||
|
||||
$chart->customFiltersForm = array(
|
||||
'form' => array(
|
||||
new \IPS\Helpers\Form\Node( 'chart_forums', $customValues, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
new Node( 'chart_forums', $customValues, FALSE, array( 'class' => 'IPS\forums\Forum', 'zeroVal' => 'any', 'multiple' => TRUE, 'permissionCheck' => function ( $forum )
|
||||
{
|
||||
return $forum->sub_can_post and !$forum->redirect_url;
|
||||
} ), NULL, NULL, NULL, 'chart_forums' )
|
||||
),
|
||||
'where' => function( $values )
|
||||
{
|
||||
$forumIds = \is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
return \IPS\Db::i()->in( 'forum_id', $forumIds );
|
||||
$forumIds = is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
return Db::i()->in( 'forum_id', $forumIds );
|
||||
},
|
||||
'groupBy' => 'forum_id',
|
||||
'series' => function( $values )
|
||||
{
|
||||
$series = array();
|
||||
$forumIds = \is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
$forumIds = is_array( $values['chart_forums'] ) ? array_keys( $values['chart_forums'] ) : explode( ',', $values['chart_forums'] );
|
||||
foreach( $forumIds as $id )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_forum_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'forums_forum_' . $id ), 'number', 'COUNT(*)', FALSE, $id );
|
||||
}
|
||||
return $series;
|
||||
},
|
||||
'defaultSeries' => function()
|
||||
{
|
||||
$series = array();
|
||||
foreach( \IPS\Db::i()->select( '*', 'forums_forums', array( 'topics>? AND club_id IS NULL', 0 ), 'last_post desc', array( 0, 50 ) ) as $forum )
|
||||
foreach( Db::i()->select( '*', 'forums_forums', array( 'topics>? AND club_id IS NULL', 0 ), 'topics desc', array( 0, 50 ) ) as $forum )
|
||||
{
|
||||
$series[] = array( \IPS\Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
$series[] = array( Member::loggedIn()->language()->addToStack( 'forums_forum_' . $forum['id'] ), 'number', 'COUNT(*)', FALSE, $forum['id'] );
|
||||
}
|
||||
|
||||
return $series;
|
||||
|
||||
Reference in new issue
Block a user