Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Marcus Eibrink-Lunzenauer
Stud.IP
Commits
73a5531e
Commit
73a5531e
authored
2 months ago
by
Jan-Hendrik Willms
Browse files
Options
Downloads
Patches
Plain Diff
fix search in StudipSemSearchHelper, fixes #5105
Closes #5105 Merge request
studip/studip!3820
parent
1d6da9b1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/classes/StudipSemSearchHelper.php
+71
-17
71 additions, 17 deletions
lib/classes/StudipSemSearchHelper.php
with
71 additions
and
17 deletions
lib/classes/StudipSemSearchHelper.php
+
71
−
17
View file @
73a5531e
...
...
@@ -53,14 +53,14 @@ class StudipSemSearchHelper {
public
function
setParams
(
$params
,
$visible_only
=
null
)
{
if
(
isset
(
$params
[
'quick_search'
]
)
&&
isset
(
$params
[
'qs_choose'
])){
if
(
$params
[
'qs_choose'
]
==
'all'
){
foreach
(
self
::
GetQuickSearchFields
()
as
$key
=>
$value
){
if
(
isset
(
$params
[
'quick_search'
]
,
$params
[
'qs_choose'
]))
{
if
(
$params
[
'qs_choose'
]
==
=
'all'
){
foreach
(
self
::
GetQuickSearchFields
()
as
$key
=>
$value
)
{
$params
[
$key
]
=
$this
->
trim
(
$params
[
'quick_search'
]);
}
$params
[
'combination'
]
=
'OR'
;
}
elseif
(
$params
[
'qs_choose'
]
==
'title_lecturer_number'
)
{
foreach
(
explode
(
'_'
,
'title_lecturer_number'
)
as
$key
){
}
elseif
(
$params
[
'qs_choose'
]
==
'title_lecturer_number'
)
{
foreach
(
explode
(
'_'
,
'title_lecturer_number'
)
as
$key
)
{
$params
[
$key
]
=
$this
->
trim
(
$params
[
'quick_search'
]);
}
$params
[
'combination'
]
=
'OR'
;
...
...
@@ -68,7 +68,11 @@ class StudipSemSearchHelper {
$params
[
$params
[
'qs_choose'
]]
=
$this
->
trim
(
$params
[
'quick_search'
]);
}
}
if
(
!
isset
(
$params
[
'combination'
]))
$params
[
'combination'
]
=
'AND'
;
if
(
!
isset
(
$params
[
'combination'
]))
{
$params
[
'combination'
]
=
'AND'
;
}
$this
->
params
=
$params
;
$this
->
visible_only
=
$visible_only
;
}
...
...
@@ -78,7 +82,6 @@ class StudipSemSearchHelper {
if
(
count
(
$this
->
params
)
===
0
)
{
return
false
;
}
$this
->
params
=
array_map
(
'addslashes'
,
$this
->
params
);
$db
=
DBManager
::
get
();
$join_sql
=
[];
...
...
@@ -164,16 +167,7 @@ class StudipSemSearchHelper {
$sql_params
[
'institute_ids'
]
=
$institute_ids
;
}
if
(
isset
(
$this
->
params
[
'lecturer'
])
&&
mb_strlen
(
$this
->
params
[
'lecturer'
])
>
2
)
{
//Search for lecturers:
$join_sql
[]
=
"JOIN `seminar_user` USING (`seminar_id`)"
;
$join_sql
[]
=
"JOIN `auth_user_md5` USING (`user_id`)"
;
$where_sql
[]
=
"(
CONCAT(`auth_user_md5`.`Nachname`, ', ', `auth_user_md5`.`Vorname`, ' ', `auth_user_md5`.`Nachname`) LIKE CONCAT('%', :lecturer_name, '%')
OR `auth_user_md5`.`username` LIKE CONCAT('%', :lecturer_name, '%')
)"
;
$sql_params
[
'lecturer_name'
]
=
$this
->
params
[
'lecturer'
];
}
$this
->
getSearchCondition
(
$where_sql
,
$join_sql
,
$sql_params
);
$query
=
sprintf
(
'SELECT DISTINCT `seminar_id` FROM `seminare` %s WHERE %s'
,
...
...
@@ -193,4 +187,64 @@ class StudipSemSearchHelper {
$what
=
preg_replace
(
"/^\x
{
00A0}+|\x{00A0
}
+$/Su"
,
''
,
$what
);
return
$what
;
}
private
function
hasSearchParam
(
string
$key
):
bool
{
return
isset
(
$this
->
params
[
$key
])
&&
mb_strlen
(
$this
->
params
[
$key
])
>
2
;
}
private
function
getSearchCondition
(
array
&
$where_sql
,
array
&
$join_sql
,
array
&
$sql_params
):
void
{
$conditions
=
[];
if
(
$this
->
hasSearchParam
(
'lecturer'
))
{
//Search for lecturers:
$join_sql
[]
=
"JOIN `seminar_user` USING (`seminar_id`)"
;
$join_sql
[]
=
"JOIN `auth_user_md5` USING (`user_id`)"
;
$conditions
[]
=
"(
CONCAT(`auth_user_md5`.`Nachname`, ', ', `auth_user_md5`.`Vorname`, ' ', `auth_user_md5`.`Nachname`) LIKE CONCAT('%', :lecturer_name, '%')
OR `auth_user_md5`.`username` LIKE CONCAT('%', :lecturer_name, '%')
)"
;
$sql_params
[
'lecturer_name'
]
=
$this
->
params
[
'lecturer'
];
}
if
(
$this
->
hasSearchParam
(
'number'
))
{
$conditions
[]
=
"`seminare`.`VeranstaltungsNummer` LIKE CONCAT('%', :number, '%')"
;
$sql_params
[
'number'
]
=
$this
->
params
[
'number'
];
}
if
(
$this
->
hasSearchParam
(
'title'
))
{
$terms
=
explode
(
' '
,
$this
->
params
[
'title'
]);
$terms
=
array_map
(
'trim'
,
$terms
);
$terms
=
array_filter
(
$terms
);
$terms
=
array_unique
(
$terms
);
$chunks
=
[];
foreach
(
$terms
as
$index
=>
$term
)
{
$chunks
[]
=
"`seminare`.`Name` LIKE CONCAT('%', :title
{
$index
}
, '%')"
;
$sql_params
[
'title'
.
$index
]
=
$term
;
}
$conditions
[]
=
'('
.
implode
(
' AND '
,
$chunks
)
.
')'
;
}
if
(
$this
->
hasSearchParam
(
'sub_title'
))
{
$conditions
[]
=
"`seminare`.`Untertitel` LIKE CONCAT('%', :sub_title, '%')"
;
$sql_params
[
'sub_title'
]
=
$this
->
params
[
'sub_title'
];
}
if
(
$this
->
hasSearchParam
(
'comment'
))
{
$conditions
[]
=
"`seminare`.`Beschreibung` LIKE CONCAT('%', :description, '%')"
;
$sql_params
[
'description'
]
=
$this
->
params
[
'comment'
];
}
if
(
count
(
$conditions
)
>
0
)
{
$where_sql
[]
=
'('
.
implode
(
' '
.
$this
->
params
[
'combination'
]
.
' '
,
$conditions
)
.
')'
;
}
}
}
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