Minor: Format code

pull/4677/head^2
Angel Fernando Quiroz Campos 3 years ago
parent 65e7d1d14c
commit e5397dfaa2
  1. 2
      public/main/announcements/announcements.php
  2. 2
      public/main/gradebook/lib/be/category.class.php
  3. 2
      public/main/inc/lib/document.lib.php
  4. 2
      public/main/inc/lib/tracking.lib.php
  5. 2
      public/main/my_space/myStudents.php
  6. 2
      public/main/my_space/student.php
  7. 2
      public/main/my_space/teachers.php
  8. 2
      public/main/my_space/users.php
  9. 2
      public/main/tracking/messages.php
  10. 3
      src/CoreBundle/Component/Utils/ChamiloApi.php
  11. 19
      src/CoreBundle/Controller/Admin/IndexBlocksController.php
  12. 3
      src/CoreBundle/Controller/SecurityController.php
  13. 48
      src/CoreBundle/DataProvider/Extension/CCalendarEventExtension.php
  14. 26
      src/CoreBundle/DataProvider/Extension/CDocumentExtension.php
  15. 25
      src/CoreBundle/DataProvider/Extension/CToolIntroExtension.php
  16. 12
      src/CoreBundle/DataProvider/Extension/CourseExtension.php
  17. 6
      src/CoreBundle/DataProvider/Extension/CourseRelUserExtension.php
  18. 30
      src/CoreBundle/DataProvider/Extension/MessageExtension.php
  19. 6
      src/CoreBundle/DataProvider/Extension/MessageTagExtension.php
  20. 32
      src/CoreBundle/DataProvider/Extension/PageExtension.php
  21. 16
      src/CoreBundle/DataProvider/Extension/PersonalFileExtension.php
  22. 7
      src/CoreBundle/DataProvider/Extension/SessionRelUserExtension.php
  23. 5
      src/CoreBundle/DataProvider/Extension/SocialPostExtension.php
  24. 5
      src/CoreBundle/DataProvider/Extension/TrackEExerciseExtension.php
  25. 25
      src/CoreBundle/DataProvider/Extension/UserRelUserExtension.php
  26. 12
      src/CoreBundle/Entity/AbstractResource.php
  27. 10
      src/CoreBundle/Entity/AccessUrl.php
  28. 3
      src/CoreBundle/Entity/AccessUrlRelCourse.php
  29. 139
      src/CoreBundle/Entity/AgendaEventInvitation.php
  30. 72
      src/CoreBundle/Entity/AgendaEventInvitee.php
  31. 14
      src/CoreBundle/Entity/AgendaEventSubscriber.php
  32. 34
      src/CoreBundle/Entity/AgendaEventSubscription.php
  33. 103
      src/CoreBundle/Entity/AgendaReminder.php
  34. 8
      src/CoreBundle/Entity/Asset.php
  35. 7
      src/CoreBundle/Entity/BranchSync.php
  36. 34
      src/CoreBundle/Entity/Course.php
  37. 8
      src/CoreBundle/Entity/CourseCategory.php
  38. 2
      src/CoreBundle/Entity/CourseRelUser.php
  39. 3
      src/CoreBundle/Entity/CourseRelUserCatalogue.php
  40. 82
      src/CoreBundle/Entity/ExtraField.php
  41. 39
      src/CoreBundle/Entity/ExtraFieldValues.php
  42. 45
      src/CoreBundle/Entity/GradebookCategory.php
  43. 18
      src/CoreBundle/Entity/Group.php
  44. 29
      src/CoreBundle/Entity/Illustration.php
  45. 4
      src/CoreBundle/Entity/Language.php
  46. 3
      src/CoreBundle/Entity/Level.php
  47. 6
      src/CoreBundle/Entity/Listener/CourseListener.php
  48. 5
      src/CoreBundle/Entity/Listener/MessageListener.php
  49. 8
      src/CoreBundle/Entity/Listener/ResourceListener.php
  50. 9
      src/CoreBundle/Entity/Listener/ResourceNodeListener.php
  51. 6
      src/CoreBundle/Entity/Listener/SessionListener.php
  52. 8
      src/CoreBundle/Entity/Listener/SkillRelUserListener.php
  53. 6
      src/CoreBundle/Entity/Listener/UserListener.php
  54. 5
      src/CoreBundle/Entity/Listener/UserRelUserListener.php
  55. 159
      src/CoreBundle/Entity/Message.php
  56. 43
      src/CoreBundle/Entity/MessageAttachment.php
  57. 172
      src/CoreBundle/Entity/MessageFeedback.php
  58. 50
      src/CoreBundle/Entity/MessageRelUser.php
  59. 46
      src/CoreBundle/Entity/MessageTag.php
  60. 65
      src/CoreBundle/Entity/Page.php
  61. 51
      src/CoreBundle/Entity/PageCategory.php
  62. 36
      src/CoreBundle/Entity/PersonalFile.php
  63. 119
      src/CoreBundle/Entity/Portfolio.php
  64. 135
      src/CoreBundle/Entity/PortfolioAttachment.php
  65. 11
      src/CoreBundle/Entity/PortfolioCategory.php
  66. 275
      src/CoreBundle/Entity/PortfolioComment.php
  67. 18
      src/CoreBundle/Entity/Profile.php
  68. 6
      src/CoreBundle/Entity/Promotion.php
  69. 13
      src/CoreBundle/Entity/ResetPasswordRequest.php
  70. 22
      src/CoreBundle/Entity/ResourceComment.php
  71. 151
      src/CoreBundle/Entity/ResourceFile.php
  72. 108
      src/CoreBundle/Entity/ResourceLink.php
  73. 141
      src/CoreBundle/Entity/ResourceNode.php
  74. 3
      src/CoreBundle/Entity/ResourceRight.php
  75. 7
      src/CoreBundle/Entity/ResourceType.php
  76. 3
      src/CoreBundle/Entity/Sequence.php
  77. 3
      src/CoreBundle/Entity/SequenceCondition.php
  78. 3
      src/CoreBundle/Entity/SequenceFormula.php
  79. 3
      src/CoreBundle/Entity/SequenceMethod.php
  80. 3
      src/CoreBundle/Entity/SequenceResource.php
  81. 3
      src/CoreBundle/Entity/SequenceRowEntity.php
  82. 3
      src/CoreBundle/Entity/SequenceRule.php
  83. 3
      src/CoreBundle/Entity/SequenceRuleCondition.php
  84. 3
      src/CoreBundle/Entity/SequenceRuleMethod.php
  85. 3
      src/CoreBundle/Entity/SequenceTypeEntity.php
  86. 3
      src/CoreBundle/Entity/SequenceValue.php
  87. 3
      src/CoreBundle/Entity/SequenceVariable.php
  88. 278
      src/CoreBundle/Entity/Session.php
  89. 34
      src/CoreBundle/Entity/SessionCategory.php
  90. 30
      src/CoreBundle/Entity/SessionRelCourse.php
  91. 44
      src/CoreBundle/Entity/SessionRelCourseRelUser.php
  92. 46
      src/CoreBundle/Entity/SessionRelUser.php
  93. 83
      src/CoreBundle/Entity/Skill.php
  94. 99
      src/CoreBundle/Entity/SocialPost.php
  95. 1
      src/CoreBundle/Entity/SysAnnouncement.php
  96. 21
      src/CoreBundle/Entity/SystemTemplate.php
  97. 3
      src/CoreBundle/Entity/TicketMessageAttachment.php
  98. 3
      src/CoreBundle/Entity/Tool.php
  99. 6
      src/CoreBundle/Entity/ToolResourceRight.php
  100. 2
      src/CoreBundle/Entity/TrackCourseRanking.php
  101. Some files were not shown because too many files have changed in this diff Show More

@ -36,7 +36,7 @@ $repo = Container::getAnnouncementRepository();
$allowToEdit = (
api_is_allowed_to_edit(false, true) ||
(1 === (int) api_get_course_setting('allow_user_edit_announcement') && !api_is_anonymous()) ||
($sessionId && api_is_coach() && api_get_configuration_value('allow_coach_to_edit_announcements'))
($sessionId && api_is_coach() && ('true' === api_get_setting('announcement.allow_coach_to_edit_announcements')))
);
$allowStudentInGroupToSend = false;

