Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -26,9 +26,13 @@ use IPS\Helpers\Form\Node;
|
||||
use IPS\Member;
|
||||
use IPS\Request;
|
||||
use IPS\Theme;
|
||||
use function array_merge;
|
||||
use function defined;
|
||||
use function explode;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function iterator_to_array;
|
||||
use function round;
|
||||
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
@@ -178,6 +182,106 @@ class Solved extends OverviewStatisticsAbstract
|
||||
return Theme::i()->getTemplate( 'stats', 'forums' )->solvedPercentage( $value, $previousValue, $nodeNames );
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate numbers for the CSV export. Yes, there's lots of duplicated code from getBlock().
|
||||
*
|
||||
* @param array|string|null $dateRange
|
||||
* @param string|null $subBlock
|
||||
* @return (null|int)[]
|
||||
*/
|
||||
public function getBlockNumbers( array|string $dateRange = null, string $subBlock = null ) : array
|
||||
{
|
||||
|
||||
/* Make sure someone isn't trying to manipulate the request or do something weird */
|
||||
if( !in_array( $subBlock, $this->getBlocks() ) )
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$value = 0;
|
||||
$previousValue = 0;
|
||||
|
||||
/* Build where clause in the event we are filtering */
|
||||
$where = array();
|
||||
$previousWhere = NULL;
|
||||
|
||||
if( $dateRange !== NULL )
|
||||
{
|
||||
if( is_array( $dateRange ) )
|
||||
{
|
||||
$where = array(
|
||||
array( 'start_date > ?', $dateRange['start']->getTimestamp() ),
|
||||
array( 'start_date < ?', $dateRange['end']->getTimestamp() ),
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$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 ( isset( Request::i()->nodes ) and Request::i()->nodes )
|
||||
{
|
||||
$where = array( array( Db::i()->in( 'forum_id', explode( ',', Request::i()->nodes ) ) ) );
|
||||
}
|
||||
|
||||
//$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' ) . ' )' ) ) ) );
|
||||
|
||||
|
||||
/* Get the current and previous values */
|
||||
switch( $subBlock )
|
||||
{
|
||||
case 'percentagesolved':
|
||||
$total = Db::i()->select( 'COUNT(*)', 'forums_topics', $this->_modifyWhereClause( $where ) )->first();
|
||||
|
||||
|
||||
$solvedWhere = $this->_modifyWhereClause( $where );
|
||||
$solvedWhere[] = [ 'core_solved_index.id is not null' ];
|
||||
$solvedWhere[] = [ 'type=?', 'solved' ];
|
||||
$solved = Db::i()->select( 'COUNT(*)', 'forums_topics', $solvedWhere )->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;
|
||||
|
||||
|
||||
if( $previousWhere !== NULL )
|
||||
{
|
||||
$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 [
|
||||
'statsreports_current_count' => $value,
|
||||
'statsreports_previous_count' => $previousValue,
|
||||
];
|
||||
|
||||
|
||||
case 'averagetimesolved':
|
||||
$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 = 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 [
|
||||
'statsreports_current_count' => $value,
|
||||
'statsreports_previous_count' => $previousValue
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
return [
|
||||
'statsreports_current_count' => $value,
|
||||
'statsreports_previous_count' => $previousValue
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the where clause to apply other filters
|
||||
*
|
||||
@@ -213,7 +317,7 @@ class Solved extends OverviewStatisticsAbstract
|
||||
}
|
||||
|
||||
$form = new Form;
|
||||
$form->attributes['data-controller'] = 'core.admin.stats.nodeFilters';
|
||||
$form->class = "ipsForm--vertical";
|
||||
$form->attributes['data-block'] = Request::i()->blockKey;
|
||||
$form->attributes['data-subblock'] = $subBlock;
|
||||
$form->add( new Node( Forum::$nodeTitle, NULL, TRUE, array( 'class' => '\IPS\forums\Forum', 'multiple' => TRUE, 'clubs' => FALSE ) ) );
|
||||
|
||||
Reference in new issue
Block a user