Fix incoming favourites count

This commit is contained in:
Floorb 2022-03-14 15:59:14 -04:00
parent e89de763d5
commit 7fb5e14f4c

View file

@ -3,6 +3,7 @@ define('IN_PONEPASTE', 1);
require_once('includes/common.php'); require_once('includes/common.php');
require_once('includes/functions.php'); require_once('includes/functions.php');
use Illuminate\Support\Facades\DB;
use PonePaste\Models\User; use PonePaste\Models\User;
use PonePaste\Models\Paste; use PonePaste\Models\Paste;
@ -27,9 +28,16 @@ if (!$profile_info) {
$p_title = $profile_username . "'s Public Pastes"; $p_title = $profile_username . "'s Public Pastes";
// FIXME: This should be incoming faves // There has to be a way to do the sum in SQL rather than PHP, but I can't figure out ho to do it in Eloquent.
//$total_pfav = Paste::where('user_id', $profile_info->id)->sum('faves'); $total_pfav = array_sum(
$total_pfav = $profile_info->favourites->count(); array_column(
Paste::select('id')
->where('user_id', $profile_info->id)
->withCount('favouriters')
->get()->toArray(),
'favouriters_count'
)
);
$total_yfav = $profile_info->favourites->count(); $total_yfav = $profile_info->favourites->count();
// Badges // Badges