This repository has been archived by the owner on Jun 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.1.13] #232 CertifyRankPosition has been attempted too many times o…
…r run too long, corrections to ga on local development, refactor to naming.
- Loading branch information
Showing
10 changed files
with
96 additions
and
94 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
namespace App\Listings; | ||
|
||
use App\Listings\ListingRanking; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
|
||
/** | ||
* Class ConfirmRankingPosition. | ||
*/ | ||
class RankPositionComparator implements ShouldQueue | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @param $event | ||
* @return void | ||
*/ | ||
public function handle($event): void | ||
{ | ||
$this->sortListingPosition($event->listing->ranking); | ||
} | ||
|
||
/** | ||
* Recursively upgrade the position if it has more points than the next listing. | ||
* | ||
* @param \App\Listings\ListingRanking $listing | ||
*/ | ||
private function sortListingPosition(ListingRanking $listing): void | ||
{ | ||
// We dont care if its already rank 1. | ||
if ($listing->rank == 1) { | ||
return; | ||
} | ||
|
||
/** @var ListingRanking $compare */ | ||
$compare = ListingRanking::where('rank', $listing->rank - 1)->first(); | ||
|
||
|
||
if ($listing->points < $compare->points) { | ||
return; | ||
} | ||
|
||
// this shit dont care if you guys have the same points | ||
if ($listing->points == $compare->points) { | ||
return; | ||
} | ||
|
||
$swap = $compare->rank; | ||
|
||
// first we update the next ranked to the current lower rank | ||
// then we use the swap value to store the next rank to the current. | ||
$compare->update(['rank' => $listing->rank]); | ||
|
||
// next we swap the rank back to the new position | ||
$listing->update(['rank' => $swap]); | ||
|
||
// we should look around, in case another listing is in front with less points. | ||
$this->sortListingPosition($listing); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"/js/app.js": "/js/app.js?id=6ebfc190e0d0167c7279", | ||
"/js/app.js": "/js/app.js?id=1efb1644fa6533cb9309", | ||
"/css/app.css": "/css/app.css?id=154aa5a6741058a03501" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters