Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sg_news
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TYPO3
sg_news
Commits
21b1fb6d
Verified
Commit
21b1fb6d
authored
3 years ago
by
Kevin Ditscheid
Browse files
Options
Downloads
Patches
Plain Diff
[TASK] Add comments to the findRelated functionality
parent
ec1b1a90
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!41
[TASK] Add related news by tag or category
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Classes/Domain/Repository/NewsRepository.php
+15
-8
15 additions, 8 deletions
Classes/Domain/Repository/NewsRepository.php
with
15 additions
and
8 deletions
Classes/Domain/Repository/NewsRepository.php
+
15
−
8
View file @
21b1fb6d
...
...
@@ -518,6 +518,7 @@ class NewsRepository extends AbstractRepository {
public
function
findRelated
(
News
$news
,
int
$limit
=
0
)
{
$connection
=
$this
->
getConnection
();
$qb
=
$connection
->
createQueryBuilder
();
// We need to build the constraint for the tags/categories
$constraints
=
[];
$tags
=
$news
->
getTags
();
if
(
$tags
->
count
()
>
0
)
{
...
...
@@ -533,6 +534,7 @@ class NewsRepository extends AbstractRepository {
$constraints
[]
=
$qb
->
expr
()
->
eq
(
'pid'
,
$news
->
getPid
());
}
// here we fetch the lastUpdated of the $limit amount of news with newer lastUpdated dates
$result
=
$qb
->
select
(
'lastUpdated'
)
->
from
(
'pages'
)
->
where
(
...
...
@@ -541,10 +543,11 @@ class NewsRepository extends AbstractRepository {
$qb
->
expr
()
->
andX
(
...
$constraints
)
)
->
setMaxResults
(
$limit
)
->
orderBy
(
'lastUpdated'
,
'
a
sc'
)
->
orderBy
(
'lastUpdated'
,
'
de
sc'
)
->
execute
();
$
max
=
$result
->
fetchOne
();
$
newest
=
$result
->
fetchOne
();
// Here we fetch the lastUpdated of the $limit amount of news with older lastUpdated dates
$result
=
$qb
->
select
(
'lastUpdated'
)
->
from
(
'pages'
)
->
where
(
...
...
@@ -553,9 +556,9 @@ class NewsRepository extends AbstractRepository {
$qb
->
expr
()
->
andX
(
...
$constraints
)
)
->
setMaxResults
(
$limit
)
->
orderBy
(
'lastUpdated'
,
'
de
sc'
)
->
orderBy
(
'lastUpdated'
,
'
a
sc'
)
->
execute
();
$
min
=
$result
->
fetchOne
();
$
oldest
=
$result
->
fetchOne
();
$query
=
$this
->
createQuery
();
$query
->
getQuerySettings
()
->
setRespectStoragePage
(
FALSE
);
...
...
@@ -563,13 +566,17 @@ class NewsRepository extends AbstractRepository {
'crdate'
=>
QueryInterface
::
ORDER_DESCENDING
]);
$constraints
=
[];
if
(
$
max
)
{
$constraints
[]
=
$query
->
lessThan
(
'lastUpdated'
,
$
max
);
if
(
$
newest
)
{
$constraints
[]
=
$query
->
lessThan
OrEqual
(
'lastUpdated'
,
$
newest
);
}
if
(
$
min
)
{
$constraints
[]
=
$query
->
greaterThan
(
'lastUpdated'
,
$
min
);
if
(
$
oldest
)
{
$constraints
[]
=
$query
->
greaterThan
OrEqual
(
'lastUpdated'
,
$
oldest
);
}
// Now we fetch the $limit amount of news via extbase query and limit them to the newest and oldest date
// remember, we fetched the oldest and newest date from the $limit amount of news newer and older then
// the given news. If we limit the result of the following query to $limit, we get $limit amount of news
// "around" the given news, where newer news are preferred due to the ordering.
$tags
=
$news
->
getTags
();
if
(
$tags
->
count
()
>
0
)
{
foreach
(
$tags
as
$tag
)
{
...
...
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