Skip to content

Commit 6390ce7

Browse files
committed
Portfolio: Fixes related to resource structure #6836Portfolio: Simplify and fix resource visibility, comments filtering, and advanced sharing logic
1 parent 8bfbba5 commit 6390ce7

10 files changed

Lines changed: 399 additions & 324 deletions

File tree

public/main/inc/lib/PortfolioController.php

Lines changed: 290 additions & 296 deletions
Large diffs are not rendered by default.

public/main/inc/lib/PortfolioNotifier.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ class PortfolioNotifier
1111
public static function notifyTeachersAndAuthor(PortfolioComment $comment)
1212
{
1313
$item = $comment->getItem();
14-
$course = $item->getCourse();
15-
$session = $item->getSession();
14+
$itemResourceLink = $item->getFirstResourceLink();
15+
$course = $itemResourceLink->getCourse();
16+
$session = $itemResourceLink->getSession();
1617

1718
$messageSubject = sprintf(
1819
get_lang('[Portfolio] New comment in post %s'),
1920
$item->getTitle(true)
2021
);
2122
$userIdListToSend = [];
22-
$userIdListToSend[] = $comment->getItem()->getUser()->getId();
23+
$userIdListToSend[] = $comment->getItem()->resourceNode->getCreator()->getId();
2324

2425
$cidreq = api_get_cidreq_params(
2526
$course ? $course->getCode() : '',
@@ -58,7 +59,7 @@ public static function notifyTeachersAndAuthor(PortfolioComment $comment)
5859

5960
$messageContent .= '<br><br><figure>'
6061
.'<blockquote>'.$comment->getExcerpt().'</blockquote>'
61-
.'<figcaption>'.$comment->getAuthor()->getFullName().'</figcaption>'
62+
.'<figcaption>'.$comment->resourceNode->getCreator()->getFullName().'</figcaption>'
6263
.'</figure>';
6364

6465
foreach ($userIdListToSend as $userIdToSend) {
@@ -69,7 +70,6 @@ public static function notifyTeachersAndAuthor(PortfolioComment $comment)
6970
0,
7071
false,
7172
false,
72-
[],
7373
false
7474
);
7575
}
@@ -78,7 +78,7 @@ public static function notifyTeachersAndAuthor(PortfolioComment $comment)
7878
private static function getCourseTitle(CourseEntity $course, ?SessionEntity $session = null): string
7979
{
8080
if ($session) {
81-
return "{$course->getTitle()} ({$session->getName()})";
81+
return "{$course->getTitle()} ({$session->getTitle()})";
8282
}
8383

8484
return $course->getTitle();

src/CoreBundle/Entity/PortfolioComment.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Chamilo\CoreBundle\Entity;
88

9+
use Cocur\Slugify\Slugify;
910
use DateTime;
1011
use Doctrine\ORM\Mapping as ORM;
1112
use Stringable;
@@ -24,7 +25,7 @@ class PortfolioComment extends AbstractResource implements ResourceInterface, St
2425
#[ORM\Id]
2526
#[ORM\GeneratedValue]
2627
#[ORM\Column(type: 'integer')]
27-
private int $id;
28+
private ?int $id = null;
2829

2930
#[ORM\ManyToOne(targetEntity: Portfolio::class, inversedBy: 'comments')]
3031
#[ORM\JoinColumn(name: 'item_id', referencedColumnName: 'id', nullable: false, onDelete: 'CASCADE')]
@@ -143,7 +144,13 @@ public function setVisibility(int $visibility): self
143144

144145
public function getResourceName(): string
145146
{
146-
return 'portfolio_comment_'.$this->id;
147+
if ($this->id) {
148+
return 'portfolio_comment_'.$this->id;
149+
}
150+
151+
return Slugify::create()->slugify(
152+
$this->date->format('c')
153+
);
147154
}
148155

149156
public function setResourceName(string $name): static

src/CoreBundle/Framework/Container.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@
3030
use Chamilo\CoreBundle\Repository\Node\IllustrationRepository;
3131
use Chamilo\CoreBundle\Repository\Node\MessageAttachmentRepository;
3232
use Chamilo\CoreBundle\Repository\Node\PersonalFileRepository;
33+
use Chamilo\CoreBundle\Repository\Node\PortfolioCommentRepository;
3334
use Chamilo\CoreBundle\Repository\Node\PortfolioRepository;
3435
use Chamilo\CoreBundle\Repository\Node\SocialPostAttachmentRepository;
3536
use Chamilo\CoreBundle\Repository\Node\TicketMessageAttachmentRepository;
3637
use Chamilo\CoreBundle\Repository\Node\UsergroupRepository;
3738
use Chamilo\CoreBundle\Repository\Node\UserRepository;
3839
use Chamilo\CoreBundle\Repository\PluginRepository;
3940
use Chamilo\CoreBundle\Repository\PromotionRepository;
41+
use Chamilo\CoreBundle\Repository\ResourceFileRepository;
4042
use Chamilo\CoreBundle\Repository\ResourceNodeRepository;
4143
use Chamilo\CoreBundle\Repository\SequenceRepository;
4244
use Chamilo\CoreBundle\Repository\SequenceResourceRepository;
@@ -710,6 +712,12 @@ public static function getPortfolioRepository(): PortfolioRepository
710712
return self::$container->get(PortfolioRepository::class);
711713
}
712714

715+
public static function getPortfolioCommentRepository(): PortfolioCommentRepository
716+
{
717+
/** @var PortfolioRepository $repo */
718+
return self::$container->get(PortfolioCommentRepository::class);
719+
}
720+
713721
public static function getPortfolioCategoryHelper(): PortfolioCategoryHelper
714722
{
715723
/** @var PortfolioCategoryHelper $helper */
@@ -720,4 +728,9 @@ public static function getSearchIndexPathResolver(): SearchIndexPathResolver
720728
{
721729
return self::$container->get(SearchIndexPathResolver::class);
722730
}
731+
732+
public static function getResourceFileRepository(): ResourceFileRepository
733+
{
734+
return self::$container->get(ResourceFileRepository::class);
735+
}
723736
}

src/CoreBundle/Migrations/Schema/V200/Version20250927180002.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function up(Schema $schema): void
6464

6565
$comment->setParent($resourceParent);
6666

67-
$resourceNode = $portfolioRepo->addResourceNode(
67+
$resourceNode = $commentRepo->addResourceNode(
6868
$comment,
6969
$author,
7070
$resourceParent,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
8+
9+
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
10+
use Doctrine\DBAL\Schema\Schema;
11+
12+
final class Version20260116085000 extends AbstractMigrationChamilo
13+
{
14+
public function getDescription(): string
15+
{
16+
return "Fix duplicated setting with wrong selected value";
17+
}
18+
19+
public function up(Schema $schema): void
20+
{
21+
$itemsType = $this->connection->fetchAssociative(
22+
'SELECT id FROM resource_type WHERE title = ?',
23+
['portfolio_items']
24+
);
25+
$commentsType = $this->connection->fetchAssociative(
26+
'SELECT id FROM resource_type WHERE title = ?',
27+
['portfolio_comments']
28+
);
29+
30+
if (empty($itemsType) || empty($commentsType)) {
31+
return;
32+
}
33+
34+
$this->addSql(sprintf(
35+
'UPDATE resource_node rn INNER JOIN portfolio_comment pc ON rn.id = pc.resource_node_id SET rn.resource_type_id = %d WHERE rn.resource_type_id = %d',
36+
$commentsType['id'],
37+
$itemsType['id']
38+
));
39+
}
40+
41+
public function down(Schema $schema): void
42+
{
43+
}
44+
}

src/CoreBundle/Repository/Node/PortfolioCommentRepository.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,30 @@
1414
use Chamilo\CoreBundle\Traits\Repository\ORM\NestedTreeRepositoryTrait;
1515
use Doctrine\Persistence\ManagerRegistry;
1616

17+
/**
18+
* @extends ResourceRepository<PortfolioComment>
19+
*/
1720
class PortfolioCommentRepository extends ResourceRepository
1821
{
19-
use NestedTreeRepositoryTrait;
20-
2122
public function __construct(ManagerRegistry $registry)
2223
{
2324
parent::__construct($registry, PortfolioComment::class);
2425
}
2526

27+
/**
28+
* @return array<int, PortfolioComment>
29+
*/
30+
public function findTemplatesByUser(User $user): array
31+
{
32+
$qb = $this->getResourcesByCreator($user);
33+
34+
$qb->andWhere(
35+
$qb->expr()->eq('resource.isTemplate', true)
36+
);
37+
38+
return $qb->getQuery()->getResult();
39+
}
40+
2641
public function findCommentsByUser(User $user, ?Course $course, ?Session $session, ?array $orderBy = null): array
2742
{
2843
$qbComments = $this->createQueryBuilder('comment');

src/CoreBundle/Repository/Node/PortfolioRepository.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function getIndexCourseItems(
6666
?Session $session = null,
6767
bool $showBaseContentInSession = false,
6868
bool $listByUser = false,
69-
?DateTime $date = null,
69+
?string $date = null,
7070
array $tags = [],
7171
?string $searchText = null,
7272
array $searchCategories = [],
@@ -88,7 +88,7 @@ public function getIndexCourseItems(
8888

8989
if ($date) {
9090
$queryBuilder
91-
->andWhere('resource.creationDate >= :date')
91+
->andWhere('node.createdAt >= :date')
9292
->setParameter(':date', $date)
9393
;
9494
}
@@ -130,7 +130,7 @@ public function getIndexCourseItems(
130130

131131
if ($listByUser) {
132132
$queryBuilder
133-
->andWhere('resource.user = :user')
133+
->andWhere('node.creator = :user')
134134
->setParameter('user', $owner)
135135
;
136136
}

src/CoreBundle/Resources/views/Portfolio/items.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</a>
6666
{% else %}
6767
<a href="{{ baseurl ~ {'action':'highlighted', 'id':item.id}|url_encode }}">
68-
{{ 'award_red_na.png'|icon(22, 'Mark as highlighted'|get_lang) }}
68+
{{ 'ActionIcon::AWARD'|mdi_icon_t(22, 'ch-tool-icon', 'Mark as highlighted'|get_lang) }}
6969
</a>
7070
{% endif %}
7171
{% endif %}

src/CoreBundle/Resources/views/Portfolio/view.html.twig

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
{% autoescape false %}
12
{% if item.isHighlighted %}
23
<span class="label label-success">
34
{{ 'ActionIcon::STAR'|mdi_icon(22) }}
4-
{{ 'Highlighted'|get_lang }}
5+
{{ 'Highlighted'|trans }}
56
</span>
67
{% endif %}
78

@@ -12,36 +13,36 @@
1213
<ul class="fa-ul list-inline">
1314
<li>
1415
<span class="fa-li fa fa-user" aria-hidden="true"></span>
15-
{{ item.user.completeName }}
16+
{{ item.creator.fullName }}
1617
</li>
1718
<li>
1819
<span class="fa-li fa fa-clock-o" aria-hidden="true"></span>
19-
{{ 'Creation date'|get_lang ~ ': ' }}
20-
{{ item.creationDate|date_to_time_ago }}
20+
{{ 'Creation date'|trans ~ ': ' }}
21+
{{ item.resourceNode.createdAt|date_to_time_ago }}
2122
</li>
2223

2324
{% if last_edit %}
2425
<li>
2526
<span class="fa-li fa fa-clock-o" aria-hidden="true"></span>
26-
{{ 'Updated on %s by %s'|get_lang|format(last_edit.date|date_to_time_ago, last_edit.user) }}
27+
{{ 'Updated on %s by %s'|trans|format(last_edit.date|date_to_time_ago, last_edit.user) }}
2728
</li>
28-
{% elseif item.creationDate != item.updateDate %}
29+
{% elseif item.resourceNode.createdAt != item.resourceNode.updatedAte %}
2930
<li>
3031
<span class="fa-li fa fa fa-clock-o" aria-hidden="true"></span>
31-
{{ 'Updated on %s'|get_lang|format(item.updateDate|date_to_time_ago) }}
32+
{{ 'Updated on %s'|trans|format(item.resourceNode.updateDate|date_to_time_ago) }}
3233
</li>
3334
{% endif %}
3435

35-
{% if _c is empty %}
36-
{% if item.session %}
36+
{% if course is empty %}
37+
{% if session %}
3738
<li>
3839
<span class="fa-li fa fa-book" aria-hidden="true"></span>
39-
{{ 'Course'|get_lang ~ ': ' ~ item.session.name ~ ' (' ~ item.course.title ~ ')' }}
40+
{{ 'Course'|trans ~ ': ' ~ session.name ~ ' (' ~ course.title ~ ')' }}
4041
</li>
41-
{% elseif not item.session and item.course %}
42+
{% elseif not session and course %}
4243
<li>
4344
<span class="fa-li fa fa-book" aria-hidden="true"></span>
44-
{{ 'Course'|get_lang ~ ': ' ~ item.course.title }}
45+
{{ 'Course'|trans ~ ': ' ~ course.title }}
4546
</li>
4647
{% endif %}
4748
{% endif %}
@@ -59,7 +60,7 @@
5960
<section id="portfolio-item-comments">
6061
<h1 class="h3">
6162
{{ 'ActionIcon::COMMENT'|mdi_icon(22) }}
62-
{{ 'XComments'|get_lang|format(count_comments) }}
63+
{{ '%s comments'|trans|format(count_comments) }}
6364
</h1>
6465

6566
{{ comments }}
@@ -95,3 +96,4 @@
9596
});
9697
});
9798
</script>
99+
{% endautoescape %}

0 commit comments

Comments
 (0)