2020-03-11 12:05:05 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-03-11 12:05:05 +01:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-03-11 12:05:05 +01:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils\Traits\Notifications;
|
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class UserNotifies.
|
2020-03-11 12:05:05 +01:00
|
|
|
*/
|
|
|
|
trait UserNotifies
|
|
|
|
{
|
|
|
|
public function findUserNotificationTypes($invitation, $company_user, $entity_name, $required_permissions) :array
|
|
|
|
{
|
2020-11-01 04:19:03 +01:00
|
|
|
if ($company_user->company->is_disabled) {
|
2020-04-01 10:54:22 +02:00
|
|
|
return [];
|
2020-04-04 12:32:42 +02:00
|
|
|
}
|
2020-04-01 10:54:22 +02:00
|
|
|
|
2020-03-11 12:05:05 +01:00
|
|
|
$notifiable_methods = [];
|
|
|
|
$notifications = $company_user->notifications;
|
|
|
|
|
2021-02-01 06:30:28 +01:00
|
|
|
//if a user owns this record or is assigned to it, they are attached the permission for notification.
|
2020-03-21 06:37:30 +01:00
|
|
|
if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) {
|
2020-09-06 11:38:10 +02:00
|
|
|
array_push($required_permissions, 'all_user_notifications');
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-11 12:05:05 +01:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, 'all_user_notifications')) >= 1 || count(array_intersect($required_permissions, 'all_notifications')) >= 1) {
|
2020-03-11 12:05:05 +01:00
|
|
|
array_push($notifiable_methods, 'mail');
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-03-11 12:05:05 +01:00
|
|
|
|
|
|
|
// if(count(array_intersect($required_permissions, $notifications->slack)) >=1)
|
|
|
|
// array_push($notifiable_methods, 'slack');
|
2020-04-01 10:54:22 +02:00
|
|
|
|
2020-03-11 12:05:05 +01:00
|
|
|
return $notifiable_methods;
|
|
|
|
}
|
2020-04-01 10:54:22 +02:00
|
|
|
|
|
|
|
public function findUserEntityNotificationType($entity, $company_user, $required_permissions) :array
|
|
|
|
{
|
2020-11-01 08:53:43 +01:00
|
|
|
if ($company_user->company->is_disabled) {
|
2020-04-01 10:54:22 +02:00
|
|
|
return [];
|
2020-04-04 12:32:42 +02:00
|
|
|
}
|
2020-04-01 10:54:22 +02:00
|
|
|
|
|
|
|
$notifiable_methods = [];
|
|
|
|
$notifications = $company_user->notifications;
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! $notifications) {
|
2020-06-05 02:24:02 +02:00
|
|
|
return [];
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-06-05 02:24:02 +02:00
|
|
|
|
2020-04-01 10:54:22 +02:00
|
|
|
if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) {
|
2020-09-06 11:38:10 +02:00
|
|
|
array_push($required_permissions, 'all_user_notifications');
|
2020-04-01 10:54:22 +02:00
|
|
|
}
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) {
|
2020-04-01 10:54:22 +02:00
|
|
|
array_push($notifiable_methods, 'mail');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notifiable_methods;
|
|
|
|
}
|
|
|
|
|
2020-05-26 12:22:50 +02:00
|
|
|
public function findCompanyUserNotificationType($company_user, $required_permissions) :array
|
|
|
|
{
|
2020-11-01 08:53:43 +01:00
|
|
|
if ($company_user->company->is_disabled) {
|
2020-05-26 12:22:50 +02:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$notifiable_methods = [];
|
|
|
|
$notifications = $company_user->notifications;
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
if (count(array_intersect($required_permissions, $notifications->email)) >= 1 || count(array_intersect($required_permissions, ['all_user_notifications'])) >= 1 || count(array_intersect($required_permissions, ['all_notifications'])) >= 1) {
|
2020-05-26 12:22:50 +02:00
|
|
|
array_push($notifiable_methods, 'mail');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $notifiable_methods;
|
|
|
|
}
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|