[DEV-222] Search fails when staff has no departments assigned (#1172)

* commented pr

* fix no department assigned issue

* undo irrelevants changes
This commit is contained in:
Joel Elias Méndez 2022-04-19 13:16:31 -03:00 committed by GitHub
parent f890fdc2d3
commit 86cad910ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -155,7 +155,7 @@ class SearchController extends Controller {
public function getSQLQueryWithOrder($inputs, $query) {
$order = "";
$query = "SELECT" . " ticket.id " . $query;
$query = "SELECT ticket.id " . $query;
$this->setQueryOrder($inputs, $order);
$inputs['page'] ? $page = $inputs['page'] : $page = 1 ;
@ -168,7 +168,9 @@ class SearchController extends Controller {
if(array_key_exists('tags',$inputs)) $this->setTagFilter($inputs['tags'], $filters);
if(array_key_exists('closed',$inputs)) $this->setClosedFilter($inputs['closed'], $filters);
if(array_key_exists('assigned',$inputs)) $this->setAssignedFilter($inputs['assigned'], $filters);
if(array_key_exists('unreadStaff',$inputs)) $this->setSeenFilter($inputs['unreadStaff'], $filters);
if(array_key_exists('unreadStaff',$inputs)) {
$this->setSeenFilter($inputs['unreadStaff'], $filters);
}
if(array_key_exists('dateRange',$inputs)) $this->setDateFilter($inputs['dateRange'], $filters);
if(array_key_exists('departments',$inputs) && array_key_exists('allowedDepartments',$inputs) && array_key_exists('staffId',$inputs)){
if(!$this->ignoreDeparmentFilter) $this->setDepartmentFilter($inputs['departments'],$inputs['allowedDepartments'], $inputs['staffId'], $filters);
@ -217,14 +219,13 @@ class SearchController extends Controller {
}
private function setDepartmentFilter($requestedDepartments,$myDepartments, $idStaff, &$filters){
if ($filters != "") $filters .= " and ";
if (!$requestedDepartments) $requestedDepartments = [];
$requestedOwnedDepartments = $this->getRequestedOwnedDepartments($requestedDepartments, $myDepartments);
$requestedNotOwnedDepartments = $this->getRequestedNotOwnedDepartments($requestedDepartments, $myDepartments);
$first = TRUE;
if(!$requestedOwnedDepartments && !$requestedNotOwnedDepartments){
if(!$requestedOwnedDepartments && !$requestedNotOwnedDepartments && !!$myDepartments){
if ($filters != "") $filters .= " and ";
foreach($myDepartments as $department) {
if($first){
$filters .= "(ticket.author_staff_id = " . $idStaff . " or ";