105 lines
3.4 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\Traits\Modules;
use App\Utilities\Versions;
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
$new_apps = $invoices = $bills = $exports = $imports = [];
2019-12-26 10:53:50 +03:00
$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
2021-09-01 23:16:41 +03:00
if ($user->isCustomer()) {
2019-12-26 10:53:50 +03:00
$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')) {
2021-06-19 18:16:09 +03:00
case 'App\Notifications\Common\ExportCompleted':
$exports['completed'][$data['file_name']] = $data['download_url'];
$notifications++;
break;
case 'App\Notifications\Common\ExportFailed':
$exports['failed'][] = $data['message'];
$notifications++;
break;
case 'App\Notifications\Common\ImportCompleted':
$imports['completed'][] = $data['translation'];
2021-06-19 18:16:09 +03:00
$notifications++;
break;
case 'App\Notifications\Common\ImportFailed':
$imports['failed'][] = '';
2021-06-19 18:16:09 +03:00
$notifications++;
break;
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
}
$new_apps = $this->getNotifications('new-apps');
foreach ($new_apps as $key => $new_app) {
if (setting('notifications.' . user()->id . '.' . $new_app->alias)) {
unset($new_apps[$key]);
continue;
2021-06-20 12:19:40 +03:00
}
$notifications++;
}
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,
'new_apps' => $new_apps,
2021-06-19 18:16:09 +03:00
'exports' => $exports,
'imports' => $imports,
2017-09-14 22:21:00 +03:00
'bills' => $bills,
'invoices' => $invoices,
'company' => $company,
'updates' => $updates,
]);
}
}