Skip to content

Commit 72cd606

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 72cd606

11 files changed

Lines changed: 684 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 wrong resource type for portfolio comments";
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+
}

0 commit comments

Comments
 (0)