@ -2196,7 +2196,7 @@ class Category implements GradebookItem
$params['bottom'] = 0;
$page_format = 'landscape' == $params['orientation'] ? 'A4-L' : 'A4';
$pdf = new PDF($page_format, $params['orientation'], $params);
if (api_get_configuration_value('add_certificate_pdf_footer')) {
if ('true' === api_get_setting('certificate.add_certificate_pdf_footer')) {
$pdf->setCertificateFooter();
}
$certificate_list = GradebookUtils::get_list_users_certificates($catId, $userList);

@ -367,7 +367,7 @@ class DocumentManager
$len = filesize($full_file_name);
// Fixing error when file name contains a ","
$filename = str_replace(',', '', $filename);
$sendFileHeaders = api_get_configuration_value('enable_x_sendfile_headers');
$sendFileHeaders = ('true' === api_get_setting('document.enable_x_sendfile_headers'));
// Allows chrome to make videos and audios seekable
header('Accept-Ranges: bytes');

@ -7740,7 +7740,7 @@ class Tracking
$columnHeaders['student_follow_page_add_LP_subscription_info'] = get_lang('Unlock');
}
if (true === api_get_configuration_value('student_follow_page_add_LP_acquisition_info')) {
if ('true' === api_get_setting('lp.student_follow_page_add_LP_acquisition_info')) {
$columnHeaders['student_follow_page_add_LP_acquisition_info'] = get_lang('Acquisition');
}

@ -2276,7 +2276,7 @@ if ($allowMessages) {
$form->display();
}
$allow = ('true' === api_get_setting('mail.allow_user_message_tracking'));
$allow = ('true' === api_get_setting('message.allow_user_message_tracking'));
if ($allow && (api_is_drh() || api_is_platform_admin())) {
$users = MessageManager::getUsersThatHadConversationWithUser($studentId);
echo Display::page_subheader2(get_lang('MessageReporting'));

@ -106,7 +106,7 @@ function get_users($from, $limit, $column, $direction)
}
}
$checkSessionVisibility = api_get_configuration_value('show_users_in_active_sessions_in_tracking');
$checkSessionVisibility = ('true' === api_get_setting('session.show_users_in_active_sessions_in_tracking'));
if (false === $drhLoaded) {
$students = UserManager::getUsersFollowedByUser(
api_get_user_id(),

@ -92,7 +92,7 @@ function get_users($from, $limit, $column, $direction)
$drhLoaded = true;
}
$checkSessionVisibility = api_get_configuration_value('show_users_in_active_sessions_in_tracking');
$checkSessionVisibility = ('true' === api_get_setting('session.show_users_in_active_sessions_in_tracking'));
if (false == $drhLoaded) {
$students = UserManager::getUsersFollowedByUser(
api_get_user_id(),

@ -105,7 +105,7 @@ function get_users($from, $limit, $column, $direction)
}
if (false === $drhLoaded) {
$checkSessionVisibility = api_get_configuration_value('show_users_in_active_sessions_in_tracking');
$checkSessionVisibility = ('true' === api_get_setting('session.show_users_in_active_sessions_in_tracking'));
$students = UserManager::getUsersFollowedByUser(
api_get_user_id(),
$status,

@ -3,7 +3,7 @@
require_once __DIR__.'/../inc/global.inc.php';
$allow = ('true' === api_get_setting('mail.allow_user_message_tracking'));
$allow = ('true' === api_get_setting('message.allow_user_message_tracking'));
if (!$allow) {
api_not_allowed(true);

@ -13,9 +13,8 @@ use DateTime;
use DateTimeZone;
use Display;
use Exception;
use Template;
use const PHP_SAPI;
use Template;
class ChamiloApi
{

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
declare(strict_types=1);
@ -19,8 +20,10 @@ class IndexBlocksController extends BaseController
private bool $isAdmin = false;
private bool $isSessionAdmin = false;
public function __construct(private TranslatorInterface $translator, private SettingsManager $settingsManager)
{
public function __construct(
private TranslatorInterface $translator,
private SettingsManager $settingsManager
) {
}
public function __invoke(): JsonResponse
@ -130,7 +133,7 @@ class IndexBlocksController extends BaseController
'label' => $this->translator->trans('Anonymise users list'),
];
if (isset($extAuthSource, $extAuthSource['extldap']) && count($extAuthSource['extldap']) > 0) {
if (isset($extAuthSource, $extAuthSource['extldap']) && \count($extAuthSource['extldap']) > 0) {
$items[] = [
'class' => 'item-user-ldap-list',
'url' => $this->generateUrl('legacy_main', ['name' => 'admin/ldap_users_list.php']),
@ -172,7 +175,7 @@ class IndexBlocksController extends BaseController
$items = array_filter($items, function (array $item) {
$urls = ['user_list.php', 'user_add.php'];
return in_array($item['url'], $urls);
return \in_array($item['url'], $urls, true);
});
}
@ -180,7 +183,7 @@ class IndexBlocksController extends BaseController
$items = array_filter($items, function (array $item) {
$urls = ['user_list.php'];
return !in_array($item['url'], $urls);
return !\in_array($item['url'], $urls, true);
});
}
@ -271,7 +274,7 @@ class IndexBlocksController extends BaseController
];
}
if (isset($extAuthSource, $extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
if (isset($extAuthSource, $extAuthSource['ldap']) && \count($extAuthSource['ldap']) > 0) {
$items[] = [
'class' => 'item-course-subscription-ldap',
'url' => $this->generateUrl('legacy_main', ['name' => 'admin/ldap_import_students.php']),
@ -422,7 +425,7 @@ class IndexBlocksController extends BaseController
];
}
$allowJustification = api_get_plugin_setting('justification', 'tool_enable') === 'true';
$allowJustification = 'true' === api_get_plugin_setting('justification', 'tool_enable');
if ($allowJustification) {
$items[] = [
@ -469,7 +472,7 @@ class IndexBlocksController extends BaseController
'url' => $this->generateUrl('legacy_main', ['name' => 'session/session_import_drh.php']),
'label' => $this->translator->trans('Import list of HR directors into sessions'),
];
if (isset($extAuthSource, $extAuthSource['ldap']) && count($extAuthSource['ldap']) > 0) {
if (isset($extAuthSource, $extAuthSource['ldap']) && \count($extAuthSource['ldap']) > 0) {
$items[] = [
'class' => 'item-session-subscription-ldap-import',
'url' => $this->generateUrl('legacy_main', ['name' => 'admin/ldap_import_students_to_session.php']),

@ -50,7 +50,8 @@ class SecurityController extends AbstractController
->setUsername($user->getUsername())
->setLoginDate(new DateTime())
->setUserIp(api_get_real_ip())
->setSuccess(true);
->setSuccess(true)
;
$this->trackELoginRecordRepository->create($trackELoginRecord);

@ -7,7 +7,6 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\DataProvider\Extension;
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
//use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface;
//use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
@ -20,9 +19,10 @@ use Symfony\Component\Security\Core\Security;
final class CCalendarEventExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security, private readonly RequestStack $requestStack)
{
public function __construct(
private readonly Security $security,
private readonly RequestStack $requestStack
) {
}
public function applyToCollection(
@ -49,6 +49,17 @@ final class CCalendarEventExtension implements QueryCollectionExtensionInterface
$this->addWhere($queryBuilder, $resourceClass);
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//$this->addWhere($queryBuilder, $resourceClass);
}
private function addWhere(QueryBuilder $qb, string $resourceClass): void
{
if (CCalendarEvent::class !== $resourceClass) {
@ -65,7 +76,8 @@ final class CCalendarEventExtension implements QueryCollectionExtensionInterface
$qb
->innerJoin("$alias.resourceNode", 'node')
->leftJoin('node.resourceLinks', 'links');
->leftJoin('node.resourceLinks', 'links')
;
$request = $this->requestStack->getCurrentRequest();
$courseId = $request->query->get('cid');
@ -84,24 +96,28 @@ final class CCalendarEventExtension implements QueryCollectionExtensionInterface
);
$qb
->setParameter('start', $startDate)
->setParameter('end', $endDate);
->setParameter('end', $endDate)
;
}
if (empty($courseId)) {
$qb
->andWhere('links.user = :user OR node.creator = :user')
->setParameter('user', $user);
->setParameter('user', $user)
;
} else {
$qb
->andWhere('links.course = :course')
->setParameter('course', $courseId);
->setParameter('course', $courseId)
;
if (empty($sessionId)) {
$qb->andWhere('links.session IS NULL');
} else {
$qb
->andWhere('links.session = :session')
->setParameter('session', $sessionId);
->setParameter('session', $sessionId)
;
}
if (empty($groupId)) {
@ -109,7 +125,8 @@ final class CCalendarEventExtension implements QueryCollectionExtensionInterface
} else {
$qb
->andWhere('links.group = :group')
->setParameter('group', $groupId);
->setParameter('group', $groupId)
;
}
}
@ -130,17 +147,6 @@ final class CCalendarEventExtension implements QueryCollectionExtensionInterface
);*/
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//$this->addWhere($queryBuilder, $resourceClass);
}
/*public function generateBetweenRange($qb, $alias, $field, $range)
{
$value = $range['between'];

@ -7,7 +7,6 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\DataProvider\Extension;
use ApiPlatform\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
//use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\QueryItemExtensionInterface;
use ApiPlatform\Doctrine\Orm\Util\QueryNameGeneratorInterface;
use ApiPlatform\Metadata\Operation;
@ -23,9 +22,10 @@ use Symfony\Component\Security\Core\Security;
*/
final class CDocumentExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security, private readonly RequestStack $requestStack)
{
public function __construct(
private readonly Security $security,
private readonly RequestStack $requestStack
) {
}
public function applyToCollection(
@ -78,12 +78,14 @@ final class CDocumentExtension implements QueryCollectionExtensionInterface //,
$queryBuilder
->innerJoin("$rootAlias.resourceNode", 'node')
->innerJoin('node.resourceLinks', 'links');
->innerJoin('node.resourceLinks', 'links')
;
// Do not show deleted resources.
$queryBuilder
->andWhere('links.visibility != :visibilityDeleted')
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED);
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED)
;
$allowDraft =
$this->security->isGranted('ROLE_ADMIN') ||
@ -92,19 +94,22 @@ final class CDocumentExtension implements QueryCollectionExtensionInterface //,
if (!$allowDraft) {
$queryBuilder
->andWhere('links.visibility != :visibilityDraft')
->setParameter('visibilityDraft', ResourceLink::VISIBILITY_DRAFT);
->setParameter('visibilityDraft', ResourceLink::VISIBILITY_DRAFT)
;
}
$queryBuilder
->andWhere('links.course = :course')
->setParameter('course', $courseId);
->setParameter('course', $courseId)
;
if (empty($sessionId)) {
$queryBuilder->andWhere('links.session IS NULL');
} else {
$queryBuilder
->andWhere('links.session = :session')
->setParameter('session', $sessionId);
->setParameter('session', $sessionId)
;
}
if (empty($groupId)) {
@ -112,7 +117,8 @@ final class CDocumentExtension implements QueryCollectionExtensionInterface //,
} else {
$queryBuilder
->andWhere('links.group = :group')
->setParameter('group', $groupId);
->setParameter('group', $groupId)
;
}
/*$queryBuilder->

@ -20,9 +20,10 @@ use Symfony\Component\Security\Core\Security;
final class CToolIntroExtension implements QueryCollectionExtensionInterface
{
public function __construct(private readonly Security $security, private readonly RequestStack $requestStack)
{
public function __construct(
private readonly Security $security,
private readonly RequestStack $requestStack
) {
}
public function applyToCollection(
@ -59,12 +60,14 @@ final class CToolIntroExtension implements QueryCollectionExtensionInterface
$queryBuilder
->innerJoin("$rootAlias.resourceNode", 'node')
->innerJoin('node.resourceLinks', 'links');
->innerJoin('node.resourceLinks', 'links')
;
// Do not show deleted resources.
$queryBuilder
->andWhere('links.visibility != :visibilityDeleted')
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED);
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED)
;
$allowDraft =
$this->security->isGranted('ROLE_ADMIN') ||
@ -73,19 +76,22 @@ final class CToolIntroExtension implements QueryCollectionExtensionInterface
if (!$allowDraft) {
$queryBuilder
->andWhere('links.visibility != :visibilityDraft')
->setParameter('visibilityDraft', ResourceLink::VISIBILITY_DRAFT);
->setParameter('visibilityDraft', ResourceLink::VISIBILITY_DRAFT)
;
}
$queryBuilder
->andWhere('links.course = :course')
->setParameter('course', $courseId);
->setParameter('course', $courseId)
;
if (empty($sessionId)) {
$queryBuilder->andWhere('links.session IS NULL');
} else {
$queryBuilder
->andWhere('links.session = :session')
->setParameter('session', $sessionId);
->setParameter('session', $sessionId)
;
}
if (empty($groupId)) {
@ -93,7 +99,8 @@ final class CToolIntroExtension implements QueryCollectionExtensionInterface
} else {
$queryBuilder
->andWhere('links.group = :group')
->setParameter('group', $groupId);
->setParameter('group', $groupId)
;
}
}
}

@ -21,9 +21,9 @@ use Symfony\Component\Security\Core\Security;
*/
final class CourseExtension implements QueryCollectionExtensionInterface
{
public function __construct(private readonly Security $security)
{
public function __construct(
private readonly Security $security
) {
}
public function applyToCollection(
@ -60,9 +60,11 @@ final class CourseExtension implements QueryCollectionExtensionInterface
$queryBuilder
->andWhere(sprintf('%s.visibility <> :visibility_hidden', $rootAlias))
->setParameter('visibility_hidden', Course::HIDDEN);
->setParameter('visibility_hidden', Course::HIDDEN)
;
$queryBuilder
->andWhere(sprintf('%s.visibility <> :visibility_closed', $rootAlias))
->setParameter('visibility_closed', Course::CLOSED);
->setParameter('visibility_closed', Course::CLOSED)
;
}
}

@ -18,9 +18,9 @@ use Symfony\Component\Security\Core\Security;
final class CourseRelUserExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security)
{
public function __construct(
private readonly Security $security
) {
}
public function applyToCollection(

@ -20,9 +20,9 @@ use Symfony\Component\Security\Core\Security;
final class MessageExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security)
{
public function __construct(
private readonly Security $security
) {
}
public function applyToCollection(
@ -49,6 +49,18 @@ final class MessageExtension implements QueryCollectionExtensionInterface //, Qu
$this->addWhere($queryBuilder, $resourceClass);
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//error_log('applyToItem1');
//$this->addWhere($queryBuilder, $resourceClass);
}
private function addWhere(QueryBuilder $qb, string $resourceClass): void
{
if (Message::class !== $resourceClass) {
@ -102,16 +114,4 @@ final class MessageExtension implements QueryCollectionExtensionInterface //, Qu
'conversation' => Message::MESSAGE_TYPE_CONVERSATION,
]);
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//error_log('applyToItem1');
//$this->addWhere($queryBuilder, $resourceClass);
}
}

@ -17,9 +17,9 @@ use Symfony\Component\Security\Core\Security;
final class MessageTagExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security)
{
public function __construct(
private readonly Security $security
) {
}
public function applyToCollection(

@ -19,9 +19,10 @@ use Symfony\Component\Security\Core\Security;
final class PageExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security, private readonly RequestStack $requestStack)
{
public function __construct(
private readonly Security $security,
private readonly RequestStack $requestStack
) {
}
public function applyToCollection(
@ -34,6 +35,17 @@ final class PageExtension implements QueryCollectionExtensionInterface //, Query
$this->addWhere($queryBuilder, $resourceClass);
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//$this->addWhere($queryBuilder, $resourceClass);
}
private function addWhere(QueryBuilder $qb, string $resourceClass): void
{
if (Page::class !== $resourceClass) {
@ -48,21 +60,11 @@ final class PageExtension implements QueryCollectionExtensionInterface //, Query
// Url filter by default.
$qb
->andWhere("$alias.url = :url")
->setParameter('url', $urlId);
->setParameter('url', $urlId)
;
if (!$this->security->isGranted('ROLE_ADMIN')) {
$qb->andWhere("$alias.enabled = 1");
}
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//$this->addWhere($queryBuilder, $resourceClass);
}
}

@ -22,9 +22,10 @@ use Symfony\Component\Security\Core\Security;
*/
final class PersonalFileExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security, private readonly RequestStack $requestStack)
{
public function __construct(
private readonly Security $security,
private readonly RequestStack $requestStack
) {
}
public function applyToCollection(
@ -63,7 +64,8 @@ final class PersonalFileExtension implements QueryCollectionExtensionInterface /
$rootAlias = $queryBuilder->getRootAliases()[0];
$queryBuilder
->innerJoin("$rootAlias.resourceNode", 'node');
->innerJoin("$rootAlias.resourceNode", 'node')
;
if ($isShared) {
$queryBuilder->leftJoin('node.resourceLinks', 'links');
@ -75,11 +77,13 @@ final class PersonalFileExtension implements QueryCollectionExtensionInterface /
$queryBuilder
->andWhere('links.visibility = :visibility')
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED);
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED)
;
$queryBuilder
->andWhere('links.user = :userLink')
->setParameter('userLink', $user);
->setParameter('userLink', $user)
;
} else {
$queryBuilder->orWhere('node.creator = :current');
$queryBuilder->setParameter('current', $user);

@ -21,9 +21,10 @@ use Symfony\Component\Security\Core\Security;
final class SessionRelUserExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct(private readonly Security $security, private readonly RequestStack $requestStack)
{
public function __construct(
private readonly Security $security,
private readonly RequestStack $requestStack
) {
}
public function applyToCollection(

@ -15,8 +15,9 @@ use Symfony\Component\Security\Core\Exception\AccessDeniedException;
class SocialPostExtension implements QueryCollectionExtensionInterface
{
public function __construct(private readonly SettingsManager $settingsManager)
{
public function __construct(
private readonly SettingsManager $settingsManager
) {
}
public function applyToCollection(

@ -17,8 +17,9 @@ use Symfony\Component\Security\Core\Security;
final class TrackEExerciseExtension implements QueryCollectionExtensionInterface
{
public function __construct(private readonly Security $security)
{
public function __construct(
private readonly Security $security
) {
}
public function applyToCollection(

@ -16,7 +16,6 @@ use Doctrine\ORM\QueryBuilder;
final class UserRelUserExtension implements QueryCollectionExtensionInterface //, QueryItemExtensionInterface
{
public function __construct()
{
}
@ -31,6 +30,18 @@ final class UserRelUserExtension implements QueryCollectionExtensionInterface //
$this->addWhere($queryBuilder, $resourceClass);
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//error_log('applyToItem');
//$this->addWhere($queryBuilder, $resourceClass);
}
private function addWhere(QueryBuilder $queryBuilder, string $resourceClass): void
{
if (Message::class !== $resourceClass) {
@ -61,16 +72,4 @@ final class UserRelUserExtension implements QueryCollectionExtensionInterface //
'conversation' => Message::MESSAGE_TYPE_CONVERSATION,
]);*/
}
public function applyToItem(
QueryBuilder $queryBuilder,
QueryNameGeneratorInterface $queryNameGenerator,
string $resourceClass,
array $identifiers,
string $operationName = null,
array $context = []
): void {
//error_log('applyToItem');
//$this->addWhere($queryBuilder, $resourceClass);
}
}

@ -167,7 +167,8 @@ abstract class AbstractResource
->setVisibility($visibility)
->setCourse($course)
->setSession($session)
->setGroup($group);
->setGroup($group)
;
$rights = [];
switch ($visibility) {
@ -176,7 +177,8 @@ abstract class AbstractResource
$editorMask = ResourceNodeVoter::getEditorMask();
$resourceRight = (new ResourceRight())
->setMask($editorMask)
->setRole(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER);
->setRole(ResourceNodeVoter::ROLE_CURRENT_COURSE_TEACHER)
;
$rights[] = $resourceRight;
break;
@ -268,7 +270,8 @@ abstract class AbstractResource
->setUser($user)
->setCourse($course)
->setSession($session)
->setGroup($group);
->setGroup($group)
;
if ($this->hasResourceNode()) {
$resourceNode = $this->getResourceNode();
@ -312,7 +315,8 @@ abstract class AbstractResource
->setCourse($course)
->setSession($session)
->setGroup($group)
->setVisibility(ResourceLink::VISIBILITY_PUBLISHED);
->setVisibility(ResourceLink::VISIBILITY_PUBLISHED)
;
if ($this->hasResourceNode()) {
$resourceNode = $this->getResourceNode();

@ -1,6 +1,6 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
@ -18,8 +18,6 @@ use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
*/
#[ApiResource(
normalizationContext: [
'groups' => ['access_url:read'],
@ -73,12 +71,12 @@ class AccessUrl extends AbstractResource implements ResourceInterface, Stringabl
protected Collection $courseCategory;
#[ORM\JoinColumn(onDelete: 'CASCADE')]
#[Gedmo\TreeParent]
#[ORM\ManyToOne(targetEntity: AccessUrl::class, inversedBy: 'children')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
protected ?AccessUrl $parent = null;
/**
* @var AccessUrl[]|Collection<int, AccessUrl>
*/
#[ORM\OneToMany(targetEntity: AccessUrl::class, mappedBy: 'parent')]
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
#[ORM\OrderBy(['id' => 'ASC'])]
protected Collection $children;
#[Gedmo\TreeLeft]
@ -91,7 +89,7 @@ class AccessUrl extends AbstractResource implements ResourceInterface, Stringabl
#[ORM\Column(name: 'rgt', type: 'integer')]
protected int $rgt;
#[Gedmo\TreeRoot]
#[ORM\ManyToOne(targetEntity: AccessUrl::class)]
#[ORM\ManyToOne(targetEntity: self::class)]
#[ORM\JoinColumn(name: 'tree_root', onDelete: 'CASCADE')]
protected ?AccessUrl $root = null;
#[Assert\NotBlank]

@ -37,9 +37,6 @@ class AccessUrlRelCourse implements EntityAccessUrlInterface, Stringable
return '-';
}
/**
* Get id.
*/
public function getId(): ?int
{
return $this->id;

@ -0,0 +1,139 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Chamilo\CoreBundle\Entity\User;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="agenda_event_invitation")
* @ORM\Entity()
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({
* "invitation" = "Chamilo\CoreBundle\Entity\AgendaEventInvitation",
* "subscription" = "Chamilo\CoreBundle\Entity\AgendaEventSubscription"
* })
*/
class AgendaEventInvitation
{
use TimestampableTypedEntity;
/**
* @ORM\Id()
* @ORM\Column(type="bigint")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\OneToMany(targetEntity="AgendaEventInvitee", mappedBy="invitation", cascade={"persist", "remove"},
* orphanRemoval=true)
*/
protected $invitees;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User", inversedBy="resourceNodes")
* @ORM\JoinColumn(name="creator_id", referencedColumnName="id", nullable=true, onDelete="CASCADE")
*/
protected $creator;
public function __construct()
{
$this->invitees = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function getInvitees(): Collection
{
return $this->invitees;
}
public function setInvitees(Collection $invitees): AgendaEventInvitation
{
$this->invitees = $invitees;
return $this;
}
public function addInvitee(AgendaEventInvitee $invitee): AgendaEventInvitation
{
$invitee->setInvitation($this);
$this->invitees->add($invitee);
return $this;
}
public function removeInviteeUser(User $user): AgendaEventInvitation
{
/** @var AgendaEventInvitee $invitee */
$invitee = $this
->invitees
->filter(function (AgendaEventInvitee $invitee) use ($user) {
return $invitee->getUser() === $user;
})
->first();
if ($invitee) {
$this->invitees->removeElement($invitee);
$invitee->setInvitation(null);
}
return $this;
}
public function removeInvitees(): self
{
$this->invitees = new ArrayCollection();
return $this;
}
public function getCreator(): User
{
return $this->creator;
}
public function setCreator(User $creator): self
{
$this->creator = $creator;
return $this;
}
public function hasUserAsInvitee(User $user): bool
{
return $this->invitees->exists(
function (int $key, AgendaEventInvitee $invitee) use ($user) {
return $invitee->getUser() === $user;
}
);
}
public function removeInviteesNotInIdList(array $idList): self
{
$toRemove = [];
/** @var AgendaEventInvitee $invitee */
foreach ($this->invitees as $key => $invitee) {
if (!in_array($invitee->getUser()->getId(), $idList)) {
$toRemove[] = $key;
}
}
foreach ($toRemove as $key) {
$this->invitees->remove($key);
}
return $this;
}
}

@ -0,0 +1,72 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Chamilo\CoreBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="agenda_event_invitee")
* @ORM\Entity()
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({
* "invitee" = "Chamilo\CoreBundle\Entity\AgendaEventInvitee",
* "subscriber" = "Chamilo\CoreBundle\Entity\AgendaEventSubscriber"
* })
*/
class AgendaEventInvitee
{
use TimestampableTypedEntity;
/**
* @ORM\Id()
* @ORM\Column(type="bigint")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\ManyToOne(targetEntity="AgendaEventInvitation", inversedBy="invitees")
* @ORM\JoinColumn(name="invitation_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $invitation;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=true, onDelete="SET NULL")
*/
protected $user;
public function getId(): int
{
return $this->id;
}
public function getInvitation(): ?AgendaEventInvitation
{
return $this->invitation;
}
public function setInvitation(?AgendaEventInvitation $invitation): AgendaEventInvitee
{
$this->invitation = $invitation;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): AgendaEventInvitee
{
$this->user = $user;
return $this;
}
}

@ -0,0 +1,14 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class AgendaEventSubscriber extends AgendaEventInvitee
{
}

@ -0,0 +1,34 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity()
*/
class AgendaEventSubscription extends AgendaEventInvitation
{
public const SUBSCRIPTION_NO = 0;
public const SUBSCRIPTION_ALL = 1;
public const SUBSCRIPTION_CLASS = 2;
/**
* @ORM\Column(name="max_attendees", type="integer", nullable=false, options={"default": 0})
*/
protected $maxAttendees = 0;
public function getMaxAttendees(): int
{
return $this->maxAttendees;
}
public function setMaxAttendees(int $maxAttendees): self
{
$this->maxAttendees = $maxAttendees;
return $this;
}
}

@ -0,0 +1,103 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="agenda_reminder")
*
* @ORM\Entity()
*/
class AgendaReminder
{
use TimestampableTypedEntity;
/**
* @ORM\Id()
* @ORM\Column(type="bigint")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="type", type="string")
*/
protected $type;
/**
* @ORM\Column(name="event_id", type="integer")
*/
protected $eventId;
/**
* @ORM\Column(name="date_interval", type="dateinterval")
*/
protected $dateInterval;
/**
* @ORM\Column(name="sent", type="boolean")
*/
protected $sent;
public function __construct()
{
$this->sent = false;
}
public function getId(): int
{
return $this->id;
}
public function getType(): string
{
return $this->type;
}
public function setType(string $type): AgendaReminder
{
$this->type = $type;
return $this;
}
public function getEventId(): int
{
return $this->eventId;
}
public function setEventId(int $eventId): AgendaReminder
{
$this->eventId = $eventId;
return $this;
}
public function getDateInterval(): \DateInterval
{
return $this->dateInterval;
}
public function setDateInterval(\DateInterval $dateInterval): AgendaReminder
{
$this->dateInterval = $dateInterval;
return $this;
}
public function isSent(): bool
{
return $this->sent;
}
public function setSent(bool $sent): AgendaReminder
{
$this->sent = $sent;
return $this;
}
}

@ -11,6 +11,7 @@ use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Stringable;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Annotation\Groups;
@ -23,7 +24,7 @@ use Vich\UploaderBundle\Mapping\Annotation as Vich;
*/
#[ORM\Table(name: 'asset')]
#[ORM\Entity]
class Asset implements \Stringable
class Asset implements Stringable
{
use TimestampableEntity;
@ -45,7 +46,7 @@ class Asset implements \Stringable
protected ?string $title = null;
#[Assert\NotBlank]
#[Assert\Choice([Asset::SCORM, Asset::WATERMARK, Asset::EXTRA_FIELD, Asset::COURSE_CATEGORY, Asset::SKILL], message: 'Choose a valid category.')]
#[Assert\Choice([self::SCORM, self::WATERMARK, self::EXTRA_FIELD, self::COURSE_CATEGORY, self::SKILL], message: 'Choose a valid category.')]
#[ORM\Column(type: 'string', length: 255)]
protected ?string $category = null;
@ -261,9 +262,6 @@ class Asset implements \Stringable
return $this->file;
}
/**
* @param File|UploadedFile $file
*/
public function setFile(File|UploadedFile $file = null): self
{
$this->file = $file;

@ -98,15 +98,14 @@ class BranchSync
protected ?int $root = null;
#[Gedmo\TreeParent]
#[ORM\ManyToOne(targetEntity: BranchSync::class, inversedBy: 'children')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'SET NULL')]
protected ?BranchSync $parent = null;
/**
*
* @var BranchSync[]|Collection
*/
#[ORM\OneToMany(targetEntity: BranchSync::class, mappedBy: 'parent')]
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
#[ORM\OrderBy(['lft' => 'ASC'])]
protected Collection $children;
@ -578,7 +577,7 @@ class BranchSync
/**
* @return BranchSync[]|Collection
*/
public function getChildren(): array|\Doctrine\Common\Collections\Collection
public function getChildren(): array|Collection
{
return $this->children;
}

@ -1,6 +1,6 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
@ -32,8 +32,6 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use function in_array;
#[ApiResource(
types: ['https://schema.org/Course'],
operations: [
@ -66,11 +64,13 @@ use function in_array;
operations: [new Get()],
uriVariables: [
'id' => new Link(
fromClass: TrackCourseRanking::class, identifiers: ['id']
fromClass: TrackCourseRanking::class,
identifiers: ['id']
),
], status: 200,
],
status: 200,
normalizationContext: [
'groups' => ['course:read']
'groups' => ['course:read'],
],
filters: [
'course.sticky_boolean_filter',
@ -79,8 +79,7 @@ use function in_array;
'annotated_chamilo_core_bundle_entity_course_api_platform_core_bridge_doctrine_orm_filter_order_filter',
]
)]
class Course extends AbstractResource implements ResourceInterface, ResourceWithAccessUrlInterface,
ResourceIllustrationInterface, ExtraFieldItemInterface, Stringable
class Course extends AbstractResource implements ResourceInterface, ResourceWithAccessUrlInterface, ResourceIllustrationInterface, ExtraFieldItemInterface, Stringable
{
public const CLOSED = 0;
public const REGISTERED = 1;
@ -119,7 +118,6 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
protected ?string $title = null;
/**
* The course code.
*
*/
#[ApiProperty(iris: ['http://schema.org/courseCode'])]
#[Groups(['course:read', 'user:write', 'course_rel_user:read'])]
@ -233,11 +231,11 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
#[ORM\OneToMany(targetEntity: Templates::class, mappedBy: 'course', cascade: ['persist', 'remove'])]
protected Collection $templates;
/**
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course")
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SpecificFieldValues", mappedBy="course").
*/
//protected $specificFieldValues;
/**
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course")
* ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\SharedSurvey", mappedBy="course").
*/
//protected $sharedSurveys;
#[ORM\Column(name: 'directory', type: 'string', length: 40, nullable: true, unique: false)]
@ -359,6 +357,11 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
//$this->sharedSurveys = new ArrayCollection();
}
public function __toString(): string
{
return $this->getTitle();
}
public static function getStatusList(): array
{
return [
@ -370,11 +373,6 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
];
}
public function __toString(): string
{
return $this->getTitle();
}
public function getTitle(): string
{
return $this->title;
@ -964,7 +962,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
{
$activeVisibilityList = [self::REGISTERED, self::OPEN_PLATFORM, self::OPEN_WORLD];
return in_array($this->visibility, $activeVisibilityList, true);
return \in_array($this->visibility, $activeVisibilityList, true);
}
/**
@ -999,6 +997,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
foreach ($list as $item) {
if ($item->getSession()->getId() === $session->getId()) {
$this->currentSession = $session;
break;
}
}
@ -1029,6 +1028,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
foreach ($urlList as $item) {
if ($item->getUrl()->getId() === $url->getId()) {
$this->currentUrl = $url;
break;
}
}

@ -1,6 +1,6 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
@ -22,8 +22,6 @@ use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
*/
#[ApiResource(
normalizationContext: [
'groups' => ['course_category:read', 'course:read'],
@ -99,7 +97,7 @@ class CourseCategory implements Stringable
/**
* @var Collection|CourseCategory[]
*/
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: CourseCategory::class)]
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
protected Collection $children;
#[Assert\NotBlank]
#[Groups(['course_category:read', 'course_category:write', 'course:read', 'session:read'])]
@ -109,7 +107,7 @@ class CourseCategory implements Stringable
#[Groups(['course_category:read', 'course_category:write', 'course:read'])]
#[ORM\Column(name: 'code', type: 'string', length: 40, nullable: false)]
protected string $code;
#[ORM\ManyToOne(targetEntity: CourseCategory::class, inversedBy: 'children')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ?CourseCategory $parent = null;
#[ORM\Column(name: 'tree_pos', type: 'integer', nullable: true)]

@ -1,6 +1,6 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */

@ -8,12 +8,13 @@ namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\UserTrait;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
#[ORM\Table(name: 'course_rel_user_catalogue')]
#[ORM\Index(name: 'course_rel_user_catalogue_user_id', columns: ['user_id'])]
#[ORM\Index(name: 'course_rel_user_catalogue_c_id', columns: ['c_id'])]
#[ORM\Entity]
class CourseRelUserCatalogue implements \Stringable
class CourseRelUserCatalogue implements Stringable
{
use UserTrait;

@ -1,19 +1,18 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -21,6 +20,7 @@ use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(operations: [new Get(security: 'is_granted(\'ROLE_ADMIN\')'), new Put(security: 'is_granted(\'ROLE_ADMIN\')'), new GetCollection(security: 'is_granted(\'ROLE_ADMIN\')'), new Post(security: 'is_granted(\'ROLE_ADMIN\')')], security: 'is_granted(\'ROLE_ADMIN\')', denormalizationContext: ['groups' => ['extra_field:write']], normalizationContext: ['groups' => ['extra_field:read']])]
#[ORM\Table(name: 'extra_field')]
#[ORM\Entity]
@ -120,22 +120,24 @@ class ExtraField
{
return $this->id;
}
public function getItemType() : int
public function getItemType(): int
{
return $this->itemType;
}
public function setItemType(int $itemType) : self
public function setItemType(int $itemType): self
{
$this->itemType = $itemType;
return $this;
}
public function getValueType() : int
public function getValueType(): int
{
return $this->valueType;
}
public function setValueType(int $valueType) : self
public function setValueType(int $valueType): self
{
$this->valueType = $valueType;
return $this;
}
/**
@ -145,9 +147,10 @@ class ExtraField
{
return $this->variable;
}
public function setVariable(string $variable) : self
public function setVariable(string $variable): self
{
$this->variable = $variable;
return $this;
}
/**
@ -157,9 +160,10 @@ class ExtraField
{
return $this->displayText;
}
public function setDisplayText(string $displayText) : self
public function setDisplayText(string $displayText): self
{
$this->displayText = $displayText;
return $this;
}
/**
@ -169,9 +173,10 @@ class ExtraField
{
return $this->defaultValue;
}
public function setDefaultValue(string $defaultValue) : self
public function setDefaultValue(string $defaultValue): self
{
$this->defaultValue = $defaultValue;
return $this;
}
/**
@ -181,9 +186,10 @@ class ExtraField
{
return $this->fieldOrder;
}
public function setFieldOrder(int $fieldOrder) : self
public function setFieldOrder(int $fieldOrder): self
{
$this->fieldOrder = $fieldOrder;
return $this;
}
/**
@ -193,97 +199,107 @@ class ExtraField
{
return $this->changeable;
}
public function setChangeable(bool $changeable) : self
public function setChangeable(bool $changeable): self
{
$this->changeable = $changeable;
return $this;
}
public function isFilter() : bool
public function isFilter(): bool
{
return $this->filter;
}
public function setFilter(bool $filter) : self
public function setFilter(bool $filter): self
{
$this->filter = $filter;
return $this;
}
public function isVisibleToSelf() : bool
public function isVisibleToSelf(): bool
{
return $this->visibleToSelf;
}
public function setVisibleToSelf(bool $visibleToSelf) : self
public function setVisibleToSelf(bool $visibleToSelf): self
{
$this->visibleToSelf = $visibleToSelf;
return $this;
}
public function isVisibleToOthers() : bool
public function isVisibleToOthers(): bool
{
return $this->visibleToOthers;
}
public function setVisibleToOthers(bool $visibleToOthers) : self
public function setVisibleToOthers(bool $visibleToOthers): self
{
$this->visibleToOthers = $visibleToOthers;
return $this;
}
public function getDescription() : ?string
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description) : self
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
/**
* @return Collection<int, ExtraFieldOptions>
*/
public function getOptions() : Collection
public function getOptions(): Collection
{
return $this->options;
}
public function setOptions(Collection $options) : self
public function setOptions(Collection $options): self
{
$this->options = $options;
return $this;
}
/**
* @return Tag[]|Collection
*/
public function getTags() : array|\Doctrine\Common\Collections\Collection
public function getTags(): array|Collection
{
return $this->tags;
}
public function setTags(Collection $tags) : self
public function setTags(Collection $tags): self
{
$this->tags = $tags;
return $this;
}
public function hasTag(string $tagName) : bool
public function hasTag(string $tagName): bool
{
if (0 === $this->tags->count()) {
return false;
}
return $this->tags->exists(fn($key, Tag $tag) => $tagName === $tag->getTag());
return $this->tags->exists(fn ($key, Tag $tag) => $tagName === $tag->getTag());
}
public function getTypeToString() : string
public function getTypeToString(): string
{
return match ($this->getItemType()) {
\ExtraField::FIELD_TYPE_RADIO, \ExtraField::FIELD_TYPE_SELECT => 'choice',
default => 'text',
};
}
public function getHelperText() : string
public function getHelperText(): string
{
return $this->helperText;
}
public function setHelperText(string $helperText) : self
public function setHelperText(string $helperText): self
{
$this->helperText = $helperText;
return $this;
}
public function setTranslatableLocale($locale)
{
$this->locale = $locale;
return $this;
}
public function getTranslatableLocale()

@ -1,24 +1,24 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Repository\ExtraFieldValuesRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(operations: [new Get(security: 'is_granted(\'ROLE_ADMIN\')'), new Put(security: 'is_granted(\'ROLE_ADMIN\')'), new GetCollection(security: 'is_granted(\'ROLE_ADMIN\')'), new Post(security: 'is_granted(\'ROLE_ADMIN\')')], security: 'is_granted(\'ROLE_ADMIN\')', denormalizationContext: ['groups' => ['extra_field_values:write']], normalizationContext: ['groups' => ['extra_field_values:read']])]
#[ORM\Table(name: 'extra_field_values')]
#[ORM\Index(name: 'idx_efv_fiii', columns: ['field_id', 'item_id'])]
@ -59,30 +59,33 @@ class ExtraFieldValues
{
$this->comment = '';
}
public function getField() : ExtraField
public function getField(): ExtraField
{
return $this->field;
}
public function setField(ExtraField $field) : self
public function setField(ExtraField $field): self
{
$this->field = $field;
return $this;
}
public function getItemId() : int
public function getItemId(): int
{
return $this->itemId;
}
public function setItemId(int $itemId) : self
public function setItemId(int $itemId): self
{
$this->itemId = $itemId;
return $this;
}
public function setComment(string $comment) : self
public function setComment(string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getComment() : ?string
public function getComment(): ?string
{
return $this->comment;
}
@ -95,22 +98,24 @@ class ExtraFieldValues
{
return $this->id;
}
public function getFieldValue() : ?string
public function getFieldValue(): ?string
{
return $this->fieldValue;
}
public function setFieldValue(?string $fieldValue) : self
public function setFieldValue(?string $fieldValue): self
{
$this->fieldValue = $fieldValue;
return $this;
}
public function getAsset() : ?Asset
public function getAsset(): ?Asset
{
return $this->asset;
}
public function setAsset(?Asset $asset) : self
public function setAsset(?Asset $asset): self
{
$this->asset = $asset;
return $this;
}
}

@ -40,14 +40,14 @@ class GradebookCategory
#[ORM\JoinColumn(name: 'c_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected Course $course;
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\GradebookCategory::class, inversedBy: 'subCategories')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'subCategories')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ?GradebookCategory $parent = null;
/**
* @var GradebookCategory[]|Collection
*/
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\GradebookCategory::class, mappedBy: 'parent')]
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
protected Collection $subCategories;
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\Session::class)]
@ -119,6 +119,9 @@ class GradebookCategory
#[ORM\Column(name: 'gradebooks_to_validate_in_dependence', type: 'integer', nullable: true)]
protected ?int $gradeBooksToValidateInDependence = null;
#[ORM\Column(name: 'allow_skills_by_subcategory', type: 'integer', nullable: true, options: ['default' => 1])]
protected $allowSkillsBySubcategory;
public function __construct()
{
$this->comments = new ArrayCollection();
@ -359,7 +362,7 @@ class GradebookCategory
/**
* @return GradebookComment[]|Collection
*/
public function getComments(): array|\Doctrine\Common\Collections\Collection
public function getComments(): array|Collection
{
return $this->comments;
}
@ -367,7 +370,7 @@ class GradebookCategory
/**
* @param GradebookComment[]|Collection $comments
*/
public function setComments(array|\Doctrine\Common\Collections\Collection $comments): self
public function setComments(array|Collection $comments): self
{
$this->comments = $comments;
@ -401,7 +404,7 @@ class GradebookCategory
/**
* @return GradebookEvaluation[]|Collection
*/
public function getEvaluations(): array|\Doctrine\Common\Collections\Collection
public function getEvaluations(): array|Collection
{
return $this->evaluations;
}
@ -409,7 +412,7 @@ class GradebookCategory
/**
* @param GradebookEvaluation[]|Collection $evaluations
*/
public function setEvaluations(array|\Doctrine\Common\Collections\Collection $evaluations): self
public function setEvaluations(array|Collection $evaluations): self
{
$this->evaluations = $evaluations;
@ -419,7 +422,7 @@ class GradebookCategory
/**
* @return GradebookLink[]|Collection
*/
public function getLinks(): array|\Doctrine\Common\Collections\Collection
public function getLinks(): array|Collection
{
return $this->links;
}
@ -427,7 +430,7 @@ class GradebookCategory
/**
* @param GradebookLink[]|Collection $links
*/
public function setLinks(array|\Doctrine\Common\Collections\Collection $links): self
public function setLinks(array|Collection $links): self
{
$this->links = $links;
@ -437,7 +440,7 @@ class GradebookCategory
/**
* @return GradebookCategory[]|Collection
*/
public function getSubCategories(): array|\Doctrine\Common\Collections\Collection
public function getSubCategories(): array|Collection
{
return $this->subCategories;
}
@ -481,7 +484,7 @@ class GradebookCategory
/**
* @return SkillRelGradebook[]|Collection
*/
public function getSkills(): array|\Doctrine\Common\Collections\Collection
public function getSkills(): array|Collection
{
return $this->skills;
}
@ -489,10 +492,30 @@ class GradebookCategory
/**
* @param SkillRelGradebook[]|Collection $skills
*/
public function setSkills(array|\Doctrine\Common\Collections\Collection $skills): self
public function setSkills(array|Collection $skills): self
{
$this->skills = $skills;
return $this;
}
/**
* @return int
*/
public function getAllowSkillsBySubcategory()
{
return $this->allowSkillsBySubcategory;
}
/**
* @param int $allowSkillsBySubcategory
*
* @return GradebookCategory
*/
public function setAllowSkillsBySubcategory($allowSkillsBySubcategory)
{
$this->allowSkillsBySubcategory = $allowSkillsBySubcategory;
return $this;
}
}

@ -9,6 +9,7 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -16,7 +17,7 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
#[ORM\Table(name: 'fos_group')]
#[ORM\Entity]
class Group implements \Stringable
class Group implements Stringable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
@ -33,11 +34,14 @@ class Group implements \Stringable
#[ORM\ManyToMany(targetEntity: \Chamilo\CoreBundle\Entity\User::class, mappedBy: 'groups')]
protected Collection $users;
public function __construct(#[Assert\NotBlank]
#[ORM\Column(name: 'name', type: 'string', length: 255, nullable: false, unique: true)]
protected string $name, #[ORM\Column(name: 'roles', type: 'array')]
protected array $roles = [])
{
public function __construct(
#[Assert\NotBlank]
#[ORM\Column(name: 'name', type: 'string', length: 255, unique: true, nullable: false)]
protected string $name,
#[ORM\Column(name: 'roles', type: 'array')]
protected array $roles = [
]
) {
$this->users = new ArrayCollection();
}
@ -107,7 +111,7 @@ class Group implements \Stringable
/**
* @return User[]|Collection
*/
public function getUsers(): array|\Doctrine\Common\Collections\Collection
public function getUsers(): array|Collection
{
return $this->users;
}

@ -1,29 +1,23 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiFilter;
use Chamilo\CoreBundle\Traits\PersonalResourceTrait;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Stringable;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(normalizationContext: ['groups' => ['illustration:read']])]
#[ORM\Table(name: 'illustration')]
#[ORM\Entity(repositoryClass: \Chamilo\CoreBundle\Repository\Node\IllustrationRepository::class)]
class Illustration extends AbstractResource implements ResourceInterface, \Stringable
class Illustration extends AbstractResource implements ResourceInterface, Stringable
{
use PersonalResourceTrait;
use TimestampableEntity;
@ -38,32 +32,33 @@ class Illustration extends AbstractResource implements ResourceInterface, \Strin
$this->id = Uuid::v4();
$this->name = 'illustration';
}
public function __toString() : string
public function __toString(): string
{
return $this->getName();
}
public function getId() : Uuid
public function getId(): Uuid
{
return $this->id;
}
public function getName() : string
public function getName(): string
{
return $this->name;
}
public function setName(string $name) : self
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getResourceIdentifier() : Uuid
public function getResourceIdentifier(): Uuid
{
return $this->getId();
}
public function getResourceName() : string
public function getResourceName(): string
{
return $this->getName();
}
public function setResourceName(string $name) : self
public function setResourceName(string $name): self
{
return $this->setName($name);
}

@ -39,11 +39,11 @@ class Language
#[ORM\Column(name: 'available', type: 'boolean', nullable: false)]
protected bool $available;
#[ORM\ManyToOne(targetEntity: Language::class, inversedBy: 'subLanguages')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'subLanguages')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', nullable: true)]
protected ?Language $parent = null;
#[ORM\OneToMany(targetEntity: Language::class, mappedBy: 'parent')]
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
protected Collection $subLanguages;
public function __construct()

@ -8,13 +8,14 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Stringable;
/**
* Skill level.
*/
#[ORM\Table(name: 'skill_level')]
#[ORM\Entity]
class Level implements \Stringable
class Level implements Stringable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]

@ -22,8 +22,10 @@ use Exception;
*/
class CourseListener
{
public function __construct(protected ToolChain $toolChain, protected SettingsManager $settingsManager)
{
public function __construct(
protected ToolChain $toolChain,
protected SettingsManager $settingsManager
) {
}
/**

@ -12,8 +12,9 @@ use Symfony\Component\Messenger\MessageBusInterface;
class MessageListener
{
public function __construct(private MessageBusInterface $bus)
{
public function __construct(
private MessageBusInterface $bus
) {
}
public function postPersist(Message $message, LifecycleEventArgs $args): void

@ -36,8 +36,12 @@ class ResourceListener
{
use AccessUrlListenerTrait;
public function __construct(protected SlugifyInterface $slugify, protected ToolChain $toolChain, protected RequestStack $request, protected Security $security)
{
public function __construct(
protected SlugifyInterface $slugify,
protected ToolChain $toolChain,
protected RequestStack $request,
protected Security $security
) {
}
/**

@ -19,8 +19,13 @@ class ResourceNodeListener
{
//protected $accessUrl;
public function __construct(protected SlugifyInterface $slugify, protected ToolChain $toolChain, protected RequestStack $request, protected Security $security, protected ResourceNodeRepository $resourceNodeRepository)
{
public function __construct(
protected SlugifyInterface $slugify,
protected ToolChain $toolChain,
protected RequestStack $request,
protected Security $security,
protected ResourceNodeRepository $resourceNodeRepository
) {
}
/*public function prePersist(ResourceNode $resourceNode, LifecycleEventArgs $event)

@ -23,8 +23,10 @@ class SessionListener
{
use AccessUrlListenerTrait;
public function __construct(protected RequestStack $request, protected Security $security)
{
public function __construct(
protected RequestStack $request,
protected Security $security
) {
}
/**

@ -18,8 +18,12 @@ use Symfony\Contracts\Translation\TranslatorInterface;
class SkillRelUserListener
{
public function __construct(private SettingsManager $settingsManager, private RouterInterface $router, private TranslatorInterface $translator, protected Security $security)
{
public function __construct(
private SettingsManager $settingsManager,
private RouterInterface $router,
private TranslatorInterface $translator,
protected Security $security
) {
}
public function postPersist(SkillRelUser $skillRelUser, LifecycleEventArgs $event): void

@ -15,8 +15,10 @@ use Symfony\Component\Security\Core\Security;
class UserListener
{
public function __construct(private UserRepository $userRepository, private Security $security)
{
public function __construct(
private UserRepository $userRepository,
private Security $security
) {
}
/**

@ -14,8 +14,9 @@ use Symfony\Component\Security\Core\Security;
class UserRelUserListener
{
public function __construct(private Security $security)
{
public function __construct(
private Security $security
) {
}
public function prePersist(UserRelUser $userRelUser, LifecycleEventArgs $args): void

@ -1,21 +1,23 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Entity\Listener\MessageListener;
use Chamilo\CoreBundle\Repository\MessageRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -24,13 +26,14 @@ use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(operations: [new Get(security: 'is_granted(\'VIEW\', object)'), new Put(security: 'is_granted(\'EDIT\', object)'), new Delete(security: 'is_granted(\'DELETE\', object)'), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(securityPostDenormalize: 'is_granted(\'CREATE\', object)')], security: 'is_granted(\'ROLE_USER\')', denormalizationContext: ['groups' => ['message:write']], normalizationContext: ['groups' => ['message:read']])]
#[ApiResource(operations: [new Get(security: 'is_granted(\'VIEW\', object)'), new Put(security: 'is_granted(\'EDIT\', object)'), new Delete(security: 'is_granted(\'DELETE\', object)'), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(securityPostDenormalize: 'is_granted(\'CREATE\', object)')], normalizationContext: ['groups' => ['message:read']], denormalizationContext: ['groups' => ['message:write']], security: 'is_granted(\'ROLE_USER\')')]
#[ORM\Table(name: 'message')]
#[ORM\Index(name: 'idx_message_user_sender', columns: ['user_sender_id'])]
#[ORM\Index(name: 'idx_message_group', columns: ['group_id'])]
#[ORM\Index(name: 'idx_message_type', columns: ['msg_type'])]
#[ORM\Entity(repositoryClass: \Chamilo\CoreBundle\Repository\MessageRepository::class)]
#[ORM\EntityListeners([\Chamilo\CoreBundle\Entity\Listener\MessageListener::class])]
#[ORM\Index(columns: ['user_sender_id'], name: 'idx_message_user_sender')]
#[ORM\Index(columns: ['group_id'], name: 'idx_message_group')]
#[ORM\Index(columns: ['msg_type'], name: 'idx_message_type')]
#[ORM\Entity(repositoryClass: MessageRepository::class)]
#[ORM\EntityListeners([MessageListener::class])]
#[ApiFilter(filterClass: OrderFilter::class, properties: ['title', 'sendDate'])]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['msgType' => 'exact', 'status' => 'exact', 'sender' => 'exact', 'receivers.receiver' => 'exact', 'receivers.tags.tag' => 'exact', 'parent' => 'exact'])]
class Message
@ -53,7 +56,7 @@ class Message
protected ?int $id = null;
#[Assert\NotBlank]
#[Groups(['message:read', 'message:write'])]
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\User::class, inversedBy: 'sentMessages')]
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'sentMessages')]
#[ORM\JoinColumn(name: 'user_sender_id', referencedColumnName: 'id', nullable: false)]
protected User $sender;
/**
@ -61,7 +64,7 @@ class Message
*/
#[Assert\Valid]
#[Groups(['message:read', 'message:write'])]
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\MessageRelUser::class, mappedBy: 'message', cascade: ['persist', 'remove'])]
#[ORM\OneToMany(mappedBy: 'message', targetEntity: MessageRelUser::class, cascade: ['persist', 'remove'])]
protected array|null|Collection $receivers;
/**
* @var Collection|MessageRelUser[]
@ -94,16 +97,16 @@ class Message
protected string $content;
#[Groups(['message:read', 'message:write'])]
protected ?MessageRelUser $firstReceiver = null;
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\Usergroup::class)]
#[ORM\ManyToOne(targetEntity: Usergroup::class)]
#[ORM\JoinColumn(name: 'group_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ?Usergroup $group = null;
/**
* @var Collection|Message[]
* @var Collection<int, Message>
*/
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\Message::class, mappedBy: 'parent')]
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
protected Collection $children;
#[Groups(['message:write'])]
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\Message::class, inversedBy: 'children')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id')]
protected ?Message $parent = null;
#[Gedmo\Timestampable(on: 'update')]
@ -112,11 +115,15 @@ class Message
#[ORM\Column(name: 'votes', type: 'integer', nullable: true)]
protected ?int $votes;
/**
* @var Collection|MessageAttachment[]
* @var Collection<int, MessageAttachment>
*/
#[Groups(['message:read'])]
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\MessageAttachment::class, mappedBy: 'message', cascade: ['remove', 'persist'])]
#[ORM\OneToMany(mappedBy: 'message', targetEntity: MessageAttachment::class, cascade: ['remove', 'persist'])]
protected Collection $attachments;
#[ORM\OneToMany(mappedBy: 'message', targetEntity: MessageFeedback::class, orphanRemoval: true)]
protected Collection $likes;
public function __construct()
{
$this->sendDate = new DateTime('now');
@ -128,20 +135,21 @@ class Message
$this->receivers = new ArrayCollection();
$this->receiversCc = new ArrayCollection();
$this->receiversTo = new ArrayCollection();
$this->likes = new ArrayCollection();
$this->votes = 0;
$this->status = 0;
}
/**
* @return null|Collection|MessageRelUser[]
*/
public function getReceivers() : null|\Doctrine\Common\Collections\Collection|array
public function getReceivers(): null|Collection|array
{
return $this->receivers;
}
/**
* @return MessageRelUser[]
*/
public function getReceiversTo()
public function getReceiversTo(): array
{
/*return $this->getReceivers()->filter(function (MessageRelUser $messageRelUser) {
return MessageRelUser::TYPE_TO === $messageRelUser->getReceiverType();
@ -152,12 +160,13 @@ class Message
$list[] = $receiver;
}
}
return $list;
}
/**
* @return MessageRelUser[]
* @return array<int, MessageRelUser>
*/
public function getReceiversCc()
public function getReceiversCc(): array
{
$list = [];
foreach ($this->receivers as $receiver) {
@ -174,174 +183,174 @@ class Message
*/
return $list;
}
public function getFirstReceiver() : ?MessageRelUser
public function getFirstReceiver(): ?MessageRelUser
{
if ($this->receivers->count() > 0) {
return $this->receivers->first();
}
return null;
}
public function hasReceiver(User $receiver)
public function hasReceiver(User $receiver): bool
{
if ($this->receivers->count()) {
$criteria = Criteria::create()->where(Criteria::expr()->eq('receiver', $receiver))->andWhere(Criteria::expr()->eq('message', $this));
return $this->receivers->matching($criteria)->count() > 0;
}
return false;
}
public function addReceiver(User $receiver, int $receiverType = MessageRelUser::TYPE_TO) : self
public function addReceiver(User $receiver, int $receiverType = MessageRelUser::TYPE_TO): self
{
$messageRelUser = (new MessageRelUser())->setReceiver($receiver)->setReceiverType($receiverType)->setMessage($this);
if (!$this->receivers->contains($messageRelUser)) {
$this->receivers->add($messageRelUser);
}
return $this;
}
public function setReceivers(\Doctrine\Common\Collections\Collection|\Chamilo\CoreBundle\Entity\MessageRelUser $receivers) : self
public function setReceivers(Collection|MessageRelUser $receivers): self
{
/** @var MessageRelUser $receiver */
foreach ($receivers as $receiver) {
$receiver->setMessage($this);
}
$this->receivers = $receivers;
return $this;
}
public function setSender(User $sender) : self
public function setSender(User $sender): self
{
$this->sender = $sender;
return $this;
}
public function getSender() : User
public function getSender(): User
{
return $this->sender;
}
public function setMsgType(int $msgType) : self
public function setMsgType(int $msgType): self
{
$this->msgType = $msgType;
return $this;
}
public function getMsgType() : int
public function getMsgType(): int
{
return $this->msgType;
}
public function setSendDate(DateTime $sendDate) : self
public function setSendDate(DateTime $sendDate): self
{
$this->sendDate = $sendDate;
return $this;
}
/**
* Get sendDate.
*
* @return DateTime
*/
public function getSendDate()
public function getSendDate(): DateTime
{
return $this->sendDate;
}
public function setTitle(string $title) : self
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getTitle() : string
public function getTitle(): string
{
return $this->title;
}
public function setContent(string $content) : self
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getContent() : string
public function getContent(): string
{
return $this->content;
}
public function setUpdateDate(DateTime $updateDate) : self
public function setUpdateDate(DateTime $updateDate): self
{
$this->updateDate = $updateDate;
return $this;
}
/**
* Get updateDate.
*
* @return DateTime
*/
public function getUpdateDate()
public function getUpdateDate(): ?DateTime
{
return $this->updateDate;
}
/**
* Get id.
*
* @return int
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
public function setVotes(int $votes) : self
public function setVotes(int $votes): self
{
$this->votes = $votes;
return $this;
}
public function getVotes() : int
public function getVotes(): int
{
return $this->votes;
}
/**
* Get attachments.
*
* @return Collection|MessageAttachment[]
* @return Collection<int, MessageAttachment>
*/
public function getAttachments() : \Doctrine\Common\Collections\Collection|array
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(MessageAttachment $attachment) : self
public function addAttachment(MessageAttachment $attachment): self
{
$this->attachments->add($attachment);
$attachment->setMessage($this);
return $this;
}
public function getParent() : ?self
public function getParent(): ?self
{
return $this->parent;
}
/**
* @return Collection|Message[]
* @return Collection<int, Message>
*/
public function getChildren() : \Doctrine\Common\Collections\Collection|array
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child) : self
public function addChild(self $child): self
{
$this->children[] = $child;
$child->setParent($this);
return $this;
}
public function setParent(self $parent = null) : self
public function setParent(self $parent = null): self
{
$this->parent = $parent;
return $this;
}
public function getGroup() : ?Usergroup
public function getGroup(): ?Usergroup
{
return $this->group;
}
public function setGroup(?Usergroup $group) : self
public function setGroup(?Usergroup $group): self
{
// $this->msgType = self::MESSAGE_TYPE_GROUP;
$this->group = $group;
return $this;
}
public function getStatus() : int
public function getStatus(): int
{
return $this->status;
}
public function setStatus(int $status) : self
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
}

@ -1,24 +1,24 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use Chamilo\CoreBundle\Controller\Api\CreateMessageAttachmentAction;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource(operations: [new Get(), new GetCollection(), new Post(controller: CreateMessageAttachmentAction::class, deserialize: false, security: 'is_granted(\'ROLE_USER\')', validationContext: ['groups' => ['Default', 'message_attachment:create']], openapiContext: ['requestBody' => ['content' => ['multipart/form-data' => ['schema' => ['type' => 'object', 'properties' => ['file' => ['type' => 'string', 'format' => 'binary'], 'messageId' => ['type' => 'integer']]]]]]])], types: ['http://schema.org/MediaObject'], normalizationContext: ['groups' => 'message:read'])]
#[ORM\Table(name: 'message_attachment')]
#[ORM\Entity(repositoryClass: \Chamilo\CoreBundle\Repository\Node\MessageAttachmentRepository::class)]
class MessageAttachment extends AbstractResource implements ResourceInterface, \Stringable
class MessageAttachment extends AbstractResource implements ResourceInterface, Stringable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
@ -42,17 +42,18 @@ class MessageAttachment extends AbstractResource implements ResourceInterface, \
$this->comment = '';
$this->path = '';
}
public function __toString() : string
public function __toString(): string
{
return $this->getFilename();
}
public function getFilename() : string
public function getFilename(): string
{
return $this->filename;
}
public function setFilename(string $filename) : self
public function setFilename(string $filename): self
{
$this->filename = $filename;
return $this;
}
/**
@ -64,9 +65,10 @@ class MessageAttachment extends AbstractResource implements ResourceInterface, \
{
return $this->path;
}
public function setPath(string $path) : self
public function setPath(string $path): self
{
$this->path = $path;
return $this;
}
/**
@ -78,30 +80,33 @@ class MessageAttachment extends AbstractResource implements ResourceInterface, \
{
return $this->comment;
}
public function setComment(string $comment) : self
public function setComment(string $comment): self
{
$this->comment = $comment;
return $this;
}
public function getSize() : int
public function getSize(): int
{
return $this->size;
}
public function setSize(int $size) : self
public function setSize(int $size): self
{
$this->size = $size;
return $this;
}
public function getMessage() : Message
public function getMessage(): Message
{
return $this->message;
}
public function setMessage(Message $message) : self
public function setMessage(Message $message): self
{
$this->message = $message;
return $this;
}
public function getResourceIdentifier() : int
public function getResourceIdentifier(): int
{
return $this->getId();
}
@ -114,11 +119,11 @@ class MessageAttachment extends AbstractResource implements ResourceInterface, \
{
return $this->id;
}
public function getResourceName() : string
public function getResourceName(): string
{
return $this->getFilename();
}
public function setResourceName(string $name) : self
public function setResourceName(string $name): self
{
return $this->setFilename($name);
}

@ -0,0 +1,172 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Entity\User;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Index;
/**
* Class MessageFeedback.
*
* @package Chamilo\CoreBundle\Entity
*
* @ORM\Table(
* name="message_feedback",
* indexes={
* @Index(name="idx_message_feedback_uid_mid", columns={"message_id", "user_id"})
* }
* )
* @ORM\Entity()
*/
class MessageFeedback
{
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id()
* @ORM\GeneratedValue()
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Message", inversedBy="likes")
* @ORM\JoinColumn(name="message_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $message;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $user;
/**
* @ORM\Column(name="liked", type="boolean", options={"default": false})
*/
private $liked;
/**
* @ORM\Column(name="disliked", type="boolean", options={"default": false})
*/
private $disliked;
/**
* @ORM\Column(name="updated_at", type="datetime", nullable=false)
*/
private $updatedAt;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*
* @return MessageFeedback
*/
public function setId($id)
{
$this->id = $id;
return $this;
}
/**
* @return Message
*/
public function getMessage()
{
return $this->message;
}
/**
* @return MessageFeedback
*/
public function setMessage(Message $message)
{
$this->message = $message;
return $this;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @return MessageFeedback
*/
public function setUser(User $user)
{
$this->user = $user;
return $this;
}
/**
* @return bool
*/
public function isLiked()
{
return $this->liked;
}
/**
* @param bool $liked
*
* @return MessageFeedback
*/
public function setLiked($liked)
{
$this->liked = $liked;
return $this;
}
/**
* @return bool
*/
public function isDisliked()
{
return $this->disliked;
}
/**
* @param bool $disliked
*
* @return MessageFeedback
*/
public function setDisliked($disliked)
{
$this->disliked = $disliked;
return $this;
}
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @return MessageFeedback
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
}

@ -1,28 +1,23 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource]
#[UniqueEntity(fields: ['message', 'receiver'], errorPath: 'message', message: 'This message-receiver relation is already used.')]
#[ORM\Table(name: 'message_rel_user')]
@ -71,74 +66,81 @@ class MessageRelUser
$this->starred = false;
$this->receiverType = self::TYPE_TO;
}
public function getId() : ?int
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|MessageTag[]
*/
public function getTags() : \Doctrine\Common\Collections\Collection|array
public function getTags(): Collection|array
{
return $this->tags;
}
public function addTag(MessageTag $tag) : self
public function addTag(MessageTag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
}
return $this;
}
public function removeTag(MessageTag $tag) : self
public function removeTag(MessageTag $tag): self
{
if ($this->tags->contains($tag)) {
$this->tags->removeElement($tag);
}
return $this;
}
public function isRead() : bool
public function isRead(): bool
{
return $this->read;
}
public function setRead(bool $read) : self
public function setRead(bool $read): self
{
$this->read = $read;
return $this;
}
public function isStarred() : bool
public function isStarred(): bool
{
return $this->starred;
}
public function setStarred(bool $starred) : self
public function setStarred(bool $starred): self
{
$this->starred = $starred;
return $this;
}
public function getMessage() : Message
public function getMessage(): Message
{
return $this->message;
}
public function setMessage(Message $message) : self
public function setMessage(Message $message): self
{
$this->message = $message;
return $this;
}
public function getReceiver() : User
public function getReceiver(): User
{
return $this->receiver;
}
public function setReceiver(User $receiver) : self
public function setReceiver(User $receiver): self
{
$this->receiver = $receiver;
return $this;
}
public function getReceiverType() : int
public function getReceiverType(): int
{
return $this->receiverType;
}
public function setReceiverType(int $receiverType) : self
public function setReceiverType(int $receiverType): self
{
$this->receiverType = $receiverType;
return $this;
}
}

@ -1,20 +1,19 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -23,6 +22,7 @@ use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(operations: [new Get(security: 'is_granted(\'VIEW\', object)'), new Put(security: 'is_granted(\'EDIT\', object)'), new Delete(security: 'is_granted(\'DELETE\', object)'), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(securityPostDenormalize: 'is_granted(\'CREATE\', object)')], security: 'is_granted("ROLE_USER") or object.user == user', denormalizationContext: ['groups' => ['message_tag:write']], normalizationContext: ['groups' => ['message_tag:read']])]
#[UniqueEntity(fields: ['user', 'tag'], errorPath: 'tag', message: 'This user-tag relation is already used.')]
#[ORM\Table(name: 'message_tag')]
@ -64,64 +64,70 @@ class MessageTag
$this->color = 'blue';
$this->messageRelUsers = new ArrayCollection();
}
public function getId() : ?int
public function getId(): ?int
{
return $this->id;
}
public function getUser() : User
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user) : self
public function setUser(User $user): self
{
$this->user = $user;
return $this;
}
public function getTag() : string
public function getTag(): string
{
return $this->tag;
}
public function setTag(string $tag) : self
public function setTag(string $tag): self
{
$this->tag = $tag;
return $this;
}
public function getColor() : string
public function getColor(): string
{
return $this->color;
}
public function setColor(string $color) : self
public function setColor(string $color): self
{
$this->color = $color;
return $this;
}
public function setPosition(int $position) : self
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getPosition() : int
public function getPosition(): int
{
return $this->position;
}
public function getMessages() : Collection
public function getMessages(): Collection
{
return $this->messageRelUsers;
}
public function addMessage(MessageRelUser $message) : self
public function addMessage(MessageRelUser $message): self
{
if (!$this->messageRelUsers->contains($message)) {
$this->messageRelUsers->add($message);
$message->addTag($this);
}
return $this;
}
public function removeMessage(MessageRelUser $message) : self
public function removeMessage(MessageRelUser $message): self
{
if ($this->messageRelUsers->contains($message)) {
$this->messageRelUsers->removeElement($message);
$message->removeTag($this);
}
return $this;
}
}

