You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
PHP
48 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace BusinessLogic\Tickets;
|
|
|
|
|
|
use BusinessLogic\Security\UserContext;
|
|
use BusinessLogic\Security\UserPrivilege;
|
|
use DataAccess\Categories\CategoryGateway;
|
|
use DataAccess\Security\UserGateway;
|
|
|
|
class Autoassigner {
|
|
/* @var $categoryGateway CategoryGateway */
|
|
private $categoryGateway;
|
|
|
|
/* @var $userGateway UserGateway */
|
|
private $userGateway;
|
|
|
|
function __construct(CategoryGateway $categoryGateway,
|
|
UserGateway $userGateway) {
|
|
$this->categoryGateway = $categoryGateway;
|
|
$this->userGateway = $userGateway;
|
|
}
|
|
|
|
/**
|
|
* @param $categoryId int
|
|
* @param $heskSettings array
|
|
* @return UserContext the user who is assigned, or null if no user should be assigned
|
|
*/
|
|
function getNextUserForTicket($categoryId, $heskSettings) {
|
|
if (!$heskSettings['autoassign']) {
|
|
return null;
|
|
}
|
|
|
|
$potentialUsers = $this->userGateway->getUsersByNumberOfOpenTicketsForAutoassign($heskSettings);
|
|
|
|
foreach ($potentialUsers as $potentialUser) {
|
|
if ($potentialUser->admin ||
|
|
(in_array($categoryId, $potentialUser->categories) &&
|
|
in_array(UserPrivilege::CAN_VIEW_TICKETS, $potentialUser->permissions) &&
|
|
in_array(UserPrivilege::CAN_REPLY_TO_TICKETS, $potentialUser->permissions))) {
|
|
return $potentialUser;
|
|
}
|
|
}
|
|
|
|
|
|
return null;
|
|
}
|
|
} |