Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
@@ -54,6 +54,13 @@ class _leaderboard extends \IPS\Task
|
||||
else
|
||||
{
|
||||
$startDate = new \IPS\DateTime( 'yesterday midnight', $timezone );
|
||||
|
||||
/* Do we need to run this task at all? If we don't have any records in core_reputation_index we can skip this task */
|
||||
$existing = \IPS\Db::i()->select( 'count(*)', 'core_reputation_index' )->first();
|
||||
if ( !$existing )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
$yesterdayEnd = new \IPS\DateTime( 'today midnight', $timezone );
|
||||
@@ -65,19 +72,20 @@ class _leaderboard extends \IPS\Task
|
||||
for( $i = 0; $i < $difference; $i++ )
|
||||
{
|
||||
$position = 0;
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'core_reputation_index.member_received as member, SUM(rep_rating) as rep', 'core_reputation_index', array( 'member_received > 0 AND rep_date BETWEEN ? and ?', $startDate->getTimeStamp(), $yesterdayEnd->getTimeStamp() ), 'rep DESC', 4, 'member' )->setKeyField('member')->setValueField('rep') as $member => $rep )
|
||||
|
||||
/* As this can run multiple times, and the unique constraint is member_id, position, it is possible to end up with multiple members with the same positon */
|
||||
$date = $startDate->setTime( 12, 0 )->getTimeStamp();
|
||||
\IPS\Db::i()->delete( 'core_reputation_leaderboard_history', array( 'leader_date BETWEEN ? and ?', $date - 4, $date ) );
|
||||
|
||||
foreach( \IPS\Db::i()->select( 'core_reputation_index.member_received as member, SUM(rep_rating) as rep', 'core_reputation_index', array( 'member_received > 0 AND rep_date BETWEEN ? and ?', $startDate->setTime( 0, 0, 1 )->getTimeStamp(), $startDate->setTime( 23, 59, 59 )->getTimeStamp() ), 'rep DESC', 4, 'member' )->setKeyField('member')->setValueField('rep') as $member => $rep )
|
||||
{
|
||||
$date = $startDate->setTime( 12, 0 )->getTimeStamp();
|
||||
$position++;
|
||||
|
||||
/* As this can run multiple times, and the unique constraint is member_id, position, it is possible to end up with multiple members with the same positon */
|
||||
\IPS\Db::i()->delete( 'core_reputation_leaderboard_history', array( 'leader_date=? and leader_position=?', $date, $position ) );
|
||||
|
||||
if ( $member and $rep )
|
||||
{
|
||||
$date = $startDate->setTime( 12, 0 )->getTimeStamp();
|
||||
$position++;
|
||||
|
||||
\IPS\Db::i()->replace( 'core_reputation_leaderboard_history', array(
|
||||
'leader_date' => $startDate->setTime( 12, 0 )->getTimeStamp(),
|
||||
'leader_date' => $date,
|
||||
'leader_member_id' => $member,
|
||||
'leader_position' => $position,
|
||||
'leader_rep_total' => $rep
|
||||
@@ -85,13 +93,18 @@ class _leaderboard extends \IPS\Task
|
||||
}
|
||||
}
|
||||
|
||||
/* If there are no entries, date is not defined correctly as midday */
|
||||
if ( ! $position )
|
||||
{
|
||||
$date = $startDate->setTime( 12, 0 )->getTimeStamp();
|
||||
}
|
||||
|
||||
/* Fill in the blanks */
|
||||
if ( $position and $position < 5 )
|
||||
{
|
||||
while( $position < 4 )
|
||||
{
|
||||
$position++;
|
||||
\IPS\Db::i()->delete( 'core_reputation_leaderboard_history', array( 'leader_date=? and leader_position=?', $date - $position, $position ) );
|
||||
|
||||
\IPS\Db::i()->replace( 'core_reputation_leaderboard_history', array(
|
||||
'leader_date' => $date - $position,
|
||||
|
||||
Reference in new issue
Block a user