1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Utils/Traits/Notifications/UserNotifies.php
David Bomba 6d7b7ca9a3
Invoice Deletion - Ledger (#3590)
* Fixes when implementing

* php_cs

* Clean up

* Clean up

* Working on adjusting ledger when an invoice is deleted
2020-04-04 21:32:42 +11:00

72 lines
2.2 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Utils\Traits\Notifications;
/**
* Class UserNotifies
* @package App\Utils\Traits
*/
trait UserNotifies
{
public function findUserNotificationTypes($invitation, $company_user, $entity_name, $required_permissions) :array
{
if ($this->migrationRunning($company_user)) {
return [];
}
$notifiable_methods = [];
$notifications = $company_user->notifications;
if ($invitation->{$entity_name}->user_id == $company_user->_user_id || $invitation->{$entity_name}->assigned_user_id == $company_user->user_id) {
array_push($required_permissions, "all_user_notifications");
}
if (count(array_intersect($required_permissions, $notifications->email)) >=1) {
array_push($notifiable_methods, 'mail');
}
// if(count(array_intersect($required_permissions, $notifications->slack)) >=1)
// array_push($notifiable_methods, 'slack');
return $notifiable_methods;
}
public function findUserEntityNotificationType($entity, $company_user, $required_permissions) :array
{
if ($this->migrationRunning($company_user)) {
return [];
}
$notifiable_methods = [];
$notifications = $company_user->notifications;
if ($entity->user_id == $company_user->_user_id || $entity->assigned_user_id == $company_user->user_id) {
array_push($required_permissions, "all_user_notifications");
}
if (count(array_intersect($required_permissions, $notifications->email)) >=1) {
array_push($notifiable_methods, 'mail');
}
// if(count(array_intersect($required_permissions, $notifications->slack)) >=1)
// array_push($notifiable_methods, 'slack');
return $notifiable_methods;
}
private function migrationRunning($company_user)
{
return $company_user->is_migrating;
}
}