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,21 +12,39 @@
|
||||
namespace IPS\forums\extensions\core\OverviewStatistics;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
|
||||
use DateTimeZone;
|
||||
use Exception;
|
||||
use IPS\DateTime;
|
||||
use IPS\Db;
|
||||
use IPS\Extensions\OverviewStatisticsAbstract;
|
||||
use IPS\forums\Forum;
|
||||
use IPS\forums\Topic;
|
||||
use IPS\Helpers\Form;
|
||||
use IPS\Helpers\Form\Date;
|
||||
use IPS\Helpers\Form\Node;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Overview statistics extension: Solved
|
||||
*/
|
||||
class _Solved
|
||||
class Solved extends OverviewStatisticsAbstract
|
||||
{
|
||||
/**
|
||||
* @brief Which statistics page (activity or user)
|
||||
*/
|
||||
public $page = 'activity';
|
||||
public string $page = 'activity';
|
||||
|
||||
/**
|
||||
* Return the sub-block keys
|
||||
@@ -34,7 +52,7 @@ class _Solved
|
||||
* @note This is designed to allow one class to support multiple blocks, for instance using the ContentRouter to generate blocks.
|
||||
* @return array
|
||||
*/
|
||||
public function getBlocks()
|
||||
public function getBlocks(): array
|
||||
{
|
||||
return array( 'percentagesolved', 'averagetimesolved' );
|
||||
}
|
||||
@@ -45,31 +63,33 @@ class _Solved
|
||||
* @param string|NULL $subBlock The subblock we are loading as returned by getBlocks()
|
||||
* @return array
|
||||
*/
|
||||
public function getBlockDetails( $subBlock = NULL )
|
||||
public function getBlockDetails( string $subBlock = NULL ): array
|
||||
{
|
||||
switch( $subBlock )
|
||||
{
|
||||
case 'percentagesolved':
|
||||
return array( 'app' => 'forums', 'title' => 'stats_percentagesolved', 'description' => 'stats_percentagesolved_desc', 'refresh' => 60, 'form' => true );
|
||||
break;
|
||||
|
||||
|
||||
case 'averagetimesolved':
|
||||
return array( 'app' => 'forums', 'title' => 'stats_averagetimesolved', 'description' => 'stats_averagetimesolved_desc', 'refresh' => 60, 'form' => true );
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the block HTML to show
|
||||
*
|
||||
* @param array|NULL $dateRange NULL for all time, or an array with 'start' and 'end' \IPS\DateTime objects to restrict to
|
||||
* @param array|string|null $dateRange String for a fixed time period in days, NULL for all time, or an array with 'start' and 'end' \IPS\DateTime objects to restrict to
|
||||
* @param string|NULL $subBlock The subblock we are loading as returned by getBlocks()
|
||||
* @return string
|
||||
*/
|
||||
public function getBlock( $dateRange = NULL, $subBlock = NULL )
|
||||
public function getBlock( array|string $dateRange = NULL, string $subBlock = NULL ): string
|
||||
{
|
||||
/* Make sure someone isn't trying to manipulate the request or do something weird */
|
||||
if( !\in_array( $subBlock, $this->getBlocks() ) )
|
||||
if( !in_array( $subBlock, $this->getBlocks() ) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
@@ -84,7 +104,7 @@ class _Solved
|
||||
|
||||
if( $dateRange !== NULL )
|
||||
{
|
||||
if( \is_array( $dateRange ) )
|
||||
if( is_array( $dateRange ) )
|
||||
{
|
||||
$where = array(
|
||||
array( 'start_date > ?', $dateRange['start']->getTimestamp() ),
|
||||
@@ -93,49 +113,26 @@ class _Solved
|
||||
}
|
||||
else
|
||||
{
|
||||
$currentDate = new \IPS\DateTime;
|
||||
$interval = NULL;
|
||||
|
||||
switch( $dateRange )
|
||||
{
|
||||
case '7':
|
||||
$interval = new \DateInterval( 'P7D' );
|
||||
break;
|
||||
|
||||
case '30':
|
||||
$interval = new \DateInterval( 'P1M' );
|
||||
break;
|
||||
|
||||
case '90':
|
||||
$interval = new \DateInterval( 'P3M' );
|
||||
break;
|
||||
|
||||
case '180':
|
||||
$interval = new \DateInterval( 'P6M' );
|
||||
break;
|
||||
|
||||
case '365':
|
||||
$interval = new \DateInterval( 'P1Y' );
|
||||
break;
|
||||
}
|
||||
|
||||
$currentDate = new DateTime;
|
||||
$interval = static::getInterval( $dateRange );
|
||||
$initialTimestamp = $currentDate->sub( $interval )->getTimestamp();
|
||||
$where = array( array( 'start_date > ?', $initialTimestamp ) );
|
||||
$previousWhere = array( array( 'start_date BETWEEN ? AND ?', $currentDate->sub( $interval )->getTimestamp(), $initialTimestamp ) );
|
||||
}
|
||||
}
|
||||
else if ( $dateRange === NULL and isset( \IPS\Request::i()->nodes ) and \IPS\Request::i()->nodes )
|
||||
else if ( isset( Request::i()->nodes ) and Request::i()->nodes )
|
||||
{
|
||||
$where = array( array( \IPS\Db::i()->in( 'forum_id', explode( ',', \IPS\Request::i()->nodes ) ) ) );
|
||||
$where = array( array( Db::i()->in( 'forum_id', explode( ',', Request::i()->nodes ) ) ) );
|
||||
}
|
||||
|
||||
$where[] = array( \IPS\Db::i()->in( 'forum_id', iterator_to_array( \IPS\Db::i()->select( 'id', 'forums_forums', '(' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers' ) . ') OR ( ' . \IPS\Db::i()->bitwiseWhere( \IPS\forums\Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers_moderator' ) . ' )' ) ) ) );
|
||||
$where[] = array( 'type=?', 'solved' );
|
||||
$where[] = array( Db::i()->in( 'forum_id', iterator_to_array( Db::i()->select( 'id', 'forums_forums', '(' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_enable_answers' ) . ') OR ( ' . Db::i()->bitwiseWhere( Forum::$bitOptions['forums_bitoptions'], 'bw_solved_set_by_moderator' ) . ' )' ) ) ) );
|
||||
|
||||
if( \IPS\Request::i()->nodes )
|
||||
if( Request::i()->nodes )
|
||||
{
|
||||
foreach( explode( ',', \IPS\Request::i()->nodes ) as $nodeId )
|
||||
foreach( explode( ',', Request::i()->nodes ) as $nodeId )
|
||||
{
|
||||
$nodeNames[] = \IPS\forums\Forum::load( $nodeId )->_title;
|
||||
$nodeNames[] = Forum::load( $nodeId )->_title;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,8 +140,8 @@ class _Solved
|
||||
switch( $subBlock )
|
||||
{
|
||||
case 'percentagesolved':
|
||||
$total = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', $this->_modifyWhereClause( $where ) )->first();
|
||||
$solved = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $this->_modifyWhereClause( $where ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$total = Db::i()->select( 'COUNT(*)', 'forums_topics', $this->_modifyWhereClause( $where ) )->first();
|
||||
$solved = Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $this->_modifyWhereClause( $where ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
|
||||
$value = $total ? round( $solved / $total * 100, 2 ) : 0;
|
||||
|
||||
@@ -152,45 +149,45 @@ class _Solved
|
||||
|
||||
if( $previousWhere !== NULL )
|
||||
{
|
||||
$previousTotal = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', $this->_modifyWhereClause( $previousWhere ) )->first();
|
||||
$previousSolved = \IPS\Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $this->_modifyWhereClause( $previousWhere ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$previousTotal = Db::i()->select( 'COUNT(*)', 'forums_topics', $this->_modifyWhereClause( $previousWhere ) )->first();
|
||||
$previousSolved = Db::i()->select( 'COUNT(*)', 'forums_topics', array_merge( $this->_modifyWhereClause( $previousWhere ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
|
||||
$previousValue = $previousTotal ? round( $previousSolved / $previousTotal * 100, 2 ) : 0;
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'stats', 'forums' )->solvedPercentage( $value, $total, $solved, $previousValue, $previousTotal, $previousSolved, $nodeNames );
|
||||
break;
|
||||
return Theme::i()->getTemplate( 'stats', 'forums' )->solvedPercentage( $value, $total, $solved, $previousValue, $previousTotal, $previousSolved, $nodeNames );
|
||||
|
||||
|
||||
case 'averagetimesolved':
|
||||
$value = \IPS\Db::i()->select( 'AVG(core_solved_index.solved_date-forums_topics.start_date)', 'forums_topics', array_merge( $this->_modifyWhereClause( $where ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$value = Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $this->_modifyWhereClause( $where ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
|
||||
if( $previousWhere !== NULL )
|
||||
{
|
||||
$previousValue = \IPS\Db::i()->select( 'AVG(core_solved_index.solved_date-forums_topics.start_date)', 'forums_topics', array_merge( $this->_modifyWhereClause( $previousWhere ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
$previousValue = Db::i()->select( 'AVG(CAST(core_solved_index.solved_date AS SIGNED)-forums_topics.start_date)', 'forums_topics', array_merge( $this->_modifyWhereClause( $previousWhere ), array( array( 'core_solved_index.id IS NOT NULL' ) ) ) )->join( 'core_solved_index', "core_solved_index.app='forums' AND core_solved_index.item_id=forums_topics.tid")->first();
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'stats', 'forums' )->timeToSolved( $value, $previousValue, $nodeNames );
|
||||
break;
|
||||
return Theme::i()->getTemplate( 'stats', 'forums' )->timeToSolved( $value, $previousValue, $nodeNames );
|
||||
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'stats', 'forums' )->solvedPercentage( $values, $previousValues, $nodeNames );
|
||||
return Theme::i()->getTemplate( 'stats', 'forums' )->solvedPercentage( $value, $previousValue, $nodeNames );
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the where clause to apply other filters
|
||||
*
|
||||
* @param array $where Current where clause
|
||||
* @param array $where Current where clause
|
||||
* @return array
|
||||
*/
|
||||
protected function _modifyWhereClause( $where )
|
||||
protected function _modifyWhereClause( array $where ): array
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'approved', array( -2, -3 ), TRUE ) );
|
||||
$where[] = array( Db::i()->in( 'approved', array( -2, -3 ), TRUE ) );
|
||||
|
||||
$where = array_merge( $where, \IPS\forums\Topic::overviewStatisticsWhere() );
|
||||
$where = array_merge( $where, Topic::overviewStatisticsWhere() );
|
||||
|
||||
if( \IPS\Request::i()->nodes )
|
||||
if( Request::i()->nodes )
|
||||
{
|
||||
$where[] = array( \IPS\Db::i()->in( 'forum_id', explode( ',', \IPS\Request::i()->nodes ) ) );
|
||||
$where[] = array( Db::i()->in( 'forum_id', explode( ',', Request::i()->nodes ) ) );
|
||||
}
|
||||
|
||||
return $where;
|
||||
@@ -202,46 +199,46 @@ class _Solved
|
||||
* @param string|NULL $subBlock The subblock we are loading as returned by getBlocks()
|
||||
* @return array
|
||||
*/
|
||||
public function getBlockForm( $subBlock = NULL )
|
||||
public function getBlockForm( string $subBlock = NULL ): mixed
|
||||
{
|
||||
/* Make sure someone isn't trying to manipulate the request or do something weird */
|
||||
if( !\in_array( $subBlock, $this->getBlocks() ) )
|
||||
if( !in_array( $subBlock, $this->getBlocks() ) )
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
$form = new \IPS\Helpers\Form;
|
||||
$form = new Form;
|
||||
$form->attributes['data-controller'] = 'core.admin.stats.nodeFilters';
|
||||
$form->attributes['data-block'] = \IPS\Request::i()->blockKey;
|
||||
$form->attributes['data-block'] = Request::i()->blockKey;
|
||||
$form->attributes['data-subblock'] = $subBlock;
|
||||
$form->add( new \IPS\Helpers\Form\Node( \IPS\forums\Forum::$nodeTitle, NULL, TRUE, array( 'class' => '\IPS\forums\Forum', 'multiple' => TRUE, 'clubs' => FALSE ) ) );
|
||||
$form->add( new Node( Forum::$nodeTitle, NULL, TRUE, array( 'class' => '\IPS\forums\Forum', 'multiple' => TRUE, 'clubs' => FALSE ) ) );
|
||||
|
||||
if( $values = $form->values() )
|
||||
{
|
||||
$dateFilters = NULL;
|
||||
|
||||
if( \IPS\Request::i()->range )
|
||||
if( Request::i()->range )
|
||||
{
|
||||
$dateFilters = \IPS\Request::i()->range;
|
||||
$dateFilters = Request::i()->range;
|
||||
}
|
||||
elseif( \IPS\Request::i()->start )
|
||||
elseif( Request::i()->start )
|
||||
{
|
||||
try
|
||||
{
|
||||
$timezone = \IPS\Member::loggedIn()->timezone ? new \DateTimeZone( \IPS\Member::loggedIn()->timezone ) : NULL;
|
||||
$timezone = Member::loggedIn()->timezone ? new DateTimeZone( Member::loggedIn()->timezone ) : NULL;
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
catch ( Exception $e )
|
||||
{
|
||||
$timezone = NULL;
|
||||
}
|
||||
|
||||
$dateFilters = array(
|
||||
'start' => new \IPS\DateTime( \IPS\Helpers\Form\Date::_convertDateFormat( \IPS\Request::i()->start ), $timezone ),
|
||||
'end' => new \IPS\DateTime( \IPS\Helpers\Form\Date::_convertDateFormat( \IPS\Request::i()->end ), $timezone )
|
||||
'start' => new DateTime( Date::_convertDateFormat( Request::i()->start ), $timezone ),
|
||||
'end' => new DateTime( Date::_convertDateFormat( Request::i()->end ), $timezone )
|
||||
);
|
||||
}
|
||||
|
||||
return $this->getBlock( $dateFilters, $subblock );
|
||||
return $this->getBlock( $dateFilters, $subBlock );
|
||||
}
|
||||
|
||||
return $form;
|
||||
|
||||
Reference in new issue
Block a user