@ -1,27 +1,27 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new Get(security: 'is_granted(\'ROLE_USER\')'),
@ -34,7 +34,7 @@ use Symfony\Component\Validator\Constraints as Assert;
'groups' => ['page:read', 'timestampable_created:read', 'timestampable_updated:read'],
],
denormalizationContext: [
'groups' => ['page:write']
'groups' => ['page:write'],
]
)]
#[ORM\Table(name: 'page')]
@ -97,89 +97,98 @@ class Page
{
$this->enabled = false;
}
public function getId() : ?int
public function getId(): ?int
{
return $this->id;
}
public function getTitle() : string
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title) : self
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getContent() : string
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content) : self
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getSlug() : string
public function getSlug(): string
{
return $this->slug;
}
public function setSlug(string $slug) : self
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
public function isEnabled() : bool
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled) : self
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}
public function getLocale() : string
public function getLocale(): string
{
return $this->locale;
}
public function setLocale(string $locale) : self
public function setLocale(string $locale): self
{
$this->locale = $locale;
return $this;
}
public function getUrl() : AccessUrl
public function getUrl(): AccessUrl
{
return $this->url;
}
public function setUrl(AccessUrl $url) : self
public function setUrl(AccessUrl $url): self
{
$this->url = $url;
return $this;
}
public function getCreator() : User
public function getCreator(): User
{
return $this->creator;
}
public function setCreator(User $creator) : self
public function setCreator(User $creator): self
{
$this->creator = $creator;
return $this;
}
public function getPosition() : int
public function getPosition(): int
{
return $this->position;
}
public function setPosition(int $position) : self
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getCategory() : ?PageCategory
public function getCategory(): ?PageCategory
{
return $this->category;
}
public function setCategory(PageCategory $category) : self
public function setCategory(PageCategory $category): self
{
$this->category = $category;
return $this;
}
}

