Work: Enable CStudentPublication and CStudentPublicationAssignment as API resource #4769

pull/4788/head
Angel Fernando Quiroz Campos 1 year ago
parent 31a3158c9c
commit 515e01836f
  1. 3
      src/CoreBundle/Entity/AbstractResource.php
  2. 24
      src/CourseBundle/Entity/CStudentPublication.php
  3. 11
      src/CourseBundle/Entity/CStudentPublicationAssignment.php

@ -82,6 +82,7 @@ abstract class AbstractResource
'resource_node:write',
'document:read',
'document:write',
'c_student_publication:write',
])]
public ?int $parentResourceNode = 0;
@ -100,7 +101,7 @@ abstract class AbstractResource
* Use when sending a request to Api platform.
* Temporal array that saves the resource link list that will be filled by CreateDocumentFileAction.php.
*/
#[Groups(['c_tool_intro:write', 'resource_node:write'])]
#[Groups(['c_tool_intro:write', 'resource_node:write', 'c_student_publication:write'])]
public array $resourceLinkList = [];
/**

@ -5,32 +5,45 @@ declare(strict_types=1);
namespace Chamilo\CourseBundle\Entity;
use ApiPlatform\Metadata\ApiResource;
use Chamilo\CoreBundle\Entity\AbstractResource;
use Chamilo\CoreBundle\Entity\ResourceInterface;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\State\CStudentPublicationStateProcessor;
use Chamilo\CourseBundle\Repository\CStudentPublicationRepository;
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;
#[ORM\Table(name: 'c_student_publication')]
#[ORM\Entity(repositoryClass: CStudentPublicationRepository::class)]
#[ApiResource(
normalizationContext: [
'groups' => ['student_publication:read'],
],
denormalizationContext: [
'groups' => ['c_student_publication:write'],
]
)]
class CStudentPublication extends AbstractResource implements ResourceInterface, Stringable
{
#[ORM\Column(name: 'iid', type: 'integer')]
#[ORM\Id]
#[ORM\GeneratedValue]
protected int $iid;
protected ?int $iid = null;
#[Assert\NotBlank]
#[ORM\Column(name: 'title', type: 'string', length: 255, nullable: false)]
#[Groups(['c_student_publication:write'])]
protected string $title;
#[ORM\Column(name: 'description', type: 'text', nullable: true)]
#[Groups(['c_student_publication:write'])]
protected ?string $description;
#[ORM\Column(name: 'author', type: 'string', length: 255, nullable: true)]
@ -60,6 +73,7 @@ class CStudentPublication extends AbstractResource implements ResourceInterface,
protected ?bool $viewProperties = null;
#[ORM\Column(name: 'qualification', type: 'float', precision: 6, scale: 2, nullable: false)]
#[Groups(['c_student_publication:write'])]
protected float $qualification;
#[ORM\Column(name: 'date_of_qualification', type: 'datetime', nullable: true)]
@ -85,7 +99,9 @@ class CStudentPublication extends AbstractResource implements ResourceInterface,
#[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id')]
protected User $user;
#[Groups(['c_student_publication:write'])]
#[ORM\OneToOne(mappedBy: 'publication', targetEntity: CStudentPublicationAssignment::class, cascade: ['persist'])]
#[Assert\Valid]
protected ?CStudentPublicationAssignment $assignment = null;
#[ORM\Column(name: 'qualificator_id', type: 'integer', nullable: false)]
@ -93,9 +109,11 @@ class CStudentPublication extends AbstractResource implements ResourceInterface,
#[Assert\NotBlank]
#[ORM\Column(name: 'weight', type: 'float', precision: 6, scale: 2, nullable: false)]
protected float $weight;
#[Groups(['c_student_publication:write'])]
protected float $weight = 0;
#[ORM\Column(name: 'allow_text_assignment', type: 'integer', nullable: false)]
#[Groups(['c_student_publication:write'])]
protected int $allowTextAssignment;
#[ORM\Column(name: 'contains_file', type: 'integer', nullable: false)]
@ -445,7 +463,7 @@ class CStudentPublication extends AbstractResource implements ResourceInterface,
return $this->getIid();
}
public function getIid(): int
public function getIid(): ?int
{
return $this->iid;
}

@ -9,6 +9,8 @@ use Chamilo\CourseBundle\Repository\CStudentPublicationAssignmentRepository;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Stringable;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: 'c_student_publication_assignment')]
#[ORM\Entity(repositoryClass: CStudentPublicationAssignmentRepository::class)]
@ -20,13 +22,16 @@ class CStudentPublicationAssignment implements Stringable
protected int $iid;
#[ORM\Column(name: 'expires_on', type: 'datetime', nullable: true)]
#[Groups(['c_student_publication:write'])]
protected ?DateTime $expiresOn = null;
#[ORM\Column(name: 'ends_on', type: 'datetime', nullable: true)]
#[Groups(['c_student_publication:write'])]
#[Assert\GreaterThanOrEqual(propertyPath: 'expiresOn')]
protected ?DateTime $endsOn = null;
#[ORM\Column(name: 'add_to_calendar', type: 'integer', nullable: false)]
protected int $eventCalendarId;
protected int $eventCalendarId = 0;
#[ORM\Column(name: 'enable_qualification', type: 'boolean', nullable: false)]
protected bool $enableQualification;
@ -50,7 +55,7 @@ class CStudentPublicationAssignment implements Stringable
return $this->expiresOn;
}
public function setExpiresOn(DateTime $expiresOn): self
public function setExpiresOn(?DateTime $expiresOn): self
{
$this->expiresOn = $expiresOn;
@ -62,7 +67,7 @@ class CStudentPublicationAssignment implements Stringable
return $this->endsOn;
}
public function setEndsOn(DateTime $endsOn): self
public function setEndsOn(?DateTime $endsOn): self
{
$this->endsOn = $endsOn;

Loading…
Cancel
Save