Add @groups to parse properties when serializing from entity to json

pull/3890/head
Julio Montoya 4 years ago
parent 8124555ae3
commit 891befedc9
  1. 4
      src/CoreBundle/Entity/Course.php
  2. 3
      src/CoreBundle/Entity/Tool.php
  3. 18
      src/CoreBundle/Entity/User.php
  4. 5
      src/CourseBundle/Entity/CShortcut.php
  5. 9
      src/CourseBundle/Entity/CTool.php

@ -227,13 +227,15 @@ class Course extends AbstractResource implements ResourceInterface, ResourceWith
protected string $courseLanguage;
/**
* @Groups({"course:read", "course_rel_user:read"})
*
* @ORM\Column(name="description", type="text", nullable=true, unique=false)
*/
protected ?string $description;
/**
* @ApiSubresource()
* @Groups({"course:read", "course:write"})
* @Groups({"course:read", "course:write", "course_rel_user:read"})
* @ORM\ManyToMany(targetEntity="Chamilo\CoreBundle\Entity\CourseCategory", inversedBy="courses")
* @ORM\JoinTable(
* name="course_rel_category",

@ -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 Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -28,6 +29,8 @@ class Tool
protected int $id;
/**
* @Groups({"tool:read"})
*
* @Assert\NotBlank()
* @ORM\Column(name="name", type="string", nullable=false, unique=true)
*/

@ -75,7 +75,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
public const ANONYMOUS = 6;
/**
* @Groups({"user:read", "resource_node:read"})
* @Groups({"user:read", "resource_node:read", "user_json:read"})
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue()
@ -90,13 +90,13 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
/**
* @Assert\NotBlank()
* @ApiProperty(iri="http://schema.org/name")
* @Groups({"user:read", "user:write", "resource_node:read"})
* @Groups({"user:read", "user:write", "resource_node:read", "user_json:read"})
* @ORM\Column(name="firstname", type="string", length=64, nullable=true)
*/
protected ?string $firstname = null;
/**
* @Groups({"user:read", "user:write", "resource_node:read"})
* @Groups({"user:read", "user:write", "resource_node:read", "user_json:read"})
* @ORM\Column(name="lastname", type="string", length=64, nullable=true)
*/
protected ?string $lastname = null;
@ -114,13 +114,13 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
protected ?string $biography;
/**
* @Groups({"user:read", "user:write"})
* @Groups({"user:read", "user:write", "user_json:read"})
* @ORM\Column(name="locale", type="string", length=8)
*/
protected string $locale;
/**
* @Groups({"user:read", "user:write", "course:read", "resource_node:read"})
* @Groups({"user:read", "user:write", "course:read", "resource_node:read", "user_json:read"})
* @Assert\NotBlank()
* @ORM\Column(name="username", type="string", length=100, unique=true)
*/
@ -139,7 +139,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
protected string $usernameCanonical;
/**
* @Groups({"user:read", "user:write"})
* @Groups({"user:read", "user:write", "user_json:read"})
* @ORM\Column(name="timezone", type="string", length=64)
*/
protected string $timezone;
@ -150,7 +150,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
protected string $emailCanonical;
/**
* @Groups({"user:read", "user:write"})
* @Groups({"user:read", "user:write", "user_json:read"})
* @Assert\NotBlank()
* @Assert\Email()
*
@ -266,7 +266,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
protected Collection $dropBoxSentFiles;
/**
* @Groups({"user:read", "user:write"})
* @Groups({"user:read", "user:write", "user_json:read"})
* @ORM\Column(type="array")
*
* @var mixed[]|string[]
@ -325,6 +325,8 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
protected Collection $sessionsAsGeneralCoach;
/**
* @Groups({"user_json:read"})
*
* @ORM\OneToOne(
* targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", cascade={"remove"}, orphanRemoval=true
* )

@ -10,6 +10,7 @@ use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -19,6 +20,8 @@ use Symfony\Component\Validator\Constraints as Assert;
class CShortcut extends AbstractResource implements ResourceInterface
{
/**
* @Groups({"cshortcut:read"})
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
@ -26,6 +29,8 @@ class CShortcut extends AbstractResource implements ResourceInterface
protected int $id;
/**
* @Groups({"cshortcut:read"})
*
* @Assert\NotBlank
*
* @ORM\Column(name="name", type="string", length=255, nullable=false)

@ -15,6 +15,7 @@ use Chamilo\CourseBundle\Traits\ShowCourseResourcesInSessionTrait;
use Doctrine\ORM\Event\LifecycleEventArgs;
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;
/**
@ -35,6 +36,8 @@ class CTool extends AbstractResource implements ResourceInterface
use ShowCourseResourcesInSessionTrait;
/**
* @Groups({"ctool:read"})
*
* @ORM\Column(name="iid", type="integer")
* @ORM\Id
* @ORM\GeneratedValue
@ -44,11 +47,15 @@ class CTool extends AbstractResource implements ResourceInterface
/**
* @Assert\NotBlank
*
* @Groups({"ctool:read"})
*
* @ORM\Column(name="name", type="text", nullable=false)
*/
protected string $name;
/**
* @Groups({"ctool:read"})
*
* @ORM\Column(name="visibility", type="boolean", nullable=true)
*/
protected ?bool $visibility = null;
@ -66,6 +73,8 @@ class CTool extends AbstractResource implements ResourceInterface
protected ?Session $session = null;
/**
* @Groups({"ctool:read"})
*
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool")
* @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false)
*/

Loading…
Cancel
Save