@ -1,26 +1,39 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(operations: [new Get(security: 'is_granted(\'ROLE_USER\')'), new Put(security: 'is_granted(\'ROLE_ADMIN\')'), new Delete(security: 'is_granted(\'ROLE_ADMIN\')'), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(security: 'is_granted(\'ROLE_ADMIN\')')], denormalizationContext: ['groups' => ['page_category:write']], normalizationContext: ['groups' => ['page_category:read']])]
#[ApiResource(
operations: [
new Get(security: 'is_granted(\'ROLE_USER\')'),
new Put(security: 'is_granted(\'ROLE_ADMIN\')'),
new Delete(security: 'is_granted(\'ROLE_ADMIN\')'),
new GetCollection(security: 'is_granted(\'ROLE_USER\')'),
new Post(security: 'is_granted(\'ROLE_ADMIN\')'),
],
normalizationContext: [
'groups' => ['page_category:read'],
],
denormalizationContext: [
'groups' => ['page_category:write'],
]
)]
#[ORM\Table(name: 'page_category')]
#[ORM\Entity]
class PageCategory
@ -46,50 +59,54 @@ class PageCategory
/**
* @var Collection|Page[]
*/
#[ORM\OneToMany(targetEntity: Page::class, mappedBy: 'category', cascade: ['persist'])]
#[ORM\OneToMany(mappedBy: 'category', targetEntity: Page::class, cascade: ['persist'])]
protected Collection $pages;
public function __construct()
{
$this->pages = new ArrayCollection();
}
public function getId() : ?int
public function getId(): ?int
{
return $this->id;
}
public function getTitle() : string
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title) : self
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getCreator() : User
public function getCreator(): User
{
return $this->creator;
}
public function setCreator(User $creator) : self
public function setCreator(User $creator): self
{
$this->creator = $creator;
return $this;
}
public function getType() : string
public function getType(): string
{
return $this->type;
}
public function setType(string $type) : self
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getPages()
{
return $this->pages;
}
public function setPages(Collection $pages) : self
public function setPages(Collection $pages): self
{
$this->pages = $pages;
return $this;
}
}

@ -1,32 +1,31 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use Chamilo\CoreBundle\Controller\Api\CreatePersonalFileAction;
use Chamilo\CoreBundle\Controller\Api\UpdatePersonalFileAction;
use Chamilo\CoreBundle\Entity\Listener\ResourceListener;
use Chamilo\CoreBundle\Repository\Node\PersonalFileRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
*/
#[ApiResource(operations: [new Put(controller: UpdatePersonalFileAction::class, deserialize: false, security: 'is_granted(\'EDIT\', object.resourceNode)'), new Get(security: 'is_granted(\'VIEW\', object.resourceNode)'), new Delete(security: 'is_granted(\'DELETE\', object.resourceNode)'), new Post(controller: CreatePersonalFileAction::class, deserialize: false, security: 'is_granted(\'ROLE_USER\')', validationContext: ['groups' => ['Default', 'media_object_create', 'personal_file:write']], openapiContext: ['requestBody' => ['content' => ['multipart/form-data' => ['schema' => ['type' => 'object', 'properties' => ['title' => ['type' => 'string'], 'comment' => ['type' => 'string'], 'contentFile' => ['type' => 'string'], 'uploadFile' => ['type' => 'string', 'format' => 'binary'], 'parentResourceNodeId' => ['type' => 'integer'], 'resourceLinkList' => ['type' => 'array', 'items' => ['type' => 'object', 'properties' => ['visibility' => ['type' => 'integer'], 'c_id' => ['type' => 'integer'], 'session_id' => ['type' => 'integer']]]]]]]]]]), new GetCollection(security: 'is_granted(\'ROLE_USER\')')], normalizationContext: ['groups' => ['personal_file:read', 'resource_node:read']], denormalizationContext: ['groups' => ['personal_file:write']])]
#[ORM\Table(name: 'personal_file')]
#[ORM\EntityListeners([ResourceListener::class])]
@ -34,7 +33,7 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(filterClass: SearchFilter::class, properties: ['title' => 'partial', 'resourceNode.parent' => 'exact'])]
#[ApiFilter(filterClass: PropertyFilter::class)]
#[ApiFilter(filterClass: OrderFilter::class, properties: ['id', 'resourceNode.title', 'resourceNode.createdAt', 'resourceNode.resourceFile.size', 'resourceNode.updatedAt'])]
class PersonalFile extends AbstractResource implements ResourceInterface, \Stringable
class PersonalFile extends AbstractResource implements ResourceInterface, Stringable
{
use TimestampableEntity;
#[Groups(['personal_file:read'])]
@ -49,32 +48,33 @@ class PersonalFile extends AbstractResource implements ResourceInterface, \Strin
public function __construct()
{
}
public function __toString() : string
public function __toString(): string
{
return $this->getTitle();
}
public function getId() : int
public function getId(): int
{
return $this->id;
}
public function getTitle() : string
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title) : self
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
public function getResourceIdentifier() : int
public function getResourceIdentifier(): int
{
return $this->getId();
}
public function getResourceName() : string
public function getResourceName(): string
{
return $this->getTitle();
}
public function setResourceName(string $name) : self
public function setResourceName(string $name): self
{
return $this->setTitle($name);
}

@ -10,14 +10,11 @@ use Chamilo\CoreBundle\Traits\UserTrait;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Portfolio.
*/
#[ORM\Table(name: 'portfolio')]
#[ORM\Index(name: 'user', columns: ['user_id'])]
#[ORM\Index(name: 'course', columns: ['c_id'])]
#[ORM\Index(name: 'session', columns: ['session_id'])]
#[ORM\Index(name: 'category', columns: ['category_id'])]
#[ORM\Index(columns: ['user_id'], name: 'user')]
#[ORM\Index(columns: ['c_id'], name: 'course')]
#[ORM\Index(columns: ['session_id'], name: 'session')]
#[ORM\Index(columns: ['category_id'], name: 'category')]
#[ORM\Entity]
class Portfolio
{
@ -59,6 +56,24 @@ class Portfolio
#[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'id')]
protected PortfolioCategory $category;
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\PortfolioComment::class)]
private $comments;
#[ORM\Column(name: 'origin', type: 'integer', nullable: true)]
private int $origin;
#[ORM\Column(name: 'origin_type', type: 'integer', nullable: true)]
private int $originType;
#[ORM\Column(name: 'score', type: 'float', nullable: true)]
private float $score;
#[ORM\Column(name: 'is_highlighted', type: 'boolean', options: ['default' => false])]
private bool $isHighlighted = false;
#[ORM\Column(name: 'is_template', type: 'boolean', options: ['default' => false])]
private bool $isTemplate = false;
public function __construct()
{
$this->category = new PortfolioCategory();
@ -244,4 +259,94 @@ class Portfolio
return $this;
}
public function getComments(): Collection
{
return $this->comments;
}
public function getLastComments(int $number = 3, bool $avoidPerUserVisibility = false): Collection
{
$criteria = Criteria::create();
$criteria
->orderBy(['date' => 'DESC'])
->setMaxResults($number);
if ($avoidPerUserVisibility) {
$criteria->where(
Criteria::expr()->neq('visibility', PortfolioComment::VISIBILITY_PER_USER)
);
}
return $this->comments->matching($criteria);
}
public function getOrigin(): ?int
{
return $this->origin;
}
/**
* @return \Chamilo\CoreBundle\Entity\Portfolio
*/
public function setOrigin(?int $origin): Portfolio
{
$this->origin = $origin;
return $this;
}
public function getOriginType(): ?int
{
return $this->originType;
}
/**
* @return \Chamilo\CoreBundle\Entity\Portfolio
*/
public function setOriginType(?int $originType): Portfolio
{
$this->originType = $originType;
return $this;
}
public function getExcerpt(int $count = 380): string
{
return api_get_short_text_from_html($this->content, $count);
}
public function getScore(): ?float
{
return $this->score;
}
public function setScore(?float $score): void
{
$this->score = $score;
}
public function isHighlighted(): bool
{
return $this->isHighlighted;
}
public function setIsHighlighted(bool $isHighlighted): Portfolio
{
$this->isHighlighted = $isHighlighted;
return $this;
}
public function isTemplate(): bool
{
return $this->isTemplate;
}
public function setIsTemplate(bool $isTemplate): Portfolio
{
$this->isTemplate = $isTemplate;
return $this;
}
}

