Skip to content

Commit

Permalink
Merge pull request #6001 from AngelFQC/BT#22232-2
Browse files Browse the repository at this point in the history
Portfolio: Add portfolio_show_base_course_post_in_sessions conf setting
  • Loading branch information
NicoDucou authored Dec 24, 2024
2 parents 8a7a108 + a025de4 commit 31e06df
Show file tree
Hide file tree
Showing 8 changed files with 246 additions and 379 deletions.
48 changes: 41 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 Expand Up @@ -3954,6 +3974,20 @@ private function createCommentForm(Portfolio $item): string
$form->addButtonSave(get_lang('Save'));

if ($form->validate()) {
if ($this->session
&& true === api_get_configuration_value('portfolio_show_base_course_post_in_sessions')
&& !$item->getSession()
) {
$duplicate = $item->duplicateInSession($this->session);

$this->em->persist($duplicate);
$this->em->flush();

$item = $duplicate;

$formAction = $this->baseUrl.http_build_query(['action' => 'view', 'id' => $item->getId()]);
}

$values = $form->exportValues();

$parentComment = $this->em->find(PortfolioComment::class, $values['parent']);
Expand Down
8 changes: 8 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,14 @@
// ALTER TABLE portfolio_comment ADD visibility SMALLINT DEFAULT 1 NOT NULL;
// Then add the "@" symbol to the CPortfolioComment::$visibility property in the ORM\Column() line.
//$_configuration['portfolio_advanced_sharing'] = false;
// Show base course posts in session course. Requires DB changes and edit the Portfolio entity
// adding the "@" symbol to the beginning of ORM\ManyToOne, ORM\JoinColumn, ORM\OneToMany lines for the Portfolio::$duplicatedFrom and Portfolio::$duplicates properties.
/*
ALTER TABLE portfolio ADD duplicated_from INT DEFAULT NULL;
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062FC4CB679 FOREIGN KEY (duplicated_from) REFERENCES portfolio (id) ON DELETE SET NULL;
CREATE INDEX IDX_A9ED1062FC4CB679 ON portfolio (duplicated_from);
*/
//$_configuration['portfolio_show_base_course_post_in_sessions'] = false;

// DEPRECATED: gradebook_enable_best_score is deprecated. Use gradebook_display_extra_stats instead.
// Enable best score column in gradebook. Previously called disable_gradebook_stats
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
Loading

0 comments on commit 31e06df

Please sign in to comment.