From 9be1d8b3df58a436a1148f4856e8e2af2699fb59 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Fri, 29 Jan 2021 09:38:21 +0100 Subject: [PATCH] Update entities - api platform --- config/packages/api_platform.yaml | 2 +- src/CoreBundle/Entity/Course.php | 24 +++++++------- src/CoreBundle/Entity/Session.php | 31 +++++++++++-------- src/CoreBundle/Entity/User.php | 8 +++-- .../Resources/config/repositories.yml | 4 +-- 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/config/packages/api_platform.yaml b/config/packages/api_platform.yaml index ef6e2a5fed..5b7c7f16b7 100644 --- a/config/packages/api_platform.yaml +++ b/config/packages/api_platform.yaml @@ -13,7 +13,7 @@ api_platform: json: mime_types: ['application/json'] html: - mime_types: ['text/html' ] + mime_types: ['text/html'] graphql: mime_types: ['application/graphql'] collection: diff --git a/src/CoreBundle/Entity/Course.php b/src/CoreBundle/Entity/Course.php index f8bd7db1e3..080124781b 100644 --- a/src/CoreBundle/Entity/Course.php +++ b/src/CoreBundle/Entity/Course.php @@ -57,17 +57,15 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith public const HIDDEN = 4; /** - * @var int - * * @Groups({"course:read", "course_rel_user:read"}) * @ORM\Column(name="id", type="integer", nullable=false, unique=false) * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ - protected $id; + protected int $id; /** - * @var string The course title + * The course title. * * @Assert\NotBlank(message="A Course requires a title") * @@ -75,10 +73,11 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith * * @ORM\Column(name="title", type="string", length=250, nullable=true, unique=false) */ - protected $title; + protected string $title; /** - * @var string + * The course code. + * * @Assert\NotBlank() * @ApiProperty(iri="http://schema.org/courseCode") * @Groups({"course:read", "course:write", "course_rel_user:read"}) @@ -91,7 +90,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith * ) * @ORM\Column(name="code", type="string", length=40, nullable=false, unique=true) */ - protected $code; + protected string $code; /** * @var CourseRelUser[]|ArrayCollection @@ -118,7 +117,10 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith /** * @var ArrayCollection|AccessUrlRelCourse[] * - * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourse", mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true) + * @ORM\OneToMany( + * targetEntity="Chamilo\CoreBundle\Entity\AccessUrlRelCourse", + * mappedBy="course", cascade={"persist", "remove"}, orphanRemoval=true + * ) */ protected $urls; @@ -221,11 +223,9 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith protected $courseLanguage; /** - * @var string - * * @ORM\Column(name="description", type="text", nullable=true, unique=false) */ - protected $description; + protected string $description; /** * @var ArrayCollection @@ -393,7 +393,7 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith $this->creationDate = new \DateTime(); $this->lastVisit = new \DateTime(); $this->lastEdit = new \DateTime(); - + $this->description = ''; $this->users = new ArrayCollection(); $this->urls = new ArrayCollection(); $this->tools = new ArrayCollection(); diff --git a/src/CoreBundle/Entity/Session.php b/src/CoreBundle/Entity/Session.php index 7a6fbb4290..05dbf2121d 100644 --- a/src/CoreBundle/Entity/Session.php +++ b/src/CoreBundle/Entity/Session.php @@ -22,6 +22,18 @@ use Symfony\Component\Validator\Constraints as Assert; * attributes={"security"="is_granted('ROLE_ADMIN')"}, * normalizationContext={"groups"={"session:read"}, "swagger_definition_name"="Read"}, * denormalizationContext={"groups"={"session:write"}}, + * collectionOperations={ + * "get" = { + * "denormalization_context"={ + * "groups"={"session:read"}, + * }, + * }, + * "post"={} + * }, + * itemOperations={ + * "get"={}, + * "put"={}, + * } * ) * * @ApiFilter(SearchFilter::class, properties={"name": "partial"}) @@ -57,7 +69,7 @@ class Session * @ORM\Id * @ORM\GeneratedValue() */ - protected $id; + protected int $id; /** * @var ArrayCollection|SkillRelCourse[] @@ -128,20 +140,18 @@ class Session protected $currentUrl; /** - * @var string * @Assert\NotBlank() * @Groups({"session:read", "session:write", "session_rel_course_rel_user:read"}) * @ORM\Column(name="name", type="string", length=150, nullable=false, unique=false) */ - protected $name; + protected string $name; /** - * @var string * @Groups({"session:read", "session:write"}) * * @ORM\Column(name="description", type="text", nullable=true, unique=false) */ - protected $description; + protected string $description; /** * @var bool @@ -302,6 +312,7 @@ class Session $this->items = new ArrayCollection(); $this->urls = new ArrayCollection(); + $this->description = ''; $this->nbrClasses = 0; $this->nbrUsers = 0; $this->sendSubscriptionNotification = false; @@ -630,12 +641,8 @@ class Session /** * Set description. - * - * @param string $description - * - * @return $this */ - public function setDescription($description) + public function setDescription(string $description): self { $this->description = $description; @@ -644,10 +651,8 @@ class Session /** * Get description. - * - * @return string */ - public function getDescription() + public function getDescription(): string { return $this->description; } diff --git a/src/CoreBundle/Entity/User.php b/src/CoreBundle/Entity/User.php index 1782cc2de6..5a50ce31bd 100644 --- a/src/CoreBundle/Entity/User.php +++ b/src/CoreBundle/Entity/User.php @@ -32,11 +32,13 @@ use Symfony\Component\Validator\Mapping\ClassMetadata; * iri="http://schema.org/Person", * normalizationContext={"groups"={"user:read"}}, * denormalizationContext={"groups"={"user:write"}}, - * collectionOperations={"get"}, + * collectionOperations={ + * "get"={}, + * "post"={} + * }, * itemOperations={ * "get"={}, * "put"={}, - * "delete"={}, * } * ) * @@ -266,7 +268,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso /** * @var CourseRelUser[]|ArrayCollection * - * @ApiSubresource() + * @ApiSubresource * @ORM\OneToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseRelUser", mappedBy="user", orphanRemoval=true) */ protected $courses; diff --git a/src/CoreBundle/Resources/config/repositories.yml b/src/CoreBundle/Resources/config/repositories.yml index 06d9312e83..e427f454cd 100644 --- a/src/CoreBundle/Resources/config/repositories.yml +++ b/src/CoreBundle/Resources/config/repositories.yml @@ -28,8 +28,8 @@ services: Chamilo\CoreBundle\Repository\Node\UserRepository: calls: - setEncoder: ['@security.user_password_encoder.generic'] - - setAuthorizationChecker: [ '@security.authorization_checker'] + - setAuthorizationChecker: ['@security.authorization_checker'] - setRouter: ['@router'] - setSlugify: ['@cocur_slugify'] - setToolChain: ['@Chamilo\CoreBundle\ToolChain'] - - setResourceNodeRepository: [ '@Chamilo\CoreBundle\Repository\ResourceNodeRepository'] + - setResourceNodeRepository: ['@Chamilo\CoreBundle\Repository\ResourceNodeRepository']