@ -0,0 +1,135 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class PortfolioAttachment.
*
* @package Chamilo\CoreBundle\Entity
*
* @ORM\Table(name="portfolio_attachment")
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\PortfolioAttachmentRepository")
*/
class PortfolioAttachment
{
public const TYPE_ITEM = 1;
public const TYPE_COMMENT = 2;
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(name="path", type="string", length=255)
*/
protected $path;
/**
* @ORM\Column(name="comment", type="text", nullable=true)
*/
protected $comment;
/**
* @ORM\Column(name="size", type="integer")
*/
protected $size;
/**
* @ORM\Column(name="filename", type="string", length=255)
*/
protected $filename;
/**
* @ORM\Column(name="origin_id", type="integer")
*/
private $origin;
/**
* @ORM\Column(name="origin_type", type="integer")
*/
private $originType;
public function getId(): int
{
return $this->id;
}
public function getPath(): string
{
return $this->path;
}
public function setPath(string $path): PortfolioAttachment
{
$this->path = $path;
return $this;
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): PortfolioAttachment
{
$this->comment = $comment;
return $this;
}
public function getSize(): int
{
return $this->size;
}
public function setSize(int $size): PortfolioAttachment
{
$this->size = $size;
return $this;
}
public function getFilename(): string
{
return $this->filename;
}
public function setFilename(string $filename): PortfolioAttachment
{
$this->filename = $filename;
return $this;
}
public function getOrigin(): int
{
return $this->origin;
}
public function setOrigin(int $origin): PortfolioAttachment
{
$this->origin = $origin;
return $this;
}
public function getOriginType(): int
{
return $this->originType;
}
public function setOriginType(int $originType): PortfolioAttachment
{
$this->originType = $originType;
return $this;
}
}

@ -10,14 +10,12 @@ use Chamilo\CoreBundle\Traits\UserTrait;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
/**
* Class PortfolioCategory.
*/
#[ORM\Table(name: 'portfolio_category')]
#[ORM\Index(name: 'user', columns: ['user_id'])]
#[ORM\Index(columns: ['user_id'], name: 'user')]
#[ORM\Entity]
class PortfolioCategory implements \Stringable
class PortfolioCategory implements Stringable
{
use UserTrait;
@ -84,9 +82,6 @@ class PortfolioCategory implements \Stringable
return $this;
}
/**
* Get description.
*/
public function getDescription(): ?string
{
return $this->description;

@ -0,0 +1,275 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Entity\User;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* Class PortfolioComment.
*
* @package Chamilo\CoreBundle\Entity
*
* @Gedmo\Tree(type="nested")
* @ORM\Table(name="portfolio_comment")
* Add @ to the next line if api_get_configuration_value('allow_portfolio_tool') is true
* @ORM\Entity(repositoryClass="Chamilo\CoreBundle\Entity\Repository\PortfolioCommentRepository")
*/
class PortfolioComment
{
public const VISIBILITY_VISIBLE = 1;
public const VISIBILITY_PER_USER = 2;
/**
* @ORM\Column(name="visibility", type="smallint", options={"default": 1})
*/
protected $visibility = 1;
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
* @ORM\JoinColumn(name="author_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $author;
/**
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Portfolio", inversedBy="comments")
* @ORM\JoinColumn(name="item_id", referencedColumnName="id", nullable=false, onDelete="CASCADE")
*/
private $item;
/**
* @ORM\Column(name="content", type="text")
*/
private $content;
/**
* @ORM\Column(name="date", type="datetime")
*/
private $date;
/**
* @ORM\Column(name="is_important", type="boolean", options={"default":false})
*/
private $isImportant;
/**
* @Gedmo\TreeLeft()
* @ORM\Column(name="lft", type="integer")
*/
private $lft;
/**
* @Gedmo\TreeLevel()
* @ORM\Column(name="lvl", type="integer")
*/
private $lvl;
/**
* @Gedmo\TreeRight()
* @ORM\Column(name="rgt", type="integer")
*/
private $rgt;
/**
* @Gedmo\TreeRoot()
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\PortfolioComment")
* @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE")
*/
private $root;
/**
* @Gedmo\TreeParent()
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\PortfolioComment", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\PortfolioComment", mappedBy="parent")
* @ORM\OrderBy({"lft"="DESC"})
*/
private $children;
/**
* @ORM\Column(name="score", type="float", nullable=true)
*/
private $score;
/**
* @ORM\Column(name="is_template", type="boolean", options={"default": false})
*/
private $isTemplate = false;
/**
* PortfolioComment constructor.
*/
public function __construct()
{
$this->isImportant = false;
$this->children = new ArrayCollection();
$this->visibility = 1;
}
public function getId(): int
{
return $this->id;
}
public function getAuthor(): User
{
return $this->author;
}
public function setAuthor(User $author): PortfolioComment
{
$this->author = $author;
return $this;
}
/**
* @return \Chamilo\CoreBundle\Entity\Portfolio
*/
public function getItem(): Portfolio
{
return $this->item;
}
/**
* @param \Chamilo\CoreBundle\Entity\Portfolio $item
*/
public function setItem(Portfolio $item): PortfolioComment
{
$this->item = $item;
return $this;
}
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content): PortfolioComment
{
$this->content = $content;
return $this;
}
public function getDate(): DateTime
{
return $this->date;
}
public function setDate(DateTime $date): PortfolioComment
{
$this->date = $date;
return $this;
}
/**
* @return \Chamilo\CoreBundle\Entity\PortfolioComment|null
*/
public function getParent(): ?PortfolioComment
{
return $this->parent;
}
/**
* @param \Chamilo\CoreBundle\Entity\PortfolioComment|null $parent
*/
public function setParent(?PortfolioComment $parent): PortfolioComment
{
$this->parent = $parent;
return $this;
}
public function getChildren(): ArrayCollection
{
return $this->children;
}
public function setChildren(ArrayCollection $children): PortfolioComment
{
$this->children = $children;
return $this;
}
public function isImportant(): bool
{
return $this->isImportant;
}
public function setIsImportant(bool $isImportant): void
{
$this->isImportant = $isImportant;
}
public function getExcerpt(int $count = 190): string
{
return api_get_short_text_from_html($this->content, $count);
}
public function getScore(): ?float
{
return $this->score;
}
public function setScore(?float $score): void
{
$this->score = $score;
}
/**
* @return \Chamilo\CoreBundle\Entity\PortfolioComment
*/
public function getRoot(): PortfolioComment
{
return $this->root;
}
public function getLvl(): int
{
return $this->lvl;
}
public function isTemplate(): bool
{
return $this->isTemplate;
}
public function setIsTemplate(bool $isTemplate): PortfolioComment
{
$this->isTemplate = $isTemplate;
return $this;
}
public function getVisibility(): int
{
return $this->visibility;
}
public function setVisibility(int $visibility): PortfolioComment
{
$this->visibility = $visibility;
return $this;
}
}

@ -9,10 +9,11 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
#[ORM\Table(name: 'skill_level_profile')]
#[ORM\Entity]
class Profile implements \Stringable
class Profile implements Stringable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
@ -23,16 +24,15 @@ class Profile implements \Stringable
protected string $name;
/**
* @var Skill[]|Collection
* @var Collection<int, Skill>
*/
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\Skill::class, mappedBy: 'profile', cascade: ['persist'])]
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: Skill::class, cascade: ['persist'])]
protected Collection $skills;
/**
*
* @var Level[]|Collection
* @var Collection<int, Level>
*/
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\Level::class, mappedBy: 'profile', cascade: ['persist'])]
#[ORM\OneToMany(mappedBy: 'profile', targetEntity: Level::class, cascade: ['persist'])]
#[ORM\OrderBy(['position' => 'ASC'])]
protected Collection $levels;
@ -70,7 +70,7 @@ class Profile implements \Stringable
/**
* @return Skill[]|Collection
*/
public function getSkills(): array|\Doctrine\Common\Collections\Collection
public function getSkills(): array|Collection
{
return $this->skills;
}
@ -78,7 +78,7 @@ class Profile implements \Stringable
/**
* @param Skill[]|Collection $skills
*/
public function setSkills(array|\Doctrine\Common\Collections\Collection $skills): self
public function setSkills(array|Collection $skills): self
{
$this->skills = $skills;
@ -88,7 +88,7 @@ class Profile implements \Stringable
/**
* @return Level[]|Collection
*/
public function getLevels(): array|\Doctrine\Common\Collections\Collection
public function getLevels(): array|Collection
{
return $this->levels;
}

@ -130,7 +130,7 @@ class Promotion
/**
* @return Session[]|Collection
*/
public function getSessions(): array|\Doctrine\Common\Collections\Collection
public function getSessions(): array|Collection
{
return $this->sessions;
}
@ -145,7 +145,7 @@ class Promotion
/**
* @return SysAnnouncement[]|Collection
*/
public function getAnnouncements(): array|\Doctrine\Common\Collections\Collection
public function getAnnouncements(): array|Collection
{
return $this->announcements;
}
@ -153,7 +153,7 @@ class Promotion
/**
* @param SysAnnouncement[]|Collection $announcements
*/
public function setAnnouncements(array|\Doctrine\Common\Collections\Collection $announcements): self
public function setAnnouncements(array|Collection $announcements): self
{
$this->announcements = $announcements;

@ -4,12 +4,13 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Repository\ResetPasswordRequestRepository;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestInterface;
use SymfonyCasts\Bundle\ResetPassword\Model\ResetPasswordRequestTrait;
#[ORM\Entity(repositoryClass: \Chamilo\CoreBundle\Repository\ResetPasswordRequestRepository::class)]
#[ORM\Entity(repositoryClass: ResetPasswordRequestRepository::class)]
class ResetPasswordRequest implements ResetPasswordRequestInterface
{
use ResetPasswordRequestTrait;
@ -19,9 +20,13 @@ class ResetPasswordRequest implements ResetPasswordRequestInterface
#[ORM\Column(type: 'integer')]
private ?int $id = null;
public function __construct(#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\User::class)]
private ?object $user, DateTimeInterface $expiresAt, string $selector, string $hashedToken)
{
public function __construct(
#[ORM\ManyToOne(targetEntity: User::class)]
private ?object $user,
DateTimeInterface $expiresAt,
string $selector,
string $hashedToken
) {
$this->initialize($expiresAt, $selector, $hashedToken);
}

@ -14,6 +14,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
use Gedmo\Tree\Traits\NestedSetEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
@ -26,7 +27,7 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
#[ORM\Table(name: 'resource_comment')]
#[Gedmo\Tree(type: 'nested')]
#[ORM\Entity(repositoryClass: \Gedmo\Tree\Entity\Repository\NestedTreeRepository::class)]
#[ORM\Entity(repositoryClass: NestedTreeRepository::class)]
class ResourceComment
{
use TimestampableTypedEntity;
@ -39,12 +40,12 @@ class ResourceComment
#[Groups(['comment:read'])]
protected ?int $id = null;
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\ResourceNode::class, inversedBy: 'comments')]
#[ORM\ManyToOne(targetEntity: ResourceNode::class, inversedBy: 'comments')]
#[ORM\JoinColumn(name: 'resource_node_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ResourceNode $resourceNode;
#[Groups(['comment:read'])]
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\User::class)]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected User $author;
@ -55,7 +56,7 @@ class ResourceComment
#[ORM\JoinColumn(onDelete: 'CASCADE')]
#[Gedmo\TreeParent]
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\ResourceComment::class, inversedBy: 'children')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
protected ?ResourceComment $parent = null;
#[Groups(['comment:read'])]
@ -69,9 +70,9 @@ class ResourceComment
protected DateTime $updatedAt;
/**
* @var Collection|ResourceComment[]
* @var Collection<int, ResourceComment>
*/
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\ResourceComment::class, mappedBy: 'parent')]
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
#[ORM\OrderBy(['id' => 'ASC'])]
protected Collection $children;
@ -136,17 +137,14 @@ class ResourceComment
}
/**
* @return ResourceComment[]|Collection
* @return Collection<int, ResourceComment>
*/
public function getChildren(): array|\Doctrine\Common\Collections\Collection
public function getChildren(): Collection
{
return $this->children;
}
/**
* @param ResourceComment[]|Collection $children
*/
public function setChildren(array|\Doctrine\Common\Collections\Collection $children): self
public function setChildren(Collection $children): self
{
$this->children = $children;

@ -1,43 +1,84 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use Chamilo\CoreBundle\Controller\CreateResourceFileAction;
use DateTime;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Stringable;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
//
//* attributes={"security"="is_granted('ROLE_ADMIN')"},
/**
* @Vich\Uploadable
*/
#[ApiResource(operations: [new Get(), new Post(controller: CreateResourceFileAction::class, deserialize: false, security: 'is_granted(\'ROLE_USER\')', validationContext: ['groups' => ['Default', 'media_object_create', 'document:write']], openapiContext: ['requestBody' => ['content' => ['multipart/form-data' => ['schema' => ['type' => 'object', 'properties' => ['file' => ['type' => 'string', 'format' => 'binary']]]]]]]), new GetCollection()], types: ['http://schema.org/MediaObject'], normalizationContext: ['groups' => ['resource_file:read', 'resource_node:read', 'document:read', 'media_object_read', 'message:read']])]
#[ApiResource(
types: ['http://schema.org/MediaObject'],
operations: [
new Get(),
new Post(
controller: CreateResourceFileAction::class,
openapiContext: [
'requestBody' => [
'content' => [
'multipart/form-data' => [
'schema' => [
'type' => 'object',
'properties' => [
'file' => [
'type' => 'string',
'format' => 'binary',
],
],
],
],
],
],
],
security: 'is_granted(\'ROLE_USER\')',
validationContext: [
'groups' => ['Default', 'media_object_create', 'document:write'],
],
deserialize: false
),
new GetCollection(),
],
normalizationContext: [
'groups' => [
'resource_file:read',
'resource_node:read',
'document:read',
'media_object_read',
'message:read',
],
]
)]
#[ORM\Table(name: 'resource_file')]
#[ORM\Entity]
#[ApiFilter(filterClass: PropertyFilter::class)]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['name' => 'partial'])]
#[ApiFilter(filterClass: OrderFilter::class, properties: ['id', 'name', 'size', 'updatedAt'])]
class ResourceFile implements \Stringable
class ResourceFile implements Stringable
{
use TimestampableEntity;
#[Groups(['resource_file:read', 'resource_node:read', 'document:read', 'message:read'])]
@ -82,7 +123,7 @@ class ResourceFile implements \Stringable
protected ?File $file = null;
#[ORM\Column(name: 'crop', type: 'string', length: 255, nullable: true)]
protected ?string $crop = null;
#[ORM\OneToOne(targetEntity: \Chamilo\CoreBundle\Entity\ResourceNode::class, mappedBy: 'resourceFile')]
#[ORM\OneToOne(mappedBy: 'resourceFile', targetEntity: ResourceNode::class)]
protected ResourceNode $resourceNode;
/**
* @var string[]
@ -111,87 +152,89 @@ class ResourceFile implements \Stringable
$this->metadata = [];
$this->dimensions = [];
}
public function __toString() : string
public function __toString(): string
{
return $this->getOriginalName();
}
public function isText() : bool
public function isText(): bool
{
$mimeType = $this->getMimeType();
return str_contains($mimeType, 'text');
}
public function isImage() : bool
public function isImage(): bool
{
$mimeType = $this->getMimeType();
return str_contains($mimeType, 'image');
}
public function isVideo() : bool
public function isVideo(): bool
{
$mimeType = $this->getMimeType();
return str_contains($mimeType, 'video');
}
public function isAudio() : bool
public function isAudio(): bool
{
$mimeType = $this->getMimeType();
return str_contains($mimeType, 'audio');
}
public function getName() : ?string
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name) : self
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return string
*/
public function getCrop()
public function getCrop(): ?string
{
return $this->crop;
}
/**
* $crop example: 100,100,100,100 = width,height,x,y.
*/
public function setCrop(string $crop) : self
public function setCrop(string $crop): self
{
$this->crop = $crop;
return $this;
}
public function getSize() : ?int
public function getSize(): ?int
{
return $this->size;
}
public function setSize(?int $size) : self
public function setSize(?int $size): self
{
$this->size = $size;
return $this;
}
public function getResourceNode() : ResourceNode
public function getResourceNode(): ResourceNode
{
return $this->resourceNode;
}
public function setResourceNode(ResourceNode $resourceNode) : self
public function setResourceNode(ResourceNode $resourceNode): self
{
$this->resourceNode = $resourceNode;
return $this;
}
/*public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): self
{
$this->enabled = $enabled;
return $this;
}*/
/**
* @return int
*/
public function getId()
public function getId(): ?int
{
return $this->id;
}
@ -199,84 +242,89 @@ class ResourceFile implements \Stringable
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}*/
public function getMimeType() : ?string
public function getMimeType(): ?string
{
return $this->mimeType;
}
public function setMimeType(?string $mimeType) : self
public function setMimeType(?string $mimeType): self
{
$this->mimeType = $mimeType;
return $this;
}
public function getOriginalName() : string
public function getOriginalName(): string
{
return $this->originalName;
}
public function setOriginalName(?string $originalName) : self
public function setOriginalName(?string $originalName): self
{
$this->originalName = $originalName;
return $this;
}
public function getDimensions() : array
public function getDimensions(): array
{
return $this->dimensions;
}
public function setDimensions(?array $dimensions) : self
public function setDimensions(?array $dimensions): self
{
$this->dimensions = $dimensions;
return $this;
}
public function getWidth() : int
public function getWidth(): int
{
$data = $this->getDimensions();
if ([] !== $data) {
//$data = explode(',', $data);
return (int) $data[0];
}
return 0;
}
public function getHeight() : int
public function getHeight(): int
{
$data = $this->getDimensions();
if ([] !== $data) {
//$data = explode(',', $data);
return (int) $data[1];
}
return 0;
}
public function getMetadata() : array
public function getMetadata(): array
{
return $this->metadata;
}
public function setMetadata(array $metadata) : self
public function setMetadata(array $metadata): self
{
$this->metadata = $metadata;
return $this;
}
public function getDescription() : string
public function getDescription(): string
{
return $this->description;
}
public function setDescription(string $description) : self
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getFile() : ?File
public function getFile(): ?File
{
return $this->file;
}
/**
* @param File|UploadedFile|null $file
*/
public function setFile(\Symfony\Component\HttpFoundation\File\File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $file = null) : self
public function setFile(File|UploadedFile|null $file = null): self
{
$this->file = $file;
if (null !== $file) {
@ -284,6 +332,7 @@ class ResourceFile implements \Stringable
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable();
}
return $this;
}
}

