src/Entity/Plan.php line 14

  1. <?php
  2. namespace App\Entity;
  3. use App\Enum\RuleType;
  4. use App\Repository\PlanRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. #[ORM\Entity(repositoryClassPlanRepository::class)]
  11. class Plan
  12. {
  13.     use TimestampableEntity;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     private ?int $id null;
  18.     #[ORM\Column(length255)]
  19.     private ?string $name null;
  20.     #[ORM\Column(length255nullabletrue)]
  21.     private ?string $description null;
  22.     #[ORM\ManyToOne(inversedBy'plans'fetch'EAGER')]
  23.     private ?Period $period null;
  24.     #[ORM\ManyToMany(targetEntityRule::class, inversedBy'plans')]
  25.     private Collection $rules;
  26.     #[ORM\OneToMany(mappedBy'plan'targetEntityPlanAssignment::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  27.     private Collection $planAssignments;
  28. /*    #[ORM\ManyToMany(targetEntity: Rule::class)]
  29.     private Collection $creditRules;
  30.     #[ORM\ManyToMany(targetEntity: Rule::class)]
  31.     private Collection $commissionRules;*/
  32.     public function __construct()
  33.     {
  34.         $this->rules = new ArrayCollection();
  35.         $this->creditRules = new ArrayCollection();
  36.         $this->commissionRules = new ArrayCollection();
  37.         $this->planAssignments = new ArrayCollection();
  38.     }
  39.     public function getId(): ?int
  40.     {
  41.         return $this->id;
  42.     }
  43.     public function getName(): ?string
  44.     {
  45.         return $this->name;
  46.     }
  47.     public function setName(string $name): self
  48.     {
  49.         $this->name $name;
  50.         return $this;
  51.     }
  52.     public function getDescription(): ?string
  53.     {
  54.         return $this->description;
  55.     }
  56.     public function setDescription(?string $description): self
  57.     {
  58.         $this->description $description;
  59.         return $this;
  60.     }
  61.     public function getPeriod(): ?Period
  62.     {
  63.         return $this->period;
  64.     }
  65.     public function setPeriod(?Period $period): self
  66.     {
  67.         $this->period $period;
  68.         return $this;
  69.     }
  70.     /**
  71.      * @return Collection<int, Rule>
  72.      */
  73.     public function getRules(): Collection
  74.     {
  75.         return $this->rules;
  76.     }
  77.     public function addRule(Rule $rule): static
  78.     {
  79.         if (!$this->rules->contains($rule)) {
  80.             $this->rules->add($rule);
  81.         }
  82.         return $this;
  83.     }
  84.     public function removeRule(Rule $rule): static
  85.     {
  86.         $this->rules->removeElement($rule);
  87.         return $this;
  88.     }
  89.     /**
  90.      * @return Collection<int, Rule>
  91.      */
  92.     public function getCreditRules(): Collection
  93.     {
  94.         return $this->rules->filter(function (Rule $rule) {
  95.             return in_array($rule->getType(), [RuleType::DIRECT_RULERuleType::INDIRECT_RULE]);
  96.         });
  97.     }
  98.     /**
  99.      * @return Collection<int, Rule>
  100.      */
  101.     public function getDirectCreditRules(): Collection
  102.     {
  103.         return $this->rules->filter(function (Rule $rule) {
  104.             return $rule->getType() == RuleType::DIRECT_RULE;
  105.         });
  106.     }
  107.     /**
  108.      * @return Collection<int, Rule>
  109.      */
  110.     public function getInDirectCreditRules(): Collection
  111.     {
  112.         return $this->rules->filter(function (Rule $rule) {
  113.             return $rule->getType() == RuleType::INDIRECT_RULE;
  114.         });
  115.     }
  116.     /**
  117.      * @return Collection<int, Rule>
  118.      */
  119.     public function getCommissionRules(): Collection
  120.     {
  121.         return $this->rules->filter(function (Rule $rule) {
  122.             return $rule->getType() == RuleType::COMMISSION_RULE;
  123.         });
  124.     }
  125.     public function addCreditRule(Rule $rule): static
  126.     {
  127.         if (!$this->rules->contains($rule)) {
  128.             $this->rules->add($rule);
  129.         }
  130.         return $this;
  131.     }
  132.     public function removeCreditRule(Rule $rule): static
  133.     {
  134.         $this->rules->removeElement($rule);
  135.         return $this;
  136.     }
  137.     /*public function getCommissionRules(): Collection
  138.     {
  139.         return $this->rules;
  140.     }*/
  141.     public function addCommissionRule(Rule $rule): static
  142.     {
  143.         if (!$this->rules->contains($rule)) {
  144.             $this->rules->add($rule);
  145.         }
  146.         return $this;
  147.     }
  148.     public function removeCommissionRule(Rule $rule): static
  149.     {
  150.         $this->rules->removeElement($rule);
  151.         return $this;
  152.     }
  153.     public function __toString()
  154.     {
  155.         return $this->name;
  156.     }
  157.     /**
  158.      * @return Collection<int, PlanAssignment>
  159.      */
  160.     public function getPlanAssignments(): Collection
  161.     {
  162.         return $this->planAssignments;
  163.     }
  164.     public function addPlanAssignment(PlanAssignment $planAssignment): static
  165.     {
  166.         if (!$this->planAssignments->contains($planAssignment)) {
  167.             $this->planAssignments->add($planAssignment);
  168.             $planAssignment->setPlan($this);
  169.         }
  170.         return $this;
  171.     }
  172.     public function removePlanAssignment(PlanAssignment $planAssignment): static
  173.     {
  174.         if ($this->planAssignments->removeElement($planAssignment)) {
  175.             // set the owning side to null (unless already changed)
  176.             if ($planAssignment->getPlan() === $this) {
  177.                 $planAssignment->setPlan(null);
  178.             }
  179.         }
  180.         return $this;
  181.     }
  182. }