1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-28 20:27:13 +02:00
invoiceninja/app/Http/ViewComposers/PortalComposer.php

94 lines
3.2 KiB
PHP
Raw Normal View History

2019-07-19 06:32:51 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-07-19 06:32:51 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-07-19 06:32:51 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\ViewComposers;
2020-11-10 04:36:16 +01:00
use App\Utils\Ninja;
2019-08-12 00:33:17 +02:00
use App\Utils\TranslationHelper;
2021-06-01 00:09:38 +02:00
use Illuminate\Support\Facades\App;
2020-11-10 04:36:16 +01:00
use Illuminate\Support\Facades\Lang;
2019-07-19 06:32:51 +02:00
use Illuminate\View\View;
/**
* Class PortalComposer.
2019-07-19 06:32:51 +02:00
*/
class PortalComposer
{
public $settings;
2019-07-19 06:32:51 +02:00
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
2019-07-22 05:54:34 +02:00
public function compose(View $view) :void
2019-07-19 06:32:51 +02:00
{
$view->with($this->portalData());
2020-11-10 04:36:16 +01:00
2020-11-25 15:19:52 +01:00
if (auth()->user()) {
2021-05-31 12:40:34 +02:00
App::forgetInstance('translator');
$t = app('translator');
$t->replace(Ninja::transformTranslations(auth()->user()->client->getMergedSettings()));
2020-11-25 15:19:52 +01:00
}
2019-07-19 06:32:51 +02:00
}
/**
* @return array
*/
2019-07-22 05:54:34 +02:00
private function portalData() :array
2019-07-19 06:32:51 +02:00
{
if (! auth()->user()) {
2019-07-19 06:32:51 +02:00
return [];
}
2019-07-19 06:32:51 +02:00
$this->settings = auth()->user()->client->getMergedSettings();
2019-07-22 05:54:34 +02:00
$data['sidebar'] = $this->sidebarMenu();
$data['header'] = [];
$data['footer'] = [];
2019-08-12 00:33:17 +02:00
$data['countries'] = TranslationHelper::getCountries();
2019-08-21 06:29:07 +02:00
$data['company'] = auth()->user()->company;
$data['client'] = auth()->user()->client;
$data['settings'] = $this->settings;
$data['currencies'] = TranslationHelper::getCurrencies();
2021-02-16 13:16:22 +01:00
$data['contact'] = auth('contact')->user();
$data['multiple_contacts'] = session()->get('multiple_contacts');
2019-07-19 06:32:51 +02:00
return $data;
}
2019-07-22 05:54:34 +02:00
private function sidebarMenu() :array
{
$data = [];
2021-01-15 12:19:34 +01:00
//@todo wire this back in when we are happy with dashboard.
// if($this->settings->enable_client_portal_dashboard == TRUE)
2021-02-16 13:16:22 +01:00
// $data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity'];
$data[] = ['title' => ctrans('texts.invoices'), 'url' => 'client.invoices.index', 'icon' => 'file-text'];
$data[] = ['title' => ctrans('texts.recurring_invoices'), 'url' => 'client.recurring_invoices.index', 'icon' => 'file'];
$data[] = ['title' => ctrans('texts.payments'), 'url' => 'client.payments.index', 'icon' => 'credit-card'];
$data[] = ['title' => ctrans('texts.quotes'), 'url' => 'client.quotes.index', 'icon' => 'align-left'];
$data[] = ['title' => ctrans('texts.credits'), 'url' => 'client.credits.index', 'icon' => 'credit-card'];
$data[] = ['title' => ctrans('texts.payment_methods'), 'url' => 'client.payment_methods.index', 'icon' => 'shield'];
$data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download'];
2021-03-29 14:35:27 +02:00
$data[] = ['title' => ctrans('texts.subscriptions'), 'url' => 'client.subscriptions.index', 'icon' => 'calendar'];
2019-07-22 05:54:34 +02:00
2020-11-17 15:01:28 +01:00
if (auth()->user('contact')->client->getSetting('enable_client_portal_tasks')) {
2021-05-12 16:39:29 +02:00
$data[] = ['title' => ctrans('texts.tasks'), 'url' => 'client.tasks.index', 'icon' => 'clock'];
2020-11-17 15:01:28 +01:00
}
2019-07-22 05:54:34 +02:00
return $data;
}
}