@ -1,28 +1,26 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Chamilo\CourseBundle\Entity\CCalendarEvent;
use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Entity\CGroup;
use Chamilo\CourseBundle\Entity\CTool;
use Chamilo\CourseBundle\Entity\CToolIntro;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource]
@ -102,32 +100,37 @@ class ResourceLink implements \Stringable
$this->resourceRights = new ArrayCollection();
$this->visibility = self::VISIBILITY_DRAFT;
}
public function __toString() : string
public function __toString(): string
{
return (string) $this->getId();
}
public function getStartVisibilityAt() : ?DateTimeInterface
public function getStartVisibilityAt(): ?DateTimeInterface
{
return $this->startVisibilityAt;
}
public function setStartVisibilityAt(?DateTimeInterface $startVisibilityAt) : self
public function setStartVisibilityAt(?DateTimeInterface $startVisibilityAt): self
{
$this->startVisibilityAt = $startVisibilityAt;
return $this;
}
public function getEndVisibilityAt() : ?DateTimeInterface
public function getEndVisibilityAt(): ?DateTimeInterface
{
return $this->endVisibilityAt;
}
public function setEndVisibilityAt(?DateTimeInterface $endVisibilityAt) : self
public function setEndVisibilityAt(?DateTimeInterface $endVisibilityAt): self
{
$this->endVisibilityAt = $endVisibilityAt;
return $this;
}
/**
* @param ResourceRight[]|Collection $rights
* @param Collection<int, ResourceRight> $rights
*
* @return ResourceLink
*/
public function setResourceRights(array|\Doctrine\Common\Collections\Collection $rights) : self
public function setResourceRights(Collection $rights): self
{
$this->resourceRights = $rights;
/*foreach ($rights as $right) {
@ -135,18 +138,19 @@ class ResourceLink implements \Stringable
}*/
return $this;
}
public function addResourceRight(ResourceRight $right) : self
public function addResourceRight(ResourceRight $right): self
{
if (!$this->resourceRights->contains($right)) {
$right->setResourceLink($this);
$this->resourceRights->add($right);
}
return $this;
}
/**
* @return Collection|ResourceRight[]
*/
public function getResourceRights() : \Doctrine\Common\Collections\Collection|array
public function getResourceRights(): Collection|array
{
return $this->resourceRights;
}
@ -157,106 +161,122 @@ class ResourceLink implements \Stringable
{
return $this->id;
}
public function setUser(User $user = null) : self
public function setUser(User $user = null): self
{
$this->user = $user;
return $this;
}
public function getCourse() : ?Course
public function getCourse(): ?Course
{
return $this->course;
}
public function setCourse(Course $course = null) : self
public function setCourse(Course $course = null): self
{
$this->course = $course;
return $this;
}
public function getSession() : ?Session
public function getSession(): ?Session
{
return $this->session;
}
public function setSession(Session $session = null) : self
public function setSession(Session $session = null): self
{
$this->session = $session;
return $this;
}
public function hasSession() : bool
public function hasSession(): bool
{
return null !== $this->session;
}
public function hasCourse() : bool
public function hasCourse(): bool
{
return null !== $this->course;
}
public function hasGroup() : bool
public function hasGroup(): bool
{
return null !== $this->group;
}
public function getGroup() : ?CGroup
public function getGroup(): ?CGroup
{
return $this->group;
}
public function setGroup(CGroup $group = null) : self
public function setGroup(CGroup $group = null): self
{
$this->group = $group;
return $this;
}
public function getUserGroup() : ?Usergroup
public function getUserGroup(): ?Usergroup
{
return $this->userGroup;
}
public function setUserGroup(Usergroup $group = null) : self
public function setUserGroup(Usergroup $group = null): self
{
$this->userGroup = $group;
return $this;
}
public function getUser() : ?User
public function getUser(): ?User
{
return $this->user;
}
public function hasUser() : bool
public function hasUser(): bool
{
return null !== $this->user;
}
public function setResourceNode(ResourceNode $resourceNode) : self
public function setResourceNode(ResourceNode $resourceNode): self
{
$this->resourceNode = $resourceNode;
return $this;
}
public function getResourceNode() : ResourceNode
public function getResourceNode(): ResourceNode
{
return $this->resourceNode;
}
public function getVisibility() : int
public function getVisibility(): int
{
return $this->visibility;
}
public function setVisibility(int $visibility) : self
public function setVisibility(int $visibility): self
{
if (!\in_array($visibility, self::getVisibilityList(), true)) {
$message = sprintf('The visibility is not valid. Valid options: %s', print_r(self::getVisibilityList(), true));
$message = sprintf(
'The visibility is not valid. Valid options: %s',
print_r(self::getVisibilityList(), true)
);
throw new LogicException($message);
}
$this->visibility = $visibility;
return $this;
}
public function isPublished() : bool
public function isPublished(): bool
{
return self::VISIBILITY_PUBLISHED === $this->getVisibility();
}
public function isPending() : bool
public function isPending(): bool
{
return self::VISIBILITY_PENDING === $this->getVisibility();
}
public function isDraft() : bool
public function isDraft(): bool
{
return self::VISIBILITY_DRAFT === $this->getVisibility();
}
public static function getVisibilityList() : array
public static function getVisibilityList(): array
{
return ['Draft' => self::VISIBILITY_DRAFT, 'Pending' => self::VISIBILITY_PENDING, 'Published' => self::VISIBILITY_PUBLISHED, 'Deleted' => self::VISIBILITY_DELETED];
return [
'Draft' => self::VISIBILITY_DRAFT,
'Pending' => self::VISIBILITY_PENDING,
'Published' => self::VISIBILITY_PUBLISHED,
'Deleted' => self::VISIBILITY_DELETED,
];
}
public function getVisibilityName() : string
public function getVisibilityName(): string
{
return array_flip(static::getVisibilityList())[$this->getVisibility()];
}

@ -1,23 +1,22 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Metadata\ApiFilter;
use Chamilo\CoreBundle\Traits\TimestampableAgoTrait;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use Chamilo\CourseBundle\Entity\CShortcut;
@ -27,17 +26,16 @@ use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use InvalidArgumentException;
use Stringable;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Uid\Uuid;
use Symfony\Component\Uid\UuidV4;
use Symfony\Component\Validator\Constraints as Assert;
//* attributes={"security"="is_granted('ROLE_ADMIN')"},
/**
* Base entity for all resources.
*
*
*
*/
#[ApiResource(operations: [new Get(), new Put(), new Patch(), new Delete(), new GetCollection()], denormalizationContext: ['groups' => ['resource_node:write', 'document:write']], normalizationContext: ['groups' => ['resource_node:read', 'document:read']])]
#[ORM\Table(name: 'resource_node')]
@ -73,7 +71,7 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(uriTemplate: '/c_tools/{iid}/resource_node/parent.{_format}', uriVariables: ['iid' => new Link(fromClass: \Chamilo\CourseBundle\Entity\CTool::class, identifiers: ['iid']), 'resourceNode' => new Link(fromClass: self::class, identifiers: [], expandedValue: 'resource_node')], status: 200, filters: ['annotated_chamilo_core_bundle_entity_resource_node_api_platform_core_bridge_doctrine_orm_filter_order_filter', 'annotated_chamilo_core_bundle_entity_resource_node_api_platform_serializer_filter_property_filter', 'annotated_chamilo_core_bundle_entity_resource_node_api_platform_core_bridge_doctrine_orm_filter_search_filter'], normalizationContext: ['groups' => ['resource_node:read', 'document:read']], operations: [new Get()])]
#[ApiResource(uriTemplate: '/c_tool_intros/{iid}/resource_node.{_format}', uriVariables: ['iid' => new Link(fromClass: \Chamilo\CourseBundle\Entity\CToolIntro::class, identifiers: ['iid'])], status: 200, filters: ['annotated_chamilo_core_bundle_entity_resource_node_api_platform_core_bridge_doctrine_orm_filter_order_filter', 'annotated_chamilo_core_bundle_entity_resource_node_api_platform_serializer_filter_property_filter', 'annotated_chamilo_core_bundle_entity_resource_node_api_platform_core_bridge_doctrine_orm_filter_search_filter'], normalizationContext: ['groups' => ['resource_node:read', 'document:read']], operations: [new Get()])]
#[ApiResource(uriTemplate: '/c_tool_intros/{iid}/resource_node/parent.{_format}', uriVariables: ['iid' => new Link(fromClass: \Chamilo\CourseBundle\Entity\CToolIntro::class, identifiers: ['iid']), 'resourceNode' => new Link(fromClass: self::class, identifiers: [], expandedValue: 'resource_node')], status: 200, filters: ['annotated_chamilo_core_bundle_entity_resource_node_api_platform_core_bridge_doctrine_orm_filter_order_filter', 'annotated_chamilo_core_bundle_entity_resource_node_api_platform_serializer_filter_property_filter', 'annotated_chamilo_core_bundle_entity_resource_node_api_platform_core_bridge_doctrine_orm_filter_search_filter'], normalizationContext: ['groups' => ['resource_node:read', 'document:read']], operations: [new Get()])]
class ResourceNode implements \Stringable
class ResourceNode implements Stringable
{
use TimestampableTypedEntity;
use TimestampableAgoTrait;
@ -116,12 +114,12 @@ class ResourceNode implements \Stringable
protected User $creator;
#[ORM\JoinColumn(name: 'parent_id', onDelete: 'CASCADE')]
#[Gedmo\TreeParent]
#[ORM\ManyToOne(targetEntity: \Chamilo\CoreBundle\Entity\ResourceNode::class, inversedBy: 'children')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
protected ?ResourceNode $parent = null;
/**
* @var Collection|ResourceNode[]
*/
#[ORM\OneToMany(targetEntity: \Chamilo\CoreBundle\Entity\ResourceNode::class, mappedBy: 'parent')]
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
#[ORM\OrderBy(['id' => 'ASC'])]
protected Collection $children;
#[Gedmo\TreeLevel]
@ -172,11 +170,11 @@ class ResourceNode implements \Stringable
$this->createdAt = new DateTime();
$this->fileEditableText = false;
}
public function __toString() : string
public function __toString(): string
{
return $this->getPathForDisplay();
}
public function getUuid() : ?UuidV4
public function getUuid(): ?UuidV4
{
return $this->uuid;
}
@ -189,17 +187,18 @@ class ResourceNode implements \Stringable
{
return $this->id;
}
public function hasCreator() : bool
public function hasCreator(): bool
{
return null !== $this->creator;
}
public function getCreator() : ?User
public function getCreator(): ?User
{
return $this->creator;
}
public function setCreator(User $creator) : self
public function setCreator(User $creator): self
{
$this->creator = $creator;
return $this;
}
/**
@ -207,29 +206,30 @@ class ResourceNode implements \Stringable
*
* @return Collection|ResourceNode[]
*/
public function getChildren() : \Doctrine\Common\Collections\Collection|array
public function getChildren(): Collection|array
{
return $this->children;
}
/**
* Sets the parent resource.
*/
public function setParent(self $parent = null) : self
public function setParent(self $parent = null): self
{
$this->parent = $parent;
return $this;
}
/**
* Returns the parent resource.
*/
public function getParent() : ?\Chamilo\CoreBundle\Entity\ResourceNode
public function getParent(): ?self
{
return $this->parent;
}
/**
* Return the lvl value of the resource in the tree.
*/
public function getLevel() : int
public function getLevel(): int
{
return $this->level;
}
@ -247,26 +247,27 @@ class ResourceNode implements \Stringable
/**
* @return Collection|ResourceComment[]
*/
public function getComments() : \Doctrine\Common\Collections\Collection|array
public function getComments(): Collection|array
{
return $this->comments;
}
public function addComment(ResourceComment $comment) : self
public function addComment(ResourceComment $comment): self
{
$comment->setResourceNode($this);
$this->comments->add($comment);
return $this;
}
/**
* Returns the path cleaned from its ids.
* Eg.: "Root/subdir/file.txt".
*/
public function getPathForDisplay() : string
public function getPathForDisplay(): string
{
return $this->path;
//return $this->convertPathForDisplay($this->path);
}
public function getPathForDisplayToArray(?int $baseRoot = null) : array
public function getPathForDisplayToArray(?int $baseRoot = null): array
{
$parts = explode(self::PATH_SEPARATOR, $this->path);
$list = [];
@ -282,40 +283,45 @@ class ResourceNode implements \Stringable
}
$list[$id] = $value;
}
return $list;
}
public function getPathForDisplayRemoveBase(string $base) : string
public function getPathForDisplayRemoveBase(string $base): string
{
$path = str_replace($base, '', $this->path);
return $this->convertPathForDisplay($path);
}
public function getSlug() : string
public function getSlug(): string
{
return $this->slug;
}
public function getTitle() : string
public function getTitle(): string
{
return $this->title;
}
public function setTitle(string $title) : self
public function setTitle(string $title): self
{
$title = str_replace('/', '-', $title);
$this->title = $title;
return $this;
}
public function setSlug(string $slug) : self
public function setSlug(string $slug): self
{
if (str_contains(self::PATH_SEPARATOR, $slug)) {
$message = 'Invalid character "' . self::PATH_SEPARATOR . '" in resource name';
$message = 'Invalid character "'.self::PATH_SEPARATOR.'" in resource name';
throw new InvalidArgumentException($message);
}
$this->slug = $slug;
return $this;
}
/**
* Convert a path for display: remove ids.
*/
public function convertPathForDisplay(string $path) : string
public function convertPathForDisplay(string $path): string
{
/*$pathForDisplay = preg_replace(
'/-\d+'.self::PATH_SEPARATOR.'/',
@ -326,45 +332,49 @@ class ResourceNode implements \Stringable
$pathForDisplay = substr_replace($pathForDisplay, '', -3);
}
*/
$pathForDisplay = preg_replace('/-\\d+\\' . self::PATH_SEPARATOR . '/', '/', $path);
$pathForDisplay = preg_replace('/-\\d+\\'.self::PATH_SEPARATOR.'/', '/', $path);
if (null !== $pathForDisplay && '' !== $pathForDisplay) {
$pathForDisplay = substr_replace($pathForDisplay, '', -1);
}
return $pathForDisplay;
}
public function getResourceType() : ResourceType
public function getResourceType(): ResourceType
{
return $this->resourceType;
}
public function setResourceType(ResourceType $resourceType) : self
public function setResourceType(ResourceType $resourceType): self
{
$this->resourceType = $resourceType;
return $this;
}
public function getResourceLinks() : Collection
public function getResourceLinks(): Collection
{
return $this->resourceLinks;
}
public function addResourceLink(ResourceLink $link) : self
public function addResourceLink(ResourceLink $link): self
{
$link->setResourceNode($this);
$this->resourceLinks->add($link);
return $this;
}
public function setResourceLinks(Collection $resourceLinks) : self
public function setResourceLinks(Collection $resourceLinks): self
{
$this->resourceLinks = $resourceLinks;
return $this;
}
public function hasResourceFile() : bool
public function hasResourceFile(): bool
{
return null !== $this->resourceFile;
}
public function getResourceFile() : ?ResourceFile
public function getResourceFile(): ?ResourceFile
{
return $this->resourceFile;
}
public function hasEditableTextContent() : bool
public function hasEditableTextContent(): bool
{
if ($this->hasResourceFile()) {
$mimeType = $this->getResourceFile()->getMimeType();
@ -372,9 +382,10 @@ class ResourceNode implements \Stringable
return true;
}
}
return false;
}
public function isResourceFileAnImage() : bool
public function isResourceFileAnImage(): bool
{
if ($this->hasResourceFile()) {
$mimeType = $this->getResourceFile()->getMimeType();
@ -382,9 +393,10 @@ class ResourceNode implements \Stringable
return true;
}
}
return false;
}
public function isResourceFileAVideo() : bool
public function isResourceFileAVideo(): bool
{
if ($this->hasResourceFile()) {
$mimeType = $this->getResourceFile()->getMimeType();
@ -392,17 +404,19 @@ class ResourceNode implements \Stringable
return true;
}
}
return false;
}
public function setResourceFile(?ResourceFile $resourceFile = null) : self
public function setResourceFile(?ResourceFile $resourceFile = null): self
{
$this->resourceFile = $resourceFile;
if (null !== $resourceFile) {
$resourceFile->setResourceNode($this);
}
return $this;
}
public function getIcon() : string
public function getIcon(): string
{
$class = 'fa fa-folder';
if ($this->hasResourceFile()) {
@ -414,9 +428,10 @@ class ResourceNode implements \Stringable
$class = 'far fa-file-video';
}
}
return '<i class="' . $class . '"></i>';
return '<i class="'.$class.'"></i>';
}
public function getThumbnail(RouterInterface $router) : string
public function getThumbnail(RouterInterface $router): string
{
$size = 'fa-3x';
$class = sprintf('fa fa-folder %s', $size);
@ -424,41 +439,51 @@ class ResourceNode implements \Stringable
$class = sprintf('far fa-file %s', $size);
if ($this->isResourceFileAnImage()) {
$class = sprintf('far fa-file-image %s', $size);
$params = ['id' => $this->getId(), 'tool' => $this->getResourceType()->getTool(), 'type' => $this->getResourceType()->getName(), 'filter' => 'editor_thumbnail'];
$params = [
'id' => $this->getId(),
'tool' => $this->getResourceType()->getTool(),
'type' => $this->getResourceType()->getName(),
'filter' => 'editor_thumbnail',
];
$url = $router->generate('chamilo_core_resource_view', $params);
return sprintf("<img src='%s'/>", $url);
}
if ($this->isResourceFileAVideo()) {
$class = sprintf('far fa-file-video %s', $size);
}
}
return '<i class="' . $class . '"></i>';
return '<i class="'.$class.'"></i>';
}
public function getContent() : ?string
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content) : self
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getShortCut() : ?CShortcut
public function getShortCut(): ?CShortcut
{
return $this->shortCut;
}
public function setShortCut(?CShortcut $shortCut) : self
public function setShortCut(?CShortcut $shortCut): self
{
$this->shortCut = $shortCut;
return $this;
}
public function isPublic() : bool
public function isPublic(): bool
{
return $this->public;
}
public function setPublic(bool $public) : self
public function setPublic(bool $public): self
{
$this->public = $public;
return $this;
}
}

