74 lines
2.0 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?php
namespace App\Http\ViewComposers;
2020-12-24 02:16:00 +03:00
use App\Utilities\Versions;
use App\Traits\Modules;
2017-09-14 22:21:00 +03:00
use Illuminate\View\View;
class Header
{
2020-12-24 02:16:00 +03:00
use Modules;
2018-05-25 16:57:58 +03:00
2017-09-14 22:21:00 +03:00
/**
* Bind data to the view.
*
* @param View $view
* @return void
*/
public function compose(View $view)
{
2019-11-16 10:21:14 +03:00
$user = user();
2017-09-14 22:21:00 +03:00
2019-12-26 10:53:50 +03:00
$invoices = $bills = [];
$updates = $notifications = 0;
2017-09-14 22:21:00 +03:00
$company = null;
2019-12-26 10:53:50 +03:00
if (!empty($user)) {
// Get customer company
if ($user->can('read-client-portal')) {
$company = (object) [
'company_name' => setting('company.name'),
'company_email' => setting('company.email'),
'company_address' => setting('company.address'),
'company_logo' => setting('company.logo'),
];
}
2017-09-14 22:21:00 +03:00
if ($user->can('read-common-notifications')) {
$unreads = $user->unreadNotifications;
2017-09-14 22:21:00 +03:00
foreach ($unreads as $unread) {
$data = $unread->getAttribute('data');
2017-09-14 22:21:00 +03:00
switch ($unread->getAttribute('type')) {
case 'App\Notifications\Purchase\Bill':
$bills[$data['bill_id']] = $data['amount'];
$notifications++;
break;
case 'App\Notifications\Sale\Invoice':
$invoices[$data['invoice_id']] = $data['amount'];
$notifications++;
break;
}
2019-12-26 10:53:50 +03:00
}
2017-09-14 22:21:00 +03:00
}
2021-01-18 01:16:26 +03:00
if ($user->can('read-install-updates')) {
$updates = count(Versions::getUpdates());
}
2017-09-14 22:21:00 +03:00
2019-12-26 10:53:50 +03:00
$this->loadSuggestions();
}
2018-05-25 16:57:58 +03:00
2017-09-14 22:21:00 +03:00
$view->with([
'user' => $user,
'notifications' => $notifications,
'bills' => $bills,
'invoices' => $invoices,
'company' => $company,
'updates' => $updates,
]);
}
}