Skip to content

Commit

Permalink
Add "Also in this issue" to welcome note [WEB-1791]
Browse files Browse the repository at this point in the history
  • Loading branch information
IllyaMoskvin committed Aug 7, 2020
1 parent 9243f13 commit 29ddca6
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions app/Repositories/Behaviors/HandleMagazine.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Repositories\Behaviors;

use App\Models\MagazineItem;
use App\Models\MagazineIssue;

trait HandleMagazine
{
Expand All @@ -13,11 +14,20 @@ public function getAlsoInThisIssue($item)
{
$magItem = MagazineItem::where('magazinable_type', $this->morphType)->where('magazinable_id', $item->id)->first();

if (!$magItem) {
return null;
if ($magItem) {
$position = $magItem->position;
$magIssue = $magItem->magazineIssue;
} else {
$position = 0;
$magIssue = MagazineIssue::whereHas('relatedItems', function($query) use ($item) {
$query->where('browser_name', 'welcome_note');
$query->where('related_id', $item->id);
})->first();

if (!$magIssue) {
return null;
}
}
$position = $magItem->position;
$magIssue = $magItem->magazineIssue;

$items = $magIssue->magazineItems()->where('position', '>', $position)->get();
if ($items->count() < 4) {
Expand Down

0 comments on commit 29ddca6

Please sign in to comment.