Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
3f51f59a
Verified
Commit
3f51f59a
authored
6 years ago
by
Damien
Browse files
Options
Downloads
Patches
Plain Diff
FEAT #8101 Autocomplete with search
parent
cbd9ea19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/controllers/AutoCompleteController.php
+125
-32
125 additions, 32 deletions
src/core/controllers/AutoCompleteController.php
with
125 additions
and
32 deletions
src/core/controllers/AutoCompleteController.php
+
125
−
32
View file @
3f51f59a
...
...
@@ -23,8 +23,8 @@ use Entity\models\EntityModel;
use
SrcCore\models\CoreConfigModel
;
use
SrcCore\models\DatabaseModel
;
use
SrcCore\models\TextFormatModel
;
use
SrcCore\models\ValidatorModel
;
use
Status\models\StatusModel
;
use
User\models\UserEntityModel
;
use
User\models\UserModel
;
class
AutoCompleteController
...
...
@@ -86,23 +86,18 @@ class AutoCompleteController
$excludedUsers
=
[
'superadmin'
];
$searchItems
=
explode
(
' '
,
$data
[
'search'
]);
$fields
=
'(firstname ilike ? OR lastname ilike ?)'
;
$where
=
[
'enabled = ?'
,
'status != ?'
,
'user_id not in (?)'
];
$requestData
=
[
'Y'
,
'DEL'
,
$excludedUsers
];
foreach
(
$searchItems
as
$item
)
{
if
(
strlen
(
$item
)
>=
2
)
{
$where
[]
=
$fields
;
$requestData
[]
=
"%
{
$item
}
%"
;
$requestData
[]
=
"%
{
$item
}
%"
;
}
}
$requestData
=
AutoCompleteController
::
getDataForRequest
([
'search'
=>
$data
[
'search'
],
'fields'
=>
'(firstname ilike ? OR lastname ilike ?)'
,
'where'
=>
[
'enabled = ?'
,
'status != ?'
,
'user_id not in (?)'
],
'data'
=>
[
'Y'
,
'DEL'
,
$excludedUsers
],
'fieldsNumber'
=>
2
,
]);
$users
=
UserModel
::
get
([
'select'
=>
[
'user_id'
,
'firstname'
,
'lastname'
],
'where'
=>
$where
,
'data'
=>
$requestData
,
'where'
=>
$
requestData
[
'
where
'
]
,
'data'
=>
$requestData
[
'data'
]
,
'orderBy'
=>
[
'lastname'
]
]);
...
...
@@ -121,21 +116,72 @@ class AutoCompleteController
public
static
function
getUsersForAdministration
(
Request
$request
,
Response
$response
)
{
$data
=
$request
->
getQueryParams
();
$check
=
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$data
[
'search'
]);
if
(
!
$check
)
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Bad Request'
]);
}
$excludedUsers
=
[
'superadmin'
];
if
(
$GLOBALS
[
'userId'
]
!=
'superadmin'
)
{
$entities
=
EntityModel
::
getAllEntitiesByUserId
([
'userId'
=>
$GLOBALS
[
'userId'
]]);
$users
=
UserEntityModel
::
getUsersByEntities
([
$requestData
=
AutoCompleteController
::
getDataForRequest
([
'search'
=>
$data
[
'search'
],
'fields'
=>
'(users.firstname ilike ? OR users.lastname ilike ?)'
,
'where'
=>
[
'users.user_id = users_entities.user_id'
,
'users_entities.entity_id in (?)'
,
'users.status != ?'
,
'users.enabled = ?'
],
'data'
=>
[
$entities
,
'DEL'
,
'Y'
],
'fieldsNumber'
=>
2
,
]);
$users
=
DatabaseModel
::
select
([
'select'
=>
[
'DISTINCT users.user_id'
,
'users.id'
,
'users.firstname'
,
'users.lastname'
],
'entities'
=>
$entities
'table'
=>
[
'users, users_entities'
],
'where'
=>
$requestData
[
'where'
],
'data'
=>
$requestData
[
'data'
]
]);
$requestData
=
AutoCompleteController
::
getDataForRequest
([
'search'
=>
$data
[
'search'
],
'fields'
=>
'(users.firstname ilike ? OR users.lastname ilike ?)'
,
'where'
=>
[
'users_entities IS NULL'
,
'users.user_id not in (?)'
,
'users.status != ?'
,
'users.enabled = ?'
],
'data'
=>
[
$excludedUsers
,
'DEL'
,
'Y'
],
'fieldsNumber'
=>
2
,
]);
$usersNoEntities
=
UserEntityModel
::
getUsersWithoutEntities
([
'select'
=>
[
'users.id'
,
'users.user_id'
,
'users.firstname'
,
'users.lastname'
]]);
$usersNoEntities
=
DatabaseModel
::
select
([
'select'
=>
[
'users.id'
,
'users.user_id'
,
'users.firstname'
,
'users.lastname'
],
'table'
=>
[
'users'
,
'users_entities'
],
'left_join'
=>
[
'users.user_id = users_entities.user_id'
],
'where'
=>
$requestData
[
'where'
],
'data'
=>
$requestData
[
'data'
]
]);
$users
=
array_merge
(
$users
,
$usersNoEntities
);
}
else
{
$excludedUsers
=
[
'superadmin'
];
$requestData
=
AutoCompleteController
::
getDataForRequest
([
'search'
=>
$data
[
'search'
],
'fields'
=>
'(firstname ilike ? OR lastname ilike ?)'
,
'where'
=>
[
'enabled = ?'
,
'status != ?'
,
'user_id not in (?)'
],
'data'
=>
[
'Y'
,
'DEL'
,
$excludedUsers
],
'fieldsNumber'
=>
2
,
]);
$users
=
UserModel
::
get
([
'select'
=>
[
'id'
,
'user_id'
,
'firstname'
,
'lastname'
],
'where'
=>
[
'enabled = ?'
,
'
stat
us != ?'
,
'user_id not in (?)
'
],
'data'
=>
[
'Y'
,
'DEL'
,
$excludedUsers
],
'select'
=>
[
'user_id'
,
'firstname'
,
'lastname'
],
'where'
=>
$reque
st
D
at
a
[
'where
'
],
'data'
=>
$requestData
[
'data'
],
'orderBy'
=>
[
'lastname'
]
]);
}
...
...
@@ -155,12 +201,18 @@ class AutoCompleteController
public
static
function
getUsersForVisa
(
Request
$request
,
Response
$response
)
{
$data
=
$request
->
getQueryParams
();
$check
=
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$data
[
'search'
]);
if
(
!
$check
)
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Bad Request'
]);
}
$excludedUsers
=
[
'superadmin'
];
$
users
=
DatabaseModel
::
selec
t
([
'se
lect'
=>
[
'DISTINCT users.user_id'
,
'users.firstname'
,
'users.lastname
'
],
'
table'
=>
[
'users
, usergroup_content, usergroups_services'
]
,
'where'
=>
[
$
requestData
=
AutoCompleteController
::
getDataForReques
t
([
'se
arch'
=>
$data
[
'search
'
],
'
fields'
=>
'
(
users
.firstname ilike ? OR users.lastname ilike ?)'
,
'where'
=>
[
'usergroup_content.group_id = usergroups_services.group_id'
,
'usergroup_content.user_id = users.user_id'
,
'usergroups_services.service_id in (?)'
,
...
...
@@ -168,7 +220,15 @@ class AutoCompleteController
'users.enabled = ?'
,
'users.status != ?'
],
'data'
=>
[[
'visa_documents'
,
'sign_document'
],
$excludedUsers
,
'Y'
,
'DEL'
],
'data'
=>
[[
'visa_documents'
,
'sign_document'
],
$excludedUsers
,
'Y'
,
'DEL'
],
'fieldsNumber'
=>
2
,
]);
$users
=
DatabaseModel
::
select
([
'select'
=>
[
'DISTINCT users.user_id'
,
'users.firstname'
,
'users.lastname'
],
'table'
=>
[
'users, usergroup_content, usergroups_services'
],
'where'
=>
$requestData
[
'where'
],
'data'
=>
$requestData
[
'data'
],
'order_by'
=>
[
'users.lastname'
]
]);
...
...
@@ -187,10 +247,24 @@ class AutoCompleteController
public
static
function
getEntities
(
Request
$request
,
Response
$response
)
{
$data
=
$request
->
getQueryParams
();
$check
=
Validator
::
stringType
()
->
notEmpty
()
->
validate
(
$data
[
'search'
]);
if
(
!
$check
)
{
return
$response
->
withStatus
(
400
)
->
withJson
([
'errors'
=>
'Bad Request'
]);
}
$requestData
=
AutoCompleteController
::
getDataForRequest
([
'search'
=>
$data
[
'search'
],
'fields'
=>
'(entity_label ilike ?)'
,
'where'
=>
[
'enabled = ?'
],
'data'
=>
[
'Y'
],
'fieldsNumber'
=>
1
,
]);
$entities
=
EntityModel
::
get
([
'select'
=>
[
'entity_id'
,
'entity_label'
,
'short_label'
],
'where'
=>
[
'enabled = ?
'
],
'data'
=>
[
'Y
'
],
'where'
=>
$requestData
[
'where
'
],
'data'
=>
$requestData
[
'data
'
],
'orderBy'
=>
[
'entity_label'
]
]);
...
...
@@ -209,9 +283,7 @@ class AutoCompleteController
public
static
function
getStatuses
(
Request
$request
,
Response
$response
)
{
$statuses
=
StatusModel
::
get
([
'select'
=>
[
'id'
,
'label_status'
,
'img_filename'
]
]);
$statuses
=
StatusModel
::
get
([
'select'
=>
[
'id'
,
'label_status'
,
'img_filename'
]]);
$data
=
[];
foreach
(
$statuses
as
$value
)
{
...
...
@@ -284,4 +356,25 @@ class AutoCompleteController
return
$response
->
withJson
(
$addresses
);
}
private
static
function
getDataForRequest
(
array
$aArgs
)
{
ValidatorModel
::
notEmpty
(
$aArgs
,
[
'search'
,
'fields'
,
'where'
,
'data'
,
'fieldsNumber'
]);
ValidatorModel
::
stringType
(
$aArgs
,
[
'search'
,
'fields'
]);
ValidatorModel
::
arrayType
(
$aArgs
,
[
'where'
,
'data'
]);
ValidatorModel
::
intType
(
$aArgs
,
[
'fieldsNumber'
]);
$searchItems
=
explode
(
' '
,
$aArgs
[
'search'
]);
foreach
(
$searchItems
as
$item
)
{
if
(
strlen
(
$item
)
>=
2
)
{
$aArgs
[
'where'
][]
=
$aArgs
[
'fields'
];
for
(
$i
=
0
;
$i
<
$aArgs
[
'fieldsNumber'
];
$i
++
)
{
$aArgs
[
'data'
][]
=
"%
{
$item
}
%"
;
}
}
}
return
[
'where'
=>
$aArgs
[
'where'
],
'data'
=>
$aArgs
[
'data'
]];
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment