mirror of
https://github.com/opensupports/opensupports.git
synced 2025-09-26 11:29:05 +02:00
* Delete one line break in table.js * Add status icon in ticket title * Compare new filters with previous filters * Add ticket query filters * Add departments and priority filters. * Minor style changes in TagSelector and Tag * Add content on selected items Autocomplete component * Delete id prop from autocomplete component * Add DateSelector and DateRange component. * Delete compare function and add arrow orderby icon. * Add dateRange and orderBy filters. * Add minors changes of tabulations * Minors changes of funtion name and constant name * Minors changes of funtion name and constant name part 2. * Transform SearchBox in a controlled component. * Add Autocomplete and DateRange component int FormField. * Add preventDefault event in DropDown. * Create some customs list. * Add TagSelector in FormField. * Add private icon in autocomplete departments filters and correct some errors. * Delete consoleLogs. * Add ANY and TAGS (i18n). * Add search-filters reducer. * Add CLEAR (i18n). * Add clear form button in ticket search. * Correrct titel error in ticket search. * Correrct style submit button in ticket search. * Submit form not change orderBy. * Replace AdminPanelAllTicekts to AdminPanelSearchTicket. * Correct error when query is empty string. * Change form style. * Add show filters button. * Add minors style changes. * Add autors filters first part. * Add autors filters second part. * Apply filters when enter is pressed in searchbox. * Change prop name to node proptype in tag component. * Change search filter actions name. * Change name of render arrow icon in ticketList Component. * Fix an error with Autocomplete component. * Restore demo page and system. * Update ticket list test. * Fix an error with timeout in autocomplete test. * Delete custom ticket list in index.html. * rder the functions in search-filters-reducer. * Fix store undefine in session-action-test. * fix import store in session action test. * Delete unlock icon in ticket list. * Change style in autocomplete component. * Change size of lock icon in ticket list. * Fix error with blacklist in authors autocomplete. * Comment session action test. * Fix test in get-authors.rb and searchTest.php * Add onChange in tag-selector * Fix some bugs and autocomplete authors. * Wip * wip * wip * wip * Fix authors bugs in orderBy filter. * Delete some consoleLogs in autocomplete component. * Fix bug with authors filters when clicked custom list menu. * Fix highlight menu item bug. * Fix error when custom tickets list is undefined. * change double quote to single quote in search filters reducer * Fix error with get authors path in admin panel ticket search * Add page in ticket search filters * Join componentDidMount from Ticket QueryFilter and TicketQuery List in AdminPanelSearchTicket and add retrieveSearchTickets action in seartch ticket reducer. * rename search tickets api to search tickets utils * correct import of searchFiltersActions * move some functions to search tickets utils and date transformer * Fix bug with component did mount when custom tickets list menu option was clicked * Fix bug with component did mount and closed filters in url * Fix bug with authors filters in url when did mount search tickets page * Fix bug with closed urlFilters in search tickets did mount * Fix bug when change authors in urlFilters * Fix bug with authors filters in retrieveSearchTickets action * Delete changeCustomListFilters action * Fix error with dateRange filters in retrieveSearchTickets action * Add page in url * Rename filtesForAPI to filtersForAPI in search filters reducer. * Update Autocomplete test * Fix error with get-authors-test * fix bug with double request when search ticket page was mounted with item selected menu and delete custom param in url when custom ticket list form was edited * Add separator line between form filters and tickets table and delete console log * doubles the animation speed of show filters * Show form filters in search tickets * delete console log in session action * wip * Fix error with ticket list when custom list change. * Fix bug with hover of date range component. * Fix Autocomplete test. * Fix error with autocomplete owners in ticket query filters component. Co-authored-by: Ivan Diaz <ivan@opensupports.com>
105 lines
3.6 KiB
PHP
105 lines
3.6 KiB
PHP
<?php
|
|
use Respect\Validation\Validator as DataValidator;
|
|
use RedBeanPHP\Facade as RedBean;
|
|
DataValidator::with('CustomValidations', true);
|
|
|
|
/**
|
|
* @api {post} /ticket/search-authors search authors of tickets
|
|
* @apiVersion 4.6.1
|
|
*
|
|
* @apiName Search authors
|
|
*
|
|
* @apiGroup Ticket
|
|
*
|
|
* @apiDescription This path returns all the authors that match with the query.
|
|
*
|
|
* @apiPermission staff1
|
|
*
|
|
*
|
|
* @apiParam {String} query A string to find into a ticket to make a custom search.
|
|
* @apiParam {Object[]} blackList A array of objects {id, isStaff} with id and boolean to eliminate the authors of the new list.
|
|
*
|
|
* @apiUse NO_PERMISSION
|
|
* @apiUse INVALID_QUERY
|
|
*
|
|
* @apiSuccess {Object} data Empty object
|
|
*
|
|
*/
|
|
|
|
class SearchAuthorsController extends Controller {
|
|
const PATH = '/search-authors';
|
|
const METHOD = 'POST';
|
|
|
|
public function validations() {
|
|
return [
|
|
'permission' => 'staff_1',
|
|
'requestData' => [
|
|
'query' => [
|
|
'validation' => DataValidator::oneOf(DataValidator::stringType(),DataValidator::nullType()),
|
|
'error' => ERRORS::INVALID_QUERY
|
|
],
|
|
'blackList' => [
|
|
'validation' => DataValidator::oneOf(DataValidator::validAuthorsBlackList(),DataValidator::nullType()),
|
|
'error' => ERRORS::INVALID_BLACK_LIST
|
|
]
|
|
]
|
|
];
|
|
}
|
|
|
|
public function handler() {
|
|
$query = Controller::request('query');
|
|
|
|
$authorsQuery = "SELECT id,name,level FROM staff " . $this->generateAuthorsIdQuery($query) . " LIMIT 10";
|
|
$authorsMatch = RedBean::getAll($authorsQuery, [':query' => "%" .$query . "%",':queryAtBeginning' => $query . "%"] );
|
|
$authors = [];
|
|
|
|
foreach($authorsMatch as $authorMatch) {
|
|
if($authorMatch['level'] >=1 && $authorMatch['level'] <= 3){
|
|
$author = Staff::getDataStore($authorMatch['id']*1);
|
|
} else {
|
|
$author = User::getDataStore($authorMatch['id']*1);
|
|
}
|
|
array_push($authors, $author->toArray(true));
|
|
}
|
|
Response::respondSuccess([
|
|
'authors' => $authors
|
|
]);
|
|
}
|
|
public function generateAuthorsIdQuery($query) {
|
|
if ($query){
|
|
return "WHERE name LIKE :query " . $this->generateStaffBlackListQuery() . " UNION SELECT id,name,signup_date FROM user WHERE name LIKE :query " . $this->generateUserBlackListQuery() . " ORDER BY CASE WHEN (name LIKE :queryAtBeginning) THEN 1 ELSE 2 END ASC ";
|
|
} else {
|
|
return "WHERE 1=1 ". $this->generateStaffBlackListQuery() . " UNION SELECT id,name,signup_date FROM user WHERE 1=1". $this->generateUserBlackListQuery() ." ORDER BY id";
|
|
}
|
|
}
|
|
|
|
public function generateStaffBlackListQuery(){
|
|
$StaffBlackList = $this->getBlackListFiltered();
|
|
return $this->generateBlackListQuery($StaffBlackList);
|
|
}
|
|
|
|
public function generateUserBlackListQuery(){
|
|
$UserBlackList = $this->getBlackListFiltered(0);
|
|
return $this->generateBlackListQuery($UserBlackList);
|
|
}
|
|
|
|
public function generateBlackListQuery($idList){
|
|
$text = "";
|
|
foreach ($idList as $id) {
|
|
$text .= " AND id != " . $id;
|
|
}
|
|
return $text;
|
|
}
|
|
|
|
public function getBlackListFiltered($staff = 1){
|
|
$blackList = json_decode(Controller::request('blackList'));
|
|
$idList = [];
|
|
if($blackList){
|
|
foreach ($blackList as $item) {
|
|
if($staff == $item->isStaff) array_push($idList, $item->id);
|
|
}
|
|
}
|
|
return $idList;
|
|
}
|
|
}
|