Skip to content

Portfolio: Add portfolio_show_base_course_post_in_sessions conf setting #6001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading