File: D:/HostingSpaces/SBogers10/inzigd.komma.pro/app/Komma/Base/Service.php
<?php
namespace App\Komma\Base;
use App\Komma\Pages\Models\Page;
use App\Komma\Sites\Models\Site;
use App\Komma\Sites\SiteServiceInterface;
abstract class Service
{
/** @var SiteServiceInterface */
private $siteService;
/** @var Site */
protected $site;
public function __construct()
{
if(app()->runningInConsole()) return;
$this->siteService = app(SiteServiceInterface::class);
$this->site = $this->siteService->getCurrentSite();
}
/**
* Append the models belonging to the index page of $modelIndexPage
* Models are grouped by product or solution group models
*
* @param $links
*/
protected function appendGroupedModelsToLinksForModelIndexPage(&$links, $collection, Page $modelIndexPage)
{
// Create empty object
$subnav = [];
foreach ($collection as $groupKey => $models)
{
$groupCollection = collect();
// To save an additional request,
// we manually append the (current language) translation to the model
// and remove the inactive / not working pages.
foreach($models as $key => $model)
{
// Through the query builder we know it has translations
foreach ($model->translations as $translationCollectionKey => $translation){
// Check that a translation is active and has a slug
if(!$translation->active || empty($translation->slug) ){
// Remove translation from collection
$model->translations->forget($translationCollectionKey);
continue;
}
// When it matches the app language (id) append it as it's translation
if(app()->getLanguage()->id == $translation->language_id) $model->translation = $translation;
}
// Only append page to links if it has a translation
if(empty($model->translation) || !$model->translation->active) continue;
$groupCollection->push((object)[
'name' => $model->translation->name,
'route' => $model->translation->slug,
'node' => $model
]);
}
// Only append the group if it has an item in it
if($groupCollection->count() != 0)
$subnav[$modelIndexPage->code_name . '_group_' . $groupKey] = $groupCollection;
}
$links->subnav->{$modelIndexPage->code_name} = collect($subnav);
}
}