Skip to content
Closed
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
74 changes: 48 additions & 26 deletions main/inc/lib/PortfolioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@

use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
use Chamilo\CoreBundle\Entity\Course as CourseEntity;
use Chamilo\CoreBundle\Entity\CourseRelUser;
use Chamilo\CoreBundle\Entity\ExtraField as ExtraFieldEntity;
use Chamilo\CoreBundle\Entity\ExtraFieldRelTag;
use Chamilo\CoreBundle\Entity\Portfolio;
use Chamilo\CoreBundle\Entity\PortfolioAttachment;
use Chamilo\CoreBundle\Entity\PortfolioCategory;
use Chamilo\CoreBundle\Entity\PortfolioComment;
use Chamilo\CoreBundle\Entity\PortfolioRelTag;
use Chamilo\CoreBundle\Entity\SessionRelUser;
use Chamilo\CoreBundle\Entity\Tag;
use Chamilo\CourseBundle\Entity\CItemProperty;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Mpdf\MpdfException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
Expand Down Expand Up @@ -1203,6 +1206,8 @@ public function view(Portfolio $item)
;
}

$this->filterCommentsByCourseAndSession($commentsQueryBuilder);

$comments = $commentsQueryBuilder
->orderBy('comment.root, comment.lft', 'ASC')
->setParameter('item', $item)
Expand Down Expand Up @@ -1866,13 +1871,7 @@ public function details(HttpRequest $httpRequest)
->andWhere('i.course = :course')
->setParameter('course', $this->course);

if ($this->session) {
$qb
->andWhere('i.session = :session')
->setParameter('session', $this->session);
} else {
$qb->andWhere('i.session IS NULL');
}
$this->applySessionCondition($qb, 'i.session');
}

if ($isAllowedToFilterStudent && $currentUserId !== $this->owner->getId()) {
Expand Down Expand Up @@ -1901,13 +1900,7 @@ public function details(HttpRequest $httpRequest)
->andWhere('item.course = :course_id')
->setParameter('course_id', $this->course);

if ($this->session) {
$qb
->andWhere('item.session = :session')
->setParameter('session', $this->session);
} else {
$qb->andWhere('item.session IS NULL');
}
$this->applySessionCondition($qb, 'item.session');
}

