Skip to content

Commit 31e06df

Browse files
authored
Merge pull request #6001 from AngelFQC/BT#22232-2
Portfolio: Add portfolio_show_base_course_post_in_sessions conf setting
2 parents 8a7a108 + a025de4 commit 31e06df

File tree

8 files changed

+246
-379
lines changed

8 files changed

+246
-379
lines changed

main/inc/lib/PortfolioController.php

Lines changed: 41 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;
@@ -3954,6 +3974,20 @@ private function createCommentForm(Portfolio $item): string
39543974
$form->addButtonSave(get_lang('Save'));
39553975

39563976
if ($form->validate()) {
3977+
if ($this->session
3978+
&& true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions')
3979+
&& !$item->getSession()
3980+
) {
3981+
$duplicate = $item->duplicateInSession($this->session);
3982+
3983+
$this->em->persist($duplicate);
3984+
$this->em->flush();
3985+
3986+
$item = $duplicate;
3987+
3988+
$formAction = $this->baseUrl.http_build_query(['action' => 'view', 'id' => $item->getId()]);
3989+
}
3990+
39573991
$values = $form->exportValues();
39583992

39593993
$parentComment = $this->em->find(PortfolioComment::class, $values['parent']);

main/install/configuration.dist.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,14 @@
11321132
// ALTER TABLE portfolio_comment ADD visibility SMALLINT DEFAULT 1 NOT NULL;
11331133
// Then add the "@" symbol to the CPortfolioComment::$visibility property in the ORM\Column() line.
11341134
//$_configuration['portfolio_advanced_sharing'] = false;
1135+
// Show base course posts in session course. Requires DB changes and edit the Portfolio entity
1136+
// adding the "@" symbol to the beginning of ORM\ManyToOne, ORM\JoinColumn, ORM\OneToMany lines for the Portfolio::$duplicatedFrom and Portfolio::$duplicates properties.
1137+
/*
1138+
ALTER TABLE portfolio ADD duplicated_from INT DEFAULT NULL;
1139+
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062FC4CB679 FOREIGN KEY (duplicated_from) REFERENCES portfolio (id) ON DELETE SET NULL;
1140+
CREATE INDEX IDX_A9ED1062FC4CB679 ON portfolio (duplicated_from);
1141+
*/
1142+
//$_configuration['portfolio_show_base_course_post_in_sessions'] = false;
11351143

11361144
// DEPRECATED: gradebook_enable_best_score is deprecated. Use gradebook_display_extra_stats instead.
11371145
// Enable best score column in gradebook. Previously called disable_gradebook_stats

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)