Skip to content

Commit

Permalink
Portfolio: List course base content in session when portfolio_show_ba…
Browse files Browse the repository at this point in the history
…se_course_post_in_sessions is enabled - refs BT#22232
  • Loading branch information
AngelFQC committed Dec 23, 2024
1 parent e661cbb commit 918416a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
34 changes: 27 additions & 7 deletions main/inc/lib/PortfolioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1203,12 +1203,18 @@ public function view(Portfolio $item)
;
}

$comments = $commentsQueryBuilder
->orderBy('comment.root, comment.lft', 'ASC')
->setParameter('item', $item)
->getQuery()
->getArrayResult()
;
if (true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions')
&& $this->session && !$item->getSession() && !$item->isDuplicatedInSession($this->session)
) {
$comments = [];
} else {
$comments = $commentsQueryBuilder
->orderBy('comment.root, comment.lft', 'ASC')
->setParameter('item', $item)
->getQuery()
->getArrayResult()
;
}

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

Expand Down Expand Up @@ -3762,6 +3768,9 @@ private function getItemsForIndex(
$currentUserId = api_get_user_id();

if ($this->course) {
$showBaseContentInSession = $this->session
&& true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions');

$queryBuilder = $this->em->createQueryBuilder();
$queryBuilder
->select('pi')
Expand All @@ -3771,7 +3780,9 @@ private function getItemsForIndex(
$queryBuilder->setParameter('course', $this->course);

if ($this->session) {
$queryBuilder->andWhere('pi.session = :session');
$queryBuilder->andWhere(
$showBaseContentInSession ? 'pi.session = :session OR pi.session IS NULL' : 'pi.session = :session'
);
$queryBuilder->setParameter('session', $this->session);
} else {
$queryBuilder->andWhere('pi.session IS NULL');
Expand Down Expand Up @@ -3894,6 +3905,15 @@ private function getItemsForIndex(
$queryBuilder->orderBy('pi.creationDate', 'DESC');

$items = $queryBuilder->getQuery()->getResult();

if ($showBaseContentInSession) {
$items = array_filter(
$items,
fn(Portfolio $item) => !($this->session && !$item->getSession() && $item->isDuplicatedInSession($this->session))
);
}

return $items;
} else {
$itemsCriteria = [];
$itemsCriteria['category'] = null;
Expand Down
6 changes: 6 additions & 0 deletions main/template/default/portfolio/items.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
{% set item_url = baseurl ~ {'action':'view', 'id':item.id}|url_encode %}
{% set comments = item.lastComments(3, is_advanced_sharing_enabled) %}

{% if 'portfolio_show_base_course_post_in_sessions'|api_get_configuration_value %}
{% if _c.session_id and not item.session and not item.isDuplicatedInSessionId(_c.session_id) %}
{% set comments = {} %}
{% endif %}
{% endif %}

<div class="panel panel-default">
<article class="panel-body portfolio-item" id="portfolio-item-{{ item.id }}">
<div class="portfolio-actions pull-right">
Expand Down

0 comments on commit 918416a

Please sign in to comment.