@ -7,10 +7,11 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
#[ORM\Table(name: 'resource_right')]
#[ORM\Entity]
class ResourceRight implements \Stringable
class ResourceRight implements Stringable
{
#[ORM\Id]
#[ORM\Column(type: 'bigint')]

@ -10,11 +10,12 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Stringable;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'resource_type')]
#[ORM\Entity]
class ResourceType implements \Stringable
class ResourceType implements Stringable
{
use TimestampableEntity;
@ -79,7 +80,7 @@ class ResourceType implements \Stringable
/**
* @return ResourceNode[]|Collection
*/
public function getResourceNodes(): array|\Doctrine\Common\Collections\Collection
public function getResourceNodes(): array|Collection
{
return $this->resourceNodes;
}
@ -87,7 +88,7 @@ class ResourceType implements \Stringable
/**
* @param ResourceNode[]|Collection $resourceNodes
*/
public function setResourceNodes(array|\Doctrine\Common\Collections\Collection $resourceNodes): self
public function setResourceNodes(array|Collection $resourceNodes): self
{
$this->resourceNodes = $resourceNodes;

@ -9,10 +9,11 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Fhaculty\Graph\Graph;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Stringable;
#[ORM\Table(name: 'sequence')]
#[ORM\Entity(repositoryClass: \Chamilo\CoreBundle\Repository\SequenceRepository::class)]
class Sequence implements \Stringable
class Sequence implements Stringable
{
use TimestampableEntity;

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceCondition.
*/
#[ORM\Table(name: 'sequence_condition')]
#[ORM\Entity]
class SequenceCondition

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceFormula.
*/
#[ORM\Table(name: 'sequence_formula')]
#[ORM\Entity]
class SequenceFormula

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceMethod.
*/
#[ORM\Table(name: 'sequence_method')]
#[ORM\Entity]
class SequenceMethod

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceResource.
*/
#[ORM\Table(name: 'sequence_resource')]
#[ORM\Entity(repositoryClass: \Chamilo\CoreBundle\Repository\SequenceResourceRepository::class)]
class SequenceResource

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceRowEntity.
*/
#[ORM\Table(name: 'sequence_row_entity')]
#[ORM\Entity]
class SequenceRowEntity

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceRule.
*/
#[ORM\Table(name: 'sequence_rule')]
#[ORM\Entity]
class SequenceRule

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceRuleCondition.
*/
#[ORM\Table(name: 'sequence_rule_condition')]
#[ORM\Entity]
class SequenceRuleCondition

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceRuleMethod.
*/
#[ORM\Table(name: 'sequence_rule_method')]
#[ORM\Entity]
class SequenceRuleMethod

@ -8,9 +8,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Class SequenceTypeEntity.
*/
#[ORM\Table(name: 'sequence_type_entity')]
#[ORM\Entity]
class SequenceTypeEntity

@ -10,9 +10,6 @@ use Chamilo\CoreBundle\Traits\UserTrait;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
/**
* Class Sequence.
*/
#[ORM\Table(name: 'sequence_value')]
#[ORM\Entity]
class SequenceValue

@ -9,9 +9,6 @@ namespace Chamilo\CoreBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class SequenceVariable.
*/
#[ORM\Table(name: 'sequence_variable')]
#[ORM\Entity]
class SequenceVariable

@ -1,21 +1,20 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Serializer\Filter\PropertyFilter;
use Chamilo\CoreBundle\Entity\Listener\SessionListener;
use Chamilo\CoreBundle\Repository\SessionRepository;
use DateTime;
@ -23,15 +22,17 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new Get(security: 'is_granted(\'ROLE_ADMIN\') or is_granted(\'VIEW\', object)'),
new Put(security: 'is_granted(\'ROLE_ADMIN\')'),
new GetCollection(security: 'is_granted(\'ROLE_ADMIN\')'),
new Post(security: 'is_granted(\'ROLE_ADMIN\')')
new Get(security: "is_granted('ROLE_ADMIN') or is_granted('VIEW', object)"),
new Put(security: "is_granted('ROLE_ADMIN')"),
new GetCollection(security: "is_granted('ROLE_ADMIN')"),
new Post(security: "is_granted('ROLE_ADMIN')"),
],
normalizationContext: ['groups' => ['session:read']],
denormalizationContext: ['groups' => ['session:write']],
@ -45,7 +46,7 @@ use Symfony\Component\Validator\Constraints as Assert;
#[ApiFilter(filterClass: SearchFilter::class, properties: ['name' => 'partial'])]
#[ApiFilter(filterClass: PropertyFilter::class)]
#[ApiFilter(filterClass: OrderFilter::class, properties: ['id', 'name'])]
class Session implements ResourceWithAccessUrlInterface, \Stringable
class Session implements ResourceWithAccessUrlInterface, Stringable
{
public const VISIBLE = 1;
public const READ_ONLY = 2;
@ -187,30 +188,32 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
$this->status = 0;
$this->position = 0;
}
public function __toString() : string
public function __toString(): string
{
return $this->getName();
}
public static function getRelationTypeList() : array
public static function getRelationTypeList(): array
{
return [self::STUDENT, self::DRH, self::COURSE_COACH, self::GENERAL_COACH, self::SESSION_ADMIN];
}
public function getDuration() : ?int
public function getDuration(): ?int
{
return $this->duration;
}
public function setDuration(int $duration) : self
public function setDuration(int $duration): self
{
$this->duration = $duration;
return $this;
}
public function getShowDescription() : bool
public function getShowDescription(): bool
{
return $this->showDescription;
}
public function setShowDescription(bool $showDescription) : self
public function setShowDescription(bool $showDescription): self
{
$this->showDescription = $showDescription;
return $this;
}
/**
@ -225,19 +228,20 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
/**
* @return Collection<int, SessionRelUser>
*/
public function getUsers() : Collection
public function getUsers(): Collection
{
return $this->users;
}
public function setUsers(Collection $users) : self
public function setUsers(Collection $users): self
{
$this->users = new ArrayCollection();
foreach ($users as $user) {
$this->addUserSubscription($user);
}
return $this;
}
public function addUserSubscription(SessionRelUser $subscription) : void
public function addUserSubscription(SessionRelUser $subscription): void
{
$subscription->setSession($this);
if (!$this->hasUser($subscription)) {
@ -245,37 +249,42 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
$this->nbrUsers++;
}
}
public function addUserInSession(int $relationType, User $user) : self
public function addUserInSession(int $relationType, User $user): self
{
$sessionRelUser = (new SessionRelUser())->setUser($user)->setRelationType($relationType);
$this->addUserSubscription($sessionRelUser);
return $this;
}
public function removeUserInSession(int $relationType, User $user) : self
public function removeUserInSession(int $relationType, User $user): self
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('relationType', $relationType))->andWhere(Criteria::expr()->eq('user', $user));
$subscriptions = $this->users->matching($criteria);
foreach ($subscriptions as $subscription) {
$this->removeUserSubscription($subscription);
}
return $this;
}
public function removeUserSubscription(SessionRelUser $subscription) : self
public function removeUserSubscription(SessionRelUser $subscription): self
{
if ($this->hasUser($subscription)) {
$subscription->setSession(null);
$this->users->removeElement($subscription);
$this->nbrUsers--;
}
return $this;
}
public function hasUser(SessionRelUser $subscription) : bool
public function hasUser(SessionRelUser $subscription): bool
{
if (0 !== $this->getUsers()->count()) {
$criteria = Criteria::create()->where(Criteria::expr()->eq('user', $subscription->getUser()))->andWhere(Criteria::expr()->eq('session', $subscription->getSession()))->andWhere(Criteria::expr()->eq('relationType', $subscription->getRelationType()));
$relation = $this->getUsers()->matching($criteria);
return $relation->count() > 0;
}
return false;
}
/**
@ -285,31 +294,33 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
{
return $this->courses;
}
public function setCourses(ArrayCollection $courses) : void
public function setCourses(ArrayCollection $courses): void
{
$this->courses = new ArrayCollection();
foreach ($courses as $course) {
$this->addCourses($course);
}
}
public function addCourses(SessionRelCourse $course) : void
public function addCourses(SessionRelCourse $course): void
{
$course->setSession($this);
$this->courses->add($course);
}
public function hasCourse(Course $course) : bool
public function hasCourse(Course $course): bool
{
if (0 !== $this->getCourses()->count()) {
$criteria = Criteria::create()->where(Criteria::expr()->eq('course', $course));
$relation = $this->getCourses()->matching($criteria);
return $relation->count() > 0;
}
return false;
}
/**
* Remove $course.
*/
public function removeCourses(SessionRelCourse $course) : void
public function removeCourses(SessionRelCourse $course): void
{
foreach ($this->courses as $key => $value) {
if ($value->getId() === $course->getId()) {
@ -321,7 +332,7 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
* Remove course subscription for a user.
* If user status in session is student, then decrease number of course users.
*/
public function removeUserCourseSubscription(User $user, Course $course) : void
public function removeUserCourseSubscription(User $user, Course $course): void
{
foreach ($this->sessionRelCourseRelUsers as $i => $sessionRelUser) {
if ($sessionRelUser->getCourse()->getId() === $course->getId() && $sessionRelUser->getUser()->getId() === $user->getId()) {
@ -337,214 +348,239 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
* @param int $status if not set it will check if the user is registered
* with any status
*/
public function hasUserInCourse(User $user, Course $course, int $status = null) : bool
public function hasUserInCourse(User $user, Course $course, int $status = null): bool
{
$relation = $this->getUserInCourse($user, $course, $status);
return $relation->count() > 0;
}
public function hasStudentInCourse(User $user, Course $course) : bool
public function hasStudentInCourse(User $user, Course $course): bool
{
return $this->hasUserInCourse($user, $course, self::STUDENT);
}
public function hasCourseCoachInCourse(User $user, Course $course = null) : bool
public function hasCourseCoachInCourse(User $user, Course $course = null): bool
{
if (null === $course) {
return false;
}
return $this->hasUserInCourse($user, $course, self::COURSE_COACH);
}
public function getUserInCourse(User $user, Course $course, ?int $status = null) : Collection
public function getUserInCourse(User $user, Course $course, ?int $status = null): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('course', $course))->andWhere(Criteria::expr()->eq('user', $user));
if (null !== $status) {
$criteria->andWhere(Criteria::expr()->eq('status', $status));
}
return $this->getSessionRelCourseRelUsers()->matching($criteria);
}
public function getAllUsersFromCourse(int $status) : Collection
public function getAllUsersFromCourse(int $status): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('status', $status));
return $this->getSessionRelCourseRelUsers()->matching($criteria);
}
public function getSessionRelCourseByUser(User $user, ?int $status = null) : Collection
public function getSessionRelCourseByUser(User $user, ?int $status = null): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('user', $user));
if (null !== $status) {
$criteria->andWhere(Criteria::expr()->eq('status', $status));
}
return $this->sessionRelCourseRelUsers->matching($criteria);
}
public function setName(string $name) : self
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getName() : string
public function getName(): string
{
return $this->name;
}
public function setDescription(string $description) : self
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getDescription() : ?string
public function getDescription(): ?string
{
return $this->description;
}
public function setNbrCourses(int $nbrCourses) : self
public function setNbrCourses(int $nbrCourses): self
{
$this->nbrCourses = $nbrCourses;
return $this;
}
public function getNbrCourses() : int
public function getNbrCourses(): int
{
return $this->nbrCourses;
}
public function setNbrUsers(int $nbrUsers) : self
public function setNbrUsers(int $nbrUsers): self
{
$this->nbrUsers = $nbrUsers;
return $this;
}
public function getNbrUsers() : int
public function getNbrUsers(): int
{
return $this->nbrUsers;
}
public function setNbrClasses(int $nbrClasses) : self
public function setNbrClasses(int $nbrClasses): self
{
$this->nbrClasses = $nbrClasses;
return $this;
}
public function getNbrClasses() : int
public function getNbrClasses(): int
{
return $this->nbrClasses;
}
public function setVisibility(int $visibility) : self
public function setVisibility(int $visibility): self
{
$this->visibility = $visibility;
return $this;
}
public function getVisibility() : int
public function getVisibility(): int
{
return $this->visibility;
}
public function getPromotion() : ?Promotion
public function getPromotion(): ?Promotion
{
return $this->promotion;
}
public function setPromotion(?Promotion $promotion) : self
public function setPromotion(?Promotion $promotion): self
{
$this->promotion = $promotion;
return $this;
}
public function setDisplayStartDate(?DateTime $displayStartDate) : self
public function setDisplayStartDate(?DateTime $displayStartDate): self
{
$this->displayStartDate = $displayStartDate;
return $this;
}
public function getDisplayStartDate() : ?DateTime
public function getDisplayStartDate(): ?DateTime
{
return $this->displayStartDate;
}
public function setDisplayEndDate(?DateTime $displayEndDate) : self
public function setDisplayEndDate(?DateTime $displayEndDate): self
{
$this->displayEndDate = $displayEndDate;
return $this;
}
public function getDisplayEndDate() : ?DateTime
public function getDisplayEndDate(): ?DateTime
{
return $this->displayEndDate;
}
public function setAccessStartDate(?DateTime $accessStartDate) : self
public function setAccessStartDate(?DateTime $accessStartDate): self
{
$this->accessStartDate = $accessStartDate;
return $this;
}
public function getAccessStartDate() : ?DateTime
public function getAccessStartDate(): ?DateTime
{
return $this->accessStartDate;
}
public function setAccessEndDate(?DateTime $accessEndDate) : self
public function setAccessEndDate(?DateTime $accessEndDate): self
{
$this->accessEndDate = $accessEndDate;
return $this;
}
public function getAccessEndDate() : ?DateTime
public function getAccessEndDate(): ?DateTime
{
return $this->accessEndDate;
}
public function setCoachAccessStartDate(?DateTime $coachAccessStartDate) : self
public function setCoachAccessStartDate(?DateTime $coachAccessStartDate): self
{
$this->coachAccessStartDate = $coachAccessStartDate;
return $this;
}
public function getCoachAccessStartDate() : ?DateTime
public function getCoachAccessStartDate(): ?DateTime
{
return $this->coachAccessStartDate;
}
public function setCoachAccessEndDate(?DateTime $coachAccessEndDate) : self
public function setCoachAccessEndDate(?DateTime $coachAccessEndDate): self
{
$this->coachAccessEndDate = $coachAccessEndDate;
return $this;
}
public function getCoachAccessEndDate() : ?DateTime
public function getCoachAccessEndDate(): ?DateTime
{
return $this->coachAccessEndDate;
}
public function getGeneralCoaches() : Collection
public function getGeneralCoaches(): Collection
{
return $this->getGeneralCoachesSubscriptions()->map(fn(SessionRelUser $subscription) => $subscription->getUser());
return $this->getGeneralCoachesSubscriptions()->map(fn (SessionRelUser $subscription) => $subscription->getUser());
}
public function getGeneralCoachesSubscriptions() : Collection
public function getGeneralCoachesSubscriptions(): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('relationType', self::GENERAL_COACH));
return $this->users->matching($criteria);
}
public function hasUserAsGeneralCoach(User $user) : bool
public function hasUserAsGeneralCoach(User $user): bool
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('relationType', self::GENERAL_COACH))->andWhere(Criteria::expr()->eq('user', $user));
return $this->users->matching($criteria)->count() > 0;
}
public function addGeneralCoach(User $coach) : self
public function addGeneralCoach(User $coach): self
{
return $this->addUserInSession(self::GENERAL_COACH, $coach);
}
public function removeGeneralCoach(User $user) : self
public function removeGeneralCoach(User $user): self
{
$this->removeUserInSession(self::GENERAL_COACH, $user);
return $this;
}
public function getCategory() : ?SessionCategory
public function getCategory(): ?SessionCategory
{
return $this->category;
}
public function setCategory(?SessionCategory $category) : self
public function setCategory(?SessionCategory $category): self
{
$this->category = $category;
return $this;
}
public static function getStatusList() : array
public static function getStatusList(): array
{
return [self::VISIBLE => 'status_visible', self::READ_ONLY => 'status_read_only', self::INVISIBLE => 'status_invisible', self::AVAILABLE => 'status_available'];
}
/**
* Check if session is visible.
*/
public function isActive() : bool
public function isActive(): bool
{
$now = new Datetime('now');
return $now > $this->getAccessStartDate();
}
public function isActiveForStudent() : bool
public function isActiveForStudent(): bool
{
$start = $this->getAccessStartDate();
$end = $this->getAccessEndDate();
return $this->compareDates($start, $end);
}
public function isActiveForCoach() : bool
public function isActiveForCoach(): bool
{
$start = $this->getCoachAccessStartDate();
$end = $this->getCoachAccessEndDate();
return $this->compareDates($start, $end);
}
/**
@ -553,15 +589,17 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
*
* @return bool whether now is between the session access start and end dates
*/
public function isCurrentlyAccessible() : bool
public function isCurrentlyAccessible(): bool
{
$now = new Datetime();
return (null === $this->accessStartDate || $this->accessStartDate < $now) && (null === $this->accessEndDate || $now < $this->accessEndDate);
}
public function addCourse(Course $course) : self
public function addCourse(Course $course): self
{
$sessionRelCourse = (new SessionRelCourse())->setCourse($course);
$this->addCourses($sessionRelCourse);
return $this;
}
/**
@ -571,41 +609,45 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
*
* @return bool whether the course was actually found in this session and removed from it
*/
public function removeCourse(Course $course) : bool
public function removeCourse(Course $course): bool
{
$relCourse = $this->getCourseSubscription($course);
if (null !== $relCourse) {
$this->courses->removeElement($relCourse);
$this->setNbrCourses(\count($this->courses));
return true;
}
return false;
}
/**
* @return SessionRelCourseRelUser[]|ArrayCollection|Collection
*/
public function getSessionRelCourseRelUsers() : array|\Doctrine\Common\Collections\ArrayCollection|\Doctrine\Common\Collections\Collection
public function getSessionRelCourseRelUsers(): array|ArrayCollection|Collection
{
return $this->sessionRelCourseRelUsers;
}
public function setSessionRelCourseRelUsers(Collection $sessionRelCourseRelUsers) : self
public function setSessionRelCourseRelUsers(Collection $sessionRelCourseRelUsers): self
{
$this->sessionRelCourseRelUsers = new ArrayCollection();
foreach ($sessionRelCourseRelUsers as $item) {
$this->addSessionRelCourseRelUser($item);
}
return $this;
}
public function addSessionRelCourseRelUser(SessionRelCourseRelUser $sessionRelCourseRelUser) : void
public function addSessionRelCourseRelUser(SessionRelCourseRelUser $sessionRelCourseRelUser): void
{
$sessionRelCourseRelUser->setSession($this);
if (!$this->hasUserCourseSubscription($sessionRelCourseRelUser)) {
$this->sessionRelCourseRelUsers->add($sessionRelCourseRelUser);
}
}
public function getCourseSubscription(Course $course) : ?SessionRelCourse
public function getCourseSubscription(Course $course): ?SessionRelCourse
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('course', $course));
return $this->courses->matching($criteria)->current();
}
/**
@ -613,7 +655,7 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
* If user status in session is student, then increase number of course users.
* Status example: Session::STUDENT.
*/
public function addUserInCourse(int $status, User $user, Course $course) : SessionRelCourseRelUser
public function addUserInCourse(int $status, User $user, Course $course): SessionRelCourseRelUser
{
$userRelCourseRelSession = (new SessionRelCourseRelUser())->setCourse($course)->setUser($user)->setSession($this)->setStatus($status);
$this->addSessionRelCourseRelUser($userRelCourseRelSession);
@ -621,42 +663,47 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
$sessionCourse = $this->getCourseSubscription($course);
$sessionCourse->setNbrUsers($sessionCourse->getNbrUsers() + 1);
}
return $userRelCourseRelSession;
}
public function hasUserCourseSubscription(SessionRelCourseRelUser $subscription) : bool
public function hasUserCourseSubscription(SessionRelCourseRelUser $subscription): bool
{
if (0 !== $this->getSessionRelCourseRelUsers()->count()) {
$criteria = Criteria::create()->where(Criteria::expr()->eq('user', $subscription->getUser()))->andWhere(Criteria::expr()->eq('course', $subscription->getCourse()))->andWhere(Criteria::expr()->eq('session', $subscription->getSession()));
$relation = $this->getSessionRelCourseRelUsers()->matching($criteria);
return $relation->count() > 0;
}
return false;
}
/**
* currentCourse is set in CourseListener.
*/
public function getCurrentCourse() : ?Course
public function getCurrentCourse(): ?Course
{
return $this->currentCourse;
}
/**
* currentCourse is set in CourseListener.
*/
public function setCurrentCourse(Course $course) : self
public function setCurrentCourse(Course $course): self
{
// If the session is registered in the course session list.
$exists = $this->getCourses()->exists(fn($key, $element) => $course->getId() === $element->getCourse()->getId());
$exists = $this->getCourses()->exists(fn ($key, $element) => $course->getId() === $element->getCourse()->getId());
if ($exists) {
$this->currentCourse = $course;
}
return $this;
}
public function setSendSubscriptionNotification(bool $sendNotification) : self
public function setSendSubscriptionNotification(bool $sendNotification): self
{
$this->sendSubscriptionNotification = $sendNotification;
return $this;
}
public function getSendSubscriptionNotification() : bool
public function getSendSubscriptionNotification(): bool
{
return $this->sendSubscriptionNotification;
}
@ -665,24 +712,27 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
*
* @return ArrayCollection|Collection
*/
public function getSessionRelCourseRelUsersByStatus(Course $course, int $status) : \Doctrine\Common\Collections\ArrayCollection|\Doctrine\Common\Collections\Collection
public function getSessionRelCourseRelUsersByStatus(Course $course, int $status): ArrayCollection|Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('course', $course))->andWhere(Criteria::expr()->eq('status', $status));
return $this->sessionRelCourseRelUsers->matching($criteria);
}
public function getIssuedSkills() : Collection
public function getIssuedSkills(): Collection
{
return $this->issuedSkills;
}
public function setCurrentUrl(AccessUrl $url) : self
public function setCurrentUrl(AccessUrl $url): self
{
$urlList = $this->getUrls();
foreach ($urlList as $item) {
if ($item->getUrl()->getId() === $url->getId()) {
$this->currentUrl = $url;
break;
}
}
return $this;
}
/**
@ -692,30 +742,33 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
{
return $this->currentUrl;
}
public function getUrls() : Collection
public function getUrls(): Collection
{
return $this->urls;
}
public function setUrls(Collection $urls) : self
public function setUrls(Collection $urls): self
{
$this->urls = new ArrayCollection();
foreach ($urls as $url) {
$this->addUrls($url);
}
return $this;
}
public function addAccessUrl(?AccessUrl $url) : self
public function addAccessUrl(?AccessUrl $url): self
{
$accessUrlRelSession = new AccessUrlRelSession();
$accessUrlRelSession->setUrl($url);
$accessUrlRelSession->setSession($this);
$this->addUrls($accessUrlRelSession);
return $this;
}
public function addUrls(AccessUrlRelSession $url) : self
public function addUrls(AccessUrlRelSession $url): self
{
$url->setSession($this);
$this->urls->add($url);
return $this;
}
/**
@ -725,77 +778,83 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
{
return $this->position;
}
public function setPosition(int $position) : self
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
public function getStatus() : int
public function getStatus(): int
{
return $this->status;
}
public function setStatus(int $status) : self
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getSessionAdmins() : Collection
public function getSessionAdmins(): Collection
{
return $this->getGeneralAdminsSubscriptions()->map(fn(SessionRelUser $subscription) => $subscription->getUser());
return $this->getGeneralAdminsSubscriptions()->map(fn (SessionRelUser $subscription) => $subscription->getUser());
}
public function getGeneralAdminsSubscriptions() : Collection
public function getGeneralAdminsSubscriptions(): Collection
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('relationType', self::SESSION_ADMIN));
return $this->users->matching($criteria);
}
public function hasUserAsSessionAdmin(User $user) : bool
public function hasUserAsSessionAdmin(User $user): bool
{
$criteria = Criteria::create()->where(Criteria::expr()->eq('relationType', self::SESSION_ADMIN))->andWhere(Criteria::expr()->eq('user', $user));
return $this->users->matching($criteria)->count() > 0;
}
public function addSessionAdmin(User $sessionAdmin) : self
public function addSessionAdmin(User $sessionAdmin): self
{
return $this->addUserInSession(self::SESSION_ADMIN, $sessionAdmin);
}
/**
* @return SkillRelCourse[]|Collection
*/
public function getSkills() : array|\Doctrine\Common\Collections\Collection
public function getSkills(): array|Collection
{
return $this->skills;
}
/**
* @return ResourceLink[]|Collection
*/
public function getResourceLinks() : array|\Doctrine\Common\Collections\Collection
public function getResourceLinks(): array|Collection
{
return $this->resourceLinks;
}
/**
* Check if $user is course coach in any course.
*/
public function hasCoachInCourseList(User $user) : bool
public function hasCoachInCourseList(User $user): bool
{
foreach ($this->courses as $sessionCourse) {
if ($this->hasCourseCoachInCourse($user, $sessionCourse->getCourse())) {
return true;
}
}
return false;
}
/**
* Check if $user is student in any course.
*/
public function hasStudentInCourseList(User $user) : bool
public function hasStudentInCourseList(User $user): bool
{
foreach ($this->courses as $sessionCourse) {
if ($this->hasStudentInCourse($user, $sessionCourse->getCourse())) {
return true;
}
}
return false;
}
protected function compareDates(DateTime $start, DateTime $end = null) : bool
protected function compareDates(DateTime $start, DateTime $end = null): bool
{
$now = new Datetime('now');
if (!empty($start) && !empty($end) && ($now >= $start && $now <= $end)) {
@ -804,6 +863,7 @@ class Session implements ResourceWithAccessUrlInterface, \Stringable
if (!empty($start) && $now >= $start) {
return true;
}
return !empty($end) && $now <= $end;
}
}