if ($isAllowedToFilterStudent && $currentUserId !== $this->owner->getId()) {
Expand Down Expand Up @@ -3700,12 +3693,7 @@ private function getHighlightedItems()
->andWhere('pi.isHighlighted = TRUE')
->setParameter('course', $this->course);

if ($this->session) {
$queryBuilder->andWhere('pi.session = :session');
$queryBuilder->setParameter('session', $this->session);
} else {
$queryBuilder->andWhere('pi.session IS NULL');
}
$this->applySessionCondition($queryBuilder, 'pi.session');

if ($this->advancedSharingEnabled) {
$queryBuilder
Expand Down Expand Up @@ -3770,12 +3758,7 @@ private function getItemsForIndex(

$queryBuilder->setParameter('course', $this->course);

if ($this->session) {
$queryBuilder->andWhere('pi.session = :session');
$queryBuilder->setParameter('session', $this->session);
} else {
$queryBuilder->andWhere('pi.session IS NULL');
}
$this->applySessionCondition($queryBuilder, 'pi.session');

if ($frmFilterList && $frmFilterList->validate()) {
$values = $frmFilterList->exportValues();
Expand Down Expand Up @@ -4398,6 +4381,8 @@ private function getCommentsForIndex(FormValidator $frmFilterList = null): array
;
}

$this->filterCommentsByCourseAndSession($queryBuilder);

$queryBuilder->orderBy('c.date', 'DESC');

return $queryBuilder->getQuery()->getResult();
Expand Down Expand Up @@ -4430,4 +4415,41 @@ private function getLabelForCommentDate(PortfolioComment $comment): string

return $dateLabel;
}

// Rename this function properly
private function applySessionCondition(QueryBuilder $queryBuilder, string $sessionField)
{
$sessionCondition = api_get_session_condition(
$this->session ? $this->session->getId() : 0,
false,
api_get_configuration_value('portfolio_show_base_course_post_in_sessions'),
$sessionField,
true
);
$queryBuilder->andWhere($sessionCondition);
}

private function filterCommentsByCourseAndSession(QueryBuilder $queryBuilder)
{
if ($this->course) {
if ($this->session) {
$studentIdList = $this->session->getUsers()->map(fn(SessionRelUser $sru) => $sru->getUser()->getId());

if ($this->session->getSessionAdminId()) {
$studentIdList->add($this->session->getSessionAdminId());
}

if ($generalCoach = $this->session->getGeneralCoach()) {
$studentIdList->add($generalCoach->getId());
}
} else {
$studentIdList = $this->course->getUsers()->map(fn(CourseRelUser $cru) => $cru->getUser()->getId());
}

$queryBuilder
->andWhere('comment.author IN (:students)')
->setParameter('students', $studentIdList->getValues())
;
}
}
}
7 changes: 6 additions & 1 deletion main/inc/lib/api.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3044,7 +3044,8 @@ function api_get_session_condition(
$session_id,
$and = true,
$with_base_content = false,
$session_field = 'session_id'
$session_field = 'session_id',
bool $avoidConditionType = false
) {
$session_id = (int) $session_id;

Expand All @@ -3054,6 +3055,10 @@ function api_get_session_condition(
// Condition to show resources by session
$condition_add = $and ? ' AND ' : ' WHERE ';

if ($avoidConditionType) {
$condition_add = '';
}

if ($with_base_content) {
$condition_session = $condition_add." ( $session_field = $session_id OR $session_field = 0 OR $session_field IS NULL) ";
} else {
Expand Down
2 changes: 2 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,8 @@
// 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
//$_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
8 changes: 4 additions & 4 deletions main/template/default/portfolio/items.html.twig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% macro display(items, category_id, _c, _u, _p) %}
{% macro display(items, category_id, course, session, _u, _p) %}
{% set edit_img = 'edit.png'|img(22, 'Edit'|get_lang) %}
{% set visible_img = 'visible.png'|img(22, 'Invisible'|get_lang) %}
{% set invisible_img = 'invisible.png'|img(22, 'Visible'|get_lang) %}
{% set delete_img = 'delete.png'|img(22, 'Delete'|get_lang) %}
{% set baseurl = _p.web_self ~ '?' ~ (_p.web_cid_query ? _p.web_cid_query ~ '&' : '') %}
{% set is_advanced_sharing_enabled = 'portfolio_advanced_sharing'|api_get_configuration_value and not _c is empty %}
{% set is_advanced_sharing_enabled = 'portfolio_advanced_sharing'|api_get_configuration_value and course %}

<section class="portfolio-items">
{% for item in items %}
{% set item_url = baseurl ~ {'action':'view', 'id':item.id}|url_encode %}
{% set comments = item.lastComments(3, is_advanced_sharing_enabled) %}
{% set comments = item.lastComments(3, is_advanced_sharing_enabled, course, session) %}

<div class="panel panel-default">
<article class="panel-body portfolio-item" id="portfolio-item-{{ item.id }}">
Expand Down Expand Up @@ -74,7 +74,7 @@
</h3>

<ul class="fa-ul list-inline">
{% if _c is empty %}
{% if course %}
{% if item.session %}
<li>
<span class="fa-li fa fa-book" aria-hidden="true"></span>
Expand Down
5 changes: 3 additions & 2 deletions main/template/default/portfolio/list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<h4 class="page-header">{{ 'Posts'|get_lang }}</h4>
{% endif %}

{{ items.display(uncategorized_items, 0, _c, _u, _p) }}
{{ items.display(uncategorized_items, 0, course, session, _u, _p) }}

{% if found_comments %}
<section>
Expand Down Expand Up @@ -127,7 +127,8 @@
items.display(
category.items(course, session, _u.id != category.user.id),
category.id,
_c,
course,
session,
_u,
_p
)
Expand Down
28 changes: 26 additions & 2 deletions src/Chamilo/CoreBundle/Entity/Portfolio.php
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,12 @@ public function getComments(): Collection
return $this->comments;
}

public function getLastComments(int $number = 3, bool $avoidPerUserVisibility = false): Collection
{
public function getLastComments(
int $number = 3,
bool $avoidPerUserVisibility = false,
?Course $course = null,
?Session $session = null
): Collection {
$criteria = Criteria::create();
$criteria
->orderBy(['date' => 'DESC'])
Expand All @@ -389,6 +393,26 @@ public function getLastComments(int $number = 3, bool $avoidPerUserVisibility =
);
}

if ($course) {
if ($session) {
$studentIdList = $session->getUsers()->map(fn(SessionRelUser $sru) => $sru->getUser()->getId());

if ($session->getSessionAdminId()) {
$studentIdList->add($session->getSessionAdminId());
}

if ($generalCoach = $session->getGeneralCoach()) {
$studentIdList->add($generalCoach->getId());
}
} else {
$studentIdList = $course->getUsers()->map(fn(CourseRelUser $cru) => $cru->getUser()->getId());
}

$criteria->andWhere(
Criteria::expr()->in('author', $studentIdList->getValues())
);
}

return $this->comments->matching($criteria);
}

Expand Down
Loading