src/Entity/Submission.php line 10

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubmissionRepository;
  4. use Doctrine\DBAL\Types\Types;
  5. use Doctrine\ORM\Mapping as ORM;
  6. #[ORM\Entity(repositoryClassSubmissionRepository::class)]
  7. class Submission
  8. {
  9.     #[ORM\Id]
  10.     #[ORM\GeneratedValue]
  11.     #[ORM\Column]
  12.     private ?int $id null;
  13.     #[ORM\ManyToOne(inversedBy'submissions')]
  14.     #[ORM\JoinColumn(nullablefalse)]
  15.     private ?User $user null;
  16.     #[ORM\ManyToOne(inversedBy'submissions')]
  17.     #[ORM\JoinColumn(nullablefalse)]
  18.     private ?Activity $activity null;
  19.     #[ORM\ManyToOne(inversedBy'submissions')]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private ?Season $season null;
  22.     #[ORM\Column(length255nullabletrue)]
  23.     private ?string $evidenceUrl null;
  24.     #[ORM\Column(length50)]
  25.     private ?string $status null;
  26.     #[ORM\Column]
  27.     private ?int $pointsAwarded null;
  28.     #[ORM\Column]
  29.     private ?\DateTimeImmutable $submittedAt null;
  30.     #[ORM\Column(nullabletrue)]
  31.     private ?\DateTimeImmutable $approvedAt null;
  32.     #[ORM\ManyToOne]
  33.     private ?User $approvedBy null;
  34.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  35.     private ?array $activityData null;
  36.     #[ORM\Column]
  37.     private ?bool $teamSubmission false;
  38.     #[ORM\Column(typeTypes::JSONnullabletrue)]
  39.     private ?array $teamMembers null;
  40.     public function __construct()
  41.     {
  42.         $this->submittedAt = new \DateTimeImmutable();
  43.         $this->status 'pending';
  44.         $this->pointsAwarded 0;
  45.     }
  46.     public function getId(): ?int
  47.     {
  48.         return $this->id;
  49.     }
  50.     public function getUser(): ?User
  51.     {
  52.         return $this->user;
  53.     }
  54.     public function setUser(?User $user): static
  55.     {
  56.         $this->user $user;
  57.         return $this;
  58.     }
  59.     public function getActivity(): ?Activity
  60.     {
  61.         return $this->activity;
  62.     }
  63.     public function setActivity(?Activity $activity): static
  64.     {
  65.         $this->activity $activity;
  66.         return $this;
  67.     }
  68.     public function getSeason(): ?Season
  69.     {
  70.         return $this->season;
  71.     }
  72.     public function setSeason(?Season $season): static
  73.     {
  74.         $this->season $season;
  75.         return $this;
  76.     }
  77.     public function getEvidenceUrl(): ?string
  78.     {
  79.         return $this->evidenceUrl;
  80.     }
  81.     public function setEvidenceUrl(?string $evidenceUrl): static
  82.     {
  83.         $this->evidenceUrl $evidenceUrl;
  84.         return $this;
  85.     }
  86.     public function getStatus(): ?string
  87.     {
  88.         return $this->status;
  89.     }
  90.     public function setStatus(string $status): static
  91.     {
  92.         $this->status $status;
  93.         return $this;
  94.     }
  95.     public function getPointsAwarded(): ?int
  96.     {
  97.         return $this->pointsAwarded;
  98.     }
  99.     public function setPointsAwarded(int $pointsAwarded): static
  100.     {
  101.         $this->pointsAwarded $pointsAwarded;
  102.         return $this;
  103.     }
  104.     public function getSubmittedAt(): ?\DateTimeImmutable
  105.     {
  106.         return $this->submittedAt;
  107.     }
  108.     public function setSubmittedAt(\DateTimeImmutable $submittedAt): static
  109.     {
  110.         $this->submittedAt $submittedAt;
  111.         return $this;
  112.     }
  113.     public function getApprovedAt(): ?\DateTimeImmutable
  114.     {
  115.         return $this->approvedAt;
  116.     }
  117.     public function setApprovedAt(?\DateTimeImmutable $approvedAt): static
  118.     {
  119.         $this->approvedAt $approvedAt;
  120.         return $this;
  121.     }
  122.     public function getApprovedBy(): ?User
  123.     {
  124.         return $this->approvedBy;
  125.     }
  126.     public function setApprovedBy(?User $approvedBy): static
  127.     {
  128.         $this->approvedBy $approvedBy;
  129.         return $this;
  130.     }
  131.     /**
  132.      * Check if the submission is pending
  133.      */
  134.     public function isPending(): bool
  135.     {
  136.         return $this->status === 'pending';
  137.     }
  138.     /**
  139.      * Check if the submission is approved
  140.      */
  141.     public function isApproved(): bool
  142.     {
  143.         return $this->status === 'approved';
  144.     }
  145.     /**
  146.      * Check if the submission is rejected
  147.      */
  148.     public function isRejected(): bool
  149.     {
  150.         return $this->status === 'rejected';
  151.     }
  152.     /**
  153.      * Approve the submission
  154.      */
  155.     public function approve(User $approverint $points null): static
  156.     {
  157.         $this->status 'approved';
  158.         $this->approvedAt = new \DateTimeImmutable();
  159.         $this->approvedBy $approver;
  160.         
  161.         if ($points !== null) {
  162.             $this->pointsAwarded $points;
  163.         } else {
  164.             $this->pointsAwarded $this->activity->getPoints();
  165.         }
  166.         return $this;
  167.     }
  168.     /**
  169.      * Reject the submission
  170.      */
  171.     public function reject(User $approver): static
  172.     {
  173.         $this->status 'rejected';
  174.         $this->approvedAt = new \DateTimeImmutable();
  175.         $this->approvedBy $approver;
  176.         $this->pointsAwarded 0;
  177.         return $this;
  178.     }
  179.     public function getActivityData(): ?array
  180.     {
  181.         return $this->activityData;
  182.     }
  183.     public function setActivityData(?array $activityData): static
  184.     {
  185.         $this->activityData $activityData;
  186.         return $this;
  187.     }
  188.     public function isTeamSubmission(): ?bool
  189.     {
  190.         return $this->teamSubmission;
  191.     }
  192.     public function setTeamSubmission(bool $teamSubmission): static
  193.     {
  194.         $this->teamSubmission $teamSubmission;
  195.         return $this;
  196.     }
  197.     public function getTeamMembers(): ?array
  198.     {
  199.         return $this->teamMembers;
  200.     }
  201.     public function setTeamMembers(?array $teamMembers): static
  202.     {
  203.         $this->teamMembers $teamMembers;
  204.         return $this;
  205.     }
  206.     /**
  207.      * Get specific activity data value
  208.      */
  209.     public function getActivityDataValue(string $key$default null)
  210.     {
  211.         if ($this->activityData === null || !isset($this->activityData[$key])) {
  212.             return $default;
  213.         }
  214.         return $this->activityData[$key];
  215.     }
  216.     /**
  217.      * Set specific activity data value
  218.      */
  219.     public function setActivityDataValue(string $key$value): static
  220.     {
  221.         if ($this->activityData === null) {
  222.             $this->activityData = [];
  223.         }
  224.         $this->activityData[$key] = $value;
  225.         return $this;
  226.     }
  227.     /**
  228.      * Add a team member to the submission
  229.      */
  230.     public function addTeamMember(User $user): static
  231.     {
  232.         if ($this->teamMembers === null) {
  233.             $this->teamMembers = [];
  234.         }
  235.         if (!in_array($user->getId(), $this->teamMembers)) {
  236.             $this->teamMembers[] = $user->getId();
  237.         }
  238.         return $this;
  239.     }
  240.     /**
  241.      * Remove a team member from the submission
  242.      */
  243.     public function removeTeamMember(User $user): static
  244.     {
  245.         if ($this->teamMembers === null) {
  246.             return $this;
  247.         }
  248.         $key array_search($user->getId(), $this->teamMembers);
  249.         if ($key !== false) {
  250.             unset($this->teamMembers[$key]);
  251.             $this->teamMembers array_values($this->teamMembers);
  252.         }
  253.         return $this;
  254.     }
  255.     /**
  256.      * Check if a user is a team member in this submission
  257.      */
  258.     public function isTeamMember(User $user): bool
  259.     {
  260.         if ($this->teamMembers === null) {
  261.             return false;
  262.         }
  263.         return in_array($user->getId(), $this->teamMembers);
  264.     }
  265.     /**
  266.      * Get the display name for the activity, including passport item if applicable
  267.      */
  268.     public function getActivityDisplayName(): string
  269.     {
  270.         $activityName $this->activity $this->activity->getName() : 'Unknown Activity';
  271.         // Check if this is a passport activity with a selected item
  272.         $validationSchema $this->activity $this->activity->getValidationSchema() : null;
  273.         if ($validationSchema &&
  274.             isset($validationSchema['type']) &&
  275.             $validationSchema['type'] === 'passport' &&
  276.             $this->activityData &&
  277.             isset($this->activityData['selectedItem'])) {
  278.             return $activityName ' (' $this->activityData['selectedItem'] . ')';
  279.         }
  280.         return $activityName;
  281.     }
  282. }