Skip to content

Commit 918416a

Browse files
committed
Portfolio: List course base content in session when portfolio_show_base_course_post_in_sessions is enabled - refs BT#22232
1 parent e661cbb commit 918416a

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

main/inc/lib/PortfolioController.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,12 +1203,18 @@ public function view(Portfolio $item)
12031203
;
12041204
}
12051205

1206-
$comments = $commentsQueryBuilder
1207-
->orderBy('comment.root, comment.lft', 'ASC')
1208-
->setParameter('item', $item)
1209-
->getQuery()
1210-
->getArrayResult()
1211-
;
1206+
if (true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions')
1207+
&& $this->session && !$item->getSession() && !$item->isDuplicatedInSession($this->session)
1208+
) {
1209+
$comments = [];
1210+
} else {
1211+
$comments = $commentsQueryBuilder
1212+
->orderBy('comment.root, comment.lft', 'ASC')
1213+
->setParameter('item', $item)
1214+
->getQuery()
1215+
->getArrayResult()
1216+
;
1217+
}
12121218

12131219
$clockIcon = Display::returnFontAwesomeIcon('clock-o', '', true);
12141220

@@ -3762,6 +3768,9 @@ private function getItemsForIndex(
37623768
$currentUserId = api_get_user_id();
37633769

37643770
if ($this->course) {
3771+
$showBaseContentInSession = $this->session
3772+
&& true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions');
3773+
37653774
$queryBuilder = $this->em->createQueryBuilder();
37663775
$queryBuilder
37673776
->select('pi')
@@ -3771,7 +3780,9 @@ private function getItemsForIndex(
37713780
$queryBuilder->setParameter('course', $this->course);
37723781

37733782
if ($this->session) {
3774-
$queryBuilder->andWhere('pi.session = :session');
3783+
$queryBuilder->andWhere(
3784+
$showBaseContentInSession ? 'pi.session = :session OR pi.session IS NULL' : 'pi.session = :session'
3785+
);
37753786
$queryBuilder->setParameter('session', $this->session);
37763787
} else {
37773788
$queryBuilder->andWhere('pi.session IS NULL');
@@ -3894,6 +3905,15 @@ private function getItemsForIndex(
38943905
$queryBuilder->orderBy('pi.creationDate', 'DESC');
38953906

38963907
$items = $queryBuilder->getQuery()->getResult();
3908+
3909+
if ($showBaseContentInSession) {
3910+
$items = array_filter(
3911+
$items,
3912+
fn(Portfolio $item) => !($this->session && !$item->getSession() && $item->isDuplicatedInSession($this->session))
3913+
);
3914+
}
3915+
3916+
return $items;
38973917
} else {
38983918
$itemsCriteria = [];
38993919
$itemsCriteria['category'] = null;

main/template/default/portfolio/items.html.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
{% set item_url = baseurl ~ {'action':'view', 'id':item.id}|url_encode %}
1212
{% set comments = item.lastComments(3, is_advanced_sharing_enabled) %}
1313

14+
{% if 'portfolio_show_base_course_post_in_sessions'|api_get_configuration_value %}
15+
{% if _c.session_id and not item.session and not item.isDuplicatedInSessionId(_c.session_id) %}
16+
{% set comments = {} %}
17+
{% endif %}
18+
{% endif %}
19+
1420
<div class="panel panel-default">
1521
<article class="panel-body portfolio-item" id="portfolio-item-{{ item.id }}">
1622
<div class="portfolio-actions pull-right">

0 commit comments

Comments
 (0)