@ -1,30 +1,30 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiFilter;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(operations: [new Get(), new Put(), new Patch(), new Delete(), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(security: 'is_granted(\'ROLE_ADMIN\')')], security: 'is_granted(\'ROLE_USER\')', denormalizationContext: ['groups' => ['session_category:write']], normalizationContext: ['groups' => ['session_category:read']])]
#[ORM\Table(name: 'session_category')]
#[ORM\Entity]
class SessionCategory implements \Stringable
class SessionCategory implements Stringable
{
#[Groups(['session_category:read', 'session_rel_user:read'])]
#[ORM\Column(name: 'id', type: 'integer', nullable: false)]
@ -48,16 +48,17 @@ class SessionCategory implements \Stringable
{
$this->sessions = new ArrayCollection();
}
public function __toString() : string
public function __toString(): string
{
return $this->name;
}
public function setUrl(AccessUrl $url) : self
public function setUrl(AccessUrl $url): self
{
$this->url = $url;
return $this;
}
public function getUrl() : AccessUrl
public function getUrl(): AccessUrl
{
return $this->url;
}
@ -70,18 +71,20 @@ class SessionCategory implements \Stringable
{
return $this->id;
}
public function setName(string $name) : self
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getName() : string
public function getName(): string
{
return $this->name;
}
public function setDateStart(DateTime $dateStart) : self
public function setDateStart(DateTime $dateStart): self
{
$this->dateStart = $dateStart;
return $this;
}
/**
@ -93,9 +96,10 @@ class SessionCategory implements \Stringable
{
return $this->dateStart;
}
public function setDateEnd(DateTime $dateEnd) : self
public function setDateEnd(DateTime $dateEnd): self
{
$this->dateEnd = $dateEnd;
return $this;
}
/**

@ -1,21 +1,20 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiFilter;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* Course subscriptions to a session.
*/
@ -57,38 +56,41 @@ class SessionRelCourse
{
return $this->id;
}
public function setSession(Session $session) : self
public function setSession(Session $session): self
{
$this->session = $session;
return $this;
}
public function getCourse() : Course
public function getCourse(): Course
{
return $this->course;
}
public function setCourse(Course $course) : self
public function setCourse(Course $course): self
{
$this->course = $course;
return $this;
}
public function getSession() : Session
public function getSession(): Session
{
return $this->session;
}
public function setNbrUsers(int $nbrUsers) : self
public function setNbrUsers(int $nbrUsers): self
{
$this->nbrUsers = $nbrUsers;
return $this;
}
public function getNbrUsers() : int
public function getNbrUsers(): int
{
return $this->nbrUsers;
}
public function getPosition() : int
public function getPosition(): int
{
return $this->position;
}
public function setPosition(int $position) : void
public function setPosition(int $position): void
{
$this->position = $position;
}

@ -1,27 +1,21 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use Chamilo\CoreBundle\Traits\UserTrait;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\MaxDepth;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User subscriptions to a session course.
*/
@ -73,62 +67,68 @@ class SessionRelCourseRelUser
$this->legalAgreement = 0;
$this->status = Session::STUDENT;
}
public function getSession() : Session
public function getSession(): Session
{
return $this->session;
}
public function setSession(Session $session) : self
public function setSession(Session $session): self
{
$this->session = $session;
return $this;
}
public function getCourse() : Course
public function getCourse(): Course
{
return $this->course;
}
public function setCourse(Course $course) : self
public function setCourse(Course $course): self
{
$this->course = $course;
return $this;
}
public function getId() : ?int
public function getId(): ?int
{
return $this->id;
}
public function setVisibility(int $visibility) : self
public function setVisibility(int $visibility): self
{
$this->visibility = $visibility;
return $this;
}
public function getVisibility() : int
public function getVisibility(): int
{
return $this->visibility;
}
public function setStatus(int $status) : self
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getStatus() : int
public function getStatus(): int
{
return $this->status;
}
public function setLegalAgreement(int $legalAgreement) : self
public function setLegalAgreement(int $legalAgreement): self
{
$this->legalAgreement = $legalAgreement;
return $this;
}
public function getLegalAgreement() : int
public function getLegalAgreement(): int
{
return $this->legalAgreement;
}
public function getProgress() : int
public function getProgress(): int
{
return $this->progress;
}
public function setProgress(int $progress) : self
public function setProgress(int $progress): self
{
$this->progress = $progress;
return $this;
}
}

@ -1,19 +1,18 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use DateTime;
use DateTimeZone;
use Doctrine\Common\Collections\Collection;
@ -21,6 +20,7 @@ use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* User subscriptions to a session. See also SessionRelCourseRelUser.php for a more detail subscription by course.
*/
@ -73,35 +73,38 @@ class SessionRelUser
$this->movedStatus = null;
$this->registeredAt = new DateTime('now', new DateTimeZone('UTC'));
}
public function getCourses() : Collection
public function getCourses(): Collection
{
return $this->session->getSessionRelCourseByUser($this->getUser());
}
public function getId() : ?int
public function getId(): ?int
{
return $this->id;
}
public function setSession(?Session $session) : self
public function setSession(?Session $session): self
{
$this->session = $session;
return $this;
}
public function getSession() : ?Session
public function getSession(): ?Session
{
return $this->session;
}
public function setRelationType(int $relationType) : self
public function setRelationType(int $relationType): self
{
$this->relationType = $relationType;
return $this;
}
public function getRelationType() : int
public function getRelationType(): int
{
return $this->relationType;
}
public function setMovedTo(int $movedTo) : self
public function setMovedTo(int $movedTo): self
{
$this->movedTo = $movedTo;
return $this;
}
/**
@ -113,9 +116,10 @@ class SessionRelUser
{
return $this->movedTo;
}
public function setMovedStatus(int $movedStatus) : self
public function setMovedStatus(int $movedStatus): self
{
$this->movedStatus = $movedStatus;
return $this;
}
/**
@ -127,9 +131,10 @@ class SessionRelUser
{
return $this->movedStatus;
}
public function setMovedAt(DateTime $movedAt) : self
public function setMovedAt(DateTime $movedAt): self
{
$this->movedAt = $movedAt;
return $this;
}
/**
@ -141,9 +146,10 @@ class SessionRelUser
{
return $this->movedAt;
}
public function setRegisteredAt(DateTime $registeredAt) : self
public function setRegisteredAt(DateTime $registeredAt): self
{
$this->registeredAt = $registeredAt;
return $this;
}
/**
@ -162,19 +168,21 @@ class SessionRelUser
{
return $this->duration;
}
public function setDuration(int $duration) : self
public function setDuration(int $duration): self
{
$this->duration = $duration;
return $this;
}
public function getUser() : User
public function getUser(): User
{
return $this->user;
}
public function setUser(User $user) : self
public function setUser(User $user): self
{
$user->addSessionRelUser($this);
$this->user = $user;
return $this;
}
}

@ -1,31 +1,26 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\Get;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(security: 'is_granted(\'ROLE_ADMIN\')', normalizationContext: ['groups' => ['skill:read']])]
#[ORM\Table(name: 'skill')]
#[ORM\Entity(repositoryClass: \Chamilo\CoreBundle\Repository\SkillRepository::class)]
class Skill implements \Stringable
class Skill implements Stringable
{
public const STATUS_DISABLED = 0;
public const STATUS_ENABLED = 1;
@ -99,34 +94,37 @@ class Skill implements \Stringable
$this->description = '';
$this->status = self::STATUS_ENABLED;
}
public function __toString() : string
public function __toString(): string
{
return $this->getName();
}
public function setName(string $name) : self
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getName() : string
public function getName(): string
{
return $this->name;
}
public function getShortCode() : string
public function getShortCode(): string
{
return $this->shortCode;
}
public function setShortCode(string $shortCode) : self
public function setShortCode(string $shortCode): self
{
$this->shortCode = $shortCode;
return $this;
}
public function setDescription(string $description) : self
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getDescription() : string
public function getDescription(): string
{
return $this->description;
}
@ -138,6 +136,7 @@ class Skill implements \Stringable
public function setAccessUrlId(int $accessUrlId)
{
$this->accessUrlId = $accessUrlId;
return $this;
}
/**
@ -149,9 +148,10 @@ class Skill implements \Stringable
{
return $this->accessUrlId;
}
public function setIcon(string $icon) : self
public function setIcon(string $icon): self
{
$this->icon = $icon;
return $this;
}
/**
@ -163,9 +163,10 @@ class Skill implements \Stringable
{
return $this->icon;
}
public function setCriteria(string $criteria) : self
public function setCriteria(string $criteria): self
{
$this->criteria = $criteria;
return $this;
}
/**
@ -177,9 +178,10 @@ class Skill implements \Stringable
{
return $this->criteria;
}
public function setStatus(int $status) : self
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
/**
@ -201,6 +203,7 @@ class Skill implements \Stringable
public function setUpdatedAt(DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
@ -228,9 +231,10 @@ class Skill implements \Stringable
{
return $this->profile;
}
public function setProfile(Profile $profile) : self
public function setProfile(Profile $profile): self
{
$this->profile = $profile;
return $this;
}
/**
@ -249,12 +253,13 @@ class Skill implements \Stringable
{
return $this->items;
}
public function setItems(ArrayCollection $items) : self
public function setItems(ArrayCollection $items): self
{
$this->items = $items;
return $this;
}
public function hasItem(int $typeId, int $itemId) : bool
public function hasItem(int $typeId, int $itemId): bool
{
if (0 !== $this->getItems()->count()) {
$found = false;
@ -262,14 +267,17 @@ class Skill implements \Stringable
foreach ($this->getItems() as $item) {
if ($item->getItemId() === $itemId && $item->getItemType() === $typeId) {
$found = true;
break;
}
}
return $found;
}
return false;
}
public function addItem(SkillRelItem $skillRelItem) : void
public function addItem(SkillRelItem $skillRelItem): void
{
$skillRelItem->setSkill($this);
$this->items[] = $skillRelItem;
@ -281,55 +289,59 @@ class Skill implements \Stringable
{
return $this->courses;
}
public function setCourses(ArrayCollection $courses) : self
public function setCourses(ArrayCollection $courses): self
{
$this->courses = $courses;
return $this;
}
/**
* @return SkillRelSkill[]|Collection
*/
public function getSkills() : array|\Doctrine\Common\Collections\Collection
public function getSkills(): array|Collection
{
return $this->skills;
}
/**
* @param SkillRelSkill[]|Collection $skills
*/
public function setSkills(array|\Doctrine\Common\Collections\Collection $skills) : self
public function setSkills(array|Collection $skills): self
{
$this->skills = $skills;
return $this;
}
/**
* @return SkillRelGradebook[]|Collection
*/
public function getGradeBookCategories() : array|\Doctrine\Common\Collections\Collection
public function getGradeBookCategories(): array|Collection
{
return $this->gradeBookCategories;
}
/**
* @param SkillRelGradebook[]|Collection $gradeBookCategories
*/
public function setGradeBookCategories(array|\Doctrine\Common\Collections\Collection $gradeBookCategories) : self
public function setGradeBookCategories(array|Collection $gradeBookCategories): self
{
$this->gradeBookCategories = $gradeBookCategories;
return $this;
}
public function hasAsset() : bool
public function hasAsset(): bool
{
return null !== $this->asset;
}
public function getAsset() : ?Asset
public function getAsset(): ?Asset
{
return $this->asset;
}
public function setAsset(?Asset $asset) : self
public function setAsset(?Asset $asset): self
{
$this->asset = $asset;
return $this;
}
public function hasCourseAndSession(SkillRelCourse $searchItem) : bool
public function hasCourseAndSession(SkillRelCourse $searchItem): bool
{
if (0 !== $this->getCourses()->count()) {
$found = false;
@ -344,14 +356,17 @@ class Skill implements \Stringable
}
if ($item->getCourse()->getId() === $searchItem->getCourse()->getId() && $sessionPassFilter) {
$found = true;
break;
}
}
return $found;
}
return false;
}
public function addToCourse(SkillRelCourse $item) : void
public function addToCourse(SkillRelCourse $item): void
{
$item->setSkill($this);
$this->courses[] = $item;

@ -2,21 +2,19 @@
/* For licensing terms, see /license.txt */
declare (strict_types=1);
declare(strict_types=1);
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Core\Bridge\Doctrine\Common\Filter\SearchFilterInterface;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use Chamilo\CoreBundle\Controller\Api\DislikeSocialPostController;
use Chamilo\CoreBundle\Controller\Api\LikeSocialPostController;
use Chamilo\CoreBundle\Filter\SocialWallFilter;
@ -29,6 +27,7 @@ use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(operations: [new Get(security: 'is_granted(\'VIEW\', object)'), new Put(security: 'is_granted(\'EDIT\', object)'), new Delete(security: 'is_granted(\'DELETE\', object)'), new Post(uriTemplate: '/social_posts/{id}/like', controller: LikeSocialPostController::class, denormalizationContext: ['groups' => []], normalizationContext: ['groups' => ['social_post_feedback']], security: 'is_granted(\'ROLE_USER\')'), new Post(uriTemplate: '/social_posts/{id}/dislike', controller: DislikeSocialPostController::class, denormalizationContext: ['groups' => []], normalizationContext: ['groups' => ['social_post_feedback']], security: 'is_granted(\'ROLE_USER\')'), new GetCollection(security: 'is_granted(\'ROLE_USER\')'), new Post(securityPostDenormalize: 'is_granted(\'CREATE\', object)')], security: 'is_granted(\'ROLE_USER\')', denormalizationContext: ['groups' => ['social_post:write']], normalizationContext: ['groups' => ['social_post:read']])]
#[ORM\Table(name: 'social_post')]
#[ORM\Index(name: 'idx_social_post_sender', columns: ['sender_id'])]
@ -64,10 +63,10 @@ class SocialPost
#[ORM\Column(type: 'text')]
protected string $content;
#[Groups(['social_post:write', 'social_post:read'])]
#[Assert\Choice([SocialPost::TYPE_WALL_POST, SocialPost::TYPE_WALL_COMMENT, SocialPost::TYPE_GROUP_MESSAGE, SocialPost::TYPE_PROMOTED_MESSAGE], message: 'Choose a valid type.')]
#[Assert\Choice([self::TYPE_WALL_POST, self::TYPE_WALL_COMMENT, self::TYPE_GROUP_MESSAGE, self::TYPE_PROMOTED_MESSAGE], message: 'Choose a valid type.')]
#[ORM\Column(type: 'smallint')]
protected int $type;
#[Assert\Choice([SocialPost::STATUS_SENT, SocialPost::STATUS_DELETED], message: 'Choose a status.')]
#[Assert\Choice([self::STATUS_SENT, self::STATUS_DELETED], message: 'Choose a status.')]
#[ORM\Column(type: 'smallint')]
protected int $status;
#[Groups(['social_post:read'])]
@ -82,10 +81,10 @@ class SocialPost
#[ORM\ManyToOne(targetEntity: Usergroup::class)]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
protected ?Usergroup $groupReceiver = null;
#[ORM\OneToMany(targetEntity: SocialPost::class, mappedBy: 'parent')]
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
protected Collection $children;
#[Groups(['social_post:write'])]
#[ORM\ManyToOne(targetEntity: SocialPost::class, inversedBy: 'children')]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ?SocialPost $parent;
#[Groups(['social_post:read', 'social_post_feedback'])]
@ -107,145 +106,161 @@ class SocialPost
$this->countFeedbackLikes = 0;
$this->countFeedbackDislikes = 0;
}
public function getId() : int
public function getId(): int
{
return $this->id;
}
public function setId(int $id) : self
public function setId(int $id): self
{
$this->id = $id;
return $this;
}
public function getSender() : User
public function getSender(): User
{
return $this->sender;
}
public function setSender(User $sender) : self
public function setSender(User $sender): self
{
$this->sender = $sender;
return $this;
}
public function getUserReceiver() : ?User
public function getUserReceiver(): ?User
{
return $this->userReceiver;
}
public function setUserReceiver(?User $userReceiver) : self
public function setUserReceiver(?User $userReceiver): self
{
$this->userReceiver = $userReceiver;
return $this;
}
public function getStatus() : int
public function getStatus(): int
{
return $this->status;
}
public function setStatus(int $status) : self
public function setStatus(int $status): self
{
$this->status = $status;
return $this;
}
public function getSendDate() : DateTime
public function getSendDate(): DateTime
{
return $this->sendDate;
}
public function setSendDate(DateTime $sendDate) : self
public function setSendDate(DateTime $sendDate): self
{
$this->sendDate = $sendDate;
return $this;
}
public function getSubject() : ?string
public function getSubject(): ?string
{
return $this->subject;
}
public function setSubject(?string $subject) : self
public function setSubject(?string $subject): self
{
$this->subject = $subject;
return $this;
}
public function getContent() : string
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content) : self
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getUpdatedAt() : DateTime
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(DateTime $updatedAt) : self
public function setUpdatedAt(DateTime $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getFeedbacks() : Collection
public function getFeedbacks(): Collection
{
return $this->feedbacks;
}
public function setFeedbacks(Collection $feedbacks) : self
public function setFeedbacks(Collection $feedbacks): self
{
$this->feedbacks = $feedbacks;
return $this;
}
public function addFeedback(SocialPostFeedback $feedback) : self
public function addFeedback(SocialPostFeedback $feedback): self
{
if (!$this->feedbacks->contains($feedback)) {
$this->feedbacks[] = $feedback;
$feedback->setSocialPost($this);
}
return $this;
}
public function getCountFeedbackLikes() : int
public function getCountFeedbackLikes(): int
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('liked', true));
return $this->feedbacks->matching($criteria)->count();
}
public function getCountFeedbackDislikes() : int
public function getCountFeedbackDislikes(): int
{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('disliked', true));
return $this->feedbacks->matching($criteria)->count();
}
public function getParent() : ?self
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(self $parent = null) : self
public function setParent(self $parent = null): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, SocialPost>
*/
public function getChildren() : Collection
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child) : self
public function addChild(self $child): self
{
$this->children[] = $child;
$child->setParent($this);
return $this;
}
public function getGroupReceiver() : ?Usergroup
public function getGroupReceiver(): ?Usergroup
{
return $this->groupReceiver;
}
public function setGroupReceiver(?Usergroup $groupReceiver) : self
public function setGroupReceiver(?Usergroup $groupReceiver): self
{
$this->groupReceiver = $groupReceiver;
return $this;
}
public function getType() : int
public function getType(): int
{
return $this->type;
}
public function setType(int $type) : self
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
}

@ -46,7 +46,6 @@ class SysAnnouncement
/**
* An array of roles. Example: ROLE_USER, ROLE_TEACHER, ROLE_ADMIN.
*
*
* @var string[]
*/
#[ORM\Column(type: 'array')]

@ -32,6 +32,9 @@ class SystemTemplate
#[ORM\Column(name: 'content', type: 'text', nullable: false)]
protected string $content;
#[ORM\Column(name: 'language', type: 'string', length: 40, nullable: true)]
protected string $language;
public function __construct()
{
$this->comment = '';
@ -114,4 +117,22 @@ class SystemTemplate
{
return $this->id;
}
/**
* @return string
*/
public function getLanguage(): string
{
return $this->language;
}
/**
* @param string $language
*/
public function setLanguage(string $language): self
{
$this->language = $language;
return $this;
}
}

@ -8,10 +8,11 @@ namespace Chamilo\CoreBundle\Entity;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
#[ORM\Table(name: 'ticket_message_attachments')]
#[ORM\Entity]
class TicketMessageAttachment extends AbstractResource implements ResourceInterface, \Stringable
class TicketMessageAttachment extends AbstractResource implements ResourceInterface, Stringable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]

@ -10,6 +10,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
@ -18,7 +19,7 @@ use Symfony\Component\Validator\Constraints as Assert;
*/
#[ORM\Table(name: 'tool')]
#[ORM\Entity]
class Tool implements \Stringable
class Tool implements Stringable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]

@ -8,13 +8,14 @@ namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Security\Authorization\Voter\ResourceNodeVoter;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
/**
* ToolResourceRight.
*/
#[ORM\Table(name: 'tool_resource_right')]
#[ORM\Entity]
class ToolResourceRight implements \Stringable
class ToolResourceRight implements Stringable
{
#[ORM\Column(name: 'id', type: 'integer')]
#[ORM\Id]
@ -31,9 +32,6 @@ class ToolResourceRight implements \Stringable
#[ORM\JoinColumn(name: 'tool_id', referencedColumnName: 'id')]
protected ?Tool $tool = null;
/**
* @return string
*/
public function __toString(): string
{
return (string) $this->getMask();

@ -1,6 +1,6 @@
<?php
declare (strict_types=1);
declare(strict_types=1);
/* For licensing terms, see /license.txt */

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save