src/Entity/Administrator.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use DateTime;
  4. use App\Entity\Enum\BusinessModelEnum;
  5. use DateTimeInterface;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. /**
  11.  * Fichier
  12.  *
  13.  * @ORM\Table(name="administrator")
  14.  * @ORM\Entity(repositoryClass="App\Repository\AdministratorRepository")
  15.  *
  16.  * @ORM\InheritanceType("SINGLE_TABLE")
  17.  * @ORM\DiscriminatorMap(
  18.  *    {
  19.  *        "freelancer" = "App\Entity\Freelancer",
  20.  *      "partner" = "App\Entity\Partner",
  21.  * })
  22.  */
  23. abstract class Administrator
  24. {
  25.     /**
  26.      * @ORM\Id()
  27.      * @ORM\GeneratedValue()
  28.      * @ORM\Column(type="integer")
  29.      */
  30.     protected $id;
  31.     /**
  32.      * @ORM\Column(type="string", length=255)
  33.      */
  34.     private $name;
  35.     /**
  36.      * @ORM\OneToOne(targetEntity="App\Entity\User", inversedBy="administrator", cascade={"persist", "remove"})
  37.      */
  38.     private $user;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity="App\Entity\Store", mappedBy="administrator")
  41.      */
  42.     private $stores;
  43.     /**
  44.      * @ORM\Column(type="integer", nullable=true)
  45.      */
  46.     private $dailyCapping;
  47.     /**
  48.      * @ORM\Column(type="integer", nullable=true)
  49.      */
  50.     private $monthlyCapping;
  51.     /**
  52.      * @ORM\Column(type="float", nullable=true)
  53.      */
  54.     private $leadCost;
  55.     /**
  56.      * @var boolean
  57.      * @ORM\Column(type="boolean", options={"default" : false})
  58.      */
  59.     private $isCustomer;
  60.     /**
  61.      * @ORM\Column(type="integer", nullable=true)
  62.      */
  63.     private $numberOfLeadMonthly;
  64.     /**
  65.      * @ORM\Column(type="datetime", nullable=true)
  66.      * @Gedmo\Timestampable(on="create")
  67.      */
  68.     private ?DateTime $registrationDate null;
  69.     /**
  70.      * @ORM\Column(type="integer", nullable=true)
  71.      */
  72.     protected ?int $businessModel null;
  73.     /**
  74.      * @ORM\Column(type="datetime", nullable=true)
  75.      */
  76.     private ?DateTime $businessModelSince;
  77.     /**
  78.      * @ORM\Column(type="datetime", nullable=true)
  79.      */
  80.     protected ?DateTime $businessModelDeadline null;
  81.     /**
  82.      * @ORM\Column(type="integer", nullable=true)
  83.      */
  84.     private ?int $ageCapping;
  85.     public function __construct()
  86.     {
  87.         $this->stores = new ArrayCollection();
  88.         $this->isCustomer false;
  89.     }
  90.     /**
  91.      * Représente l'entité par défault
  92.      * @return string
  93.      */
  94.     public function __toString()
  95.     {
  96.         return 'Administrator ' $this->getName() . ' [' $this->getId() . ']';
  97.     }
  98.     /**
  99.      * Représente l'entité dans le BO
  100.      * @return string
  101.      */
  102.     public function getLabel()
  103.     {
  104.         return $this->getName();
  105.     }
  106.     /**
  107.      * Représente l'entité par son nom et son type (admin ou freelance)
  108.      * @return string
  109.      */
  110.     public function getLabelWithType()
  111.     {
  112.         return $this->getName() . ' [Administrateur]';
  113.     }
  114.     public function getId(): ?int
  115.     {
  116.         return $this->id;
  117.     }
  118.     public function getNameAndEmailUser()
  119.     {
  120.         if ($this->isFreelancer() === true && $this->getUser() !== null) {
  121.             return $this->getNameAndEmailUser();
  122.         } else {
  123.             return $this->getName() . ' [Partenaire]';
  124.         }
  125.     }
  126.     public function getName(): ?string
  127.     {
  128.         return $this->name;
  129.     }
  130.     public function setName(string $name): self
  131.     {
  132.         $this->name $name;
  133.         return $this;
  134.     }
  135.     public function getUser(): ?User
  136.     {
  137.         return $this->user;
  138.     }
  139.     public function setUser(?User $user): self
  140.     {
  141.         $this->user $user;
  142.         return $this;
  143.     }
  144.     /**
  145.      * @return Collection|Store[]
  146.      */
  147.     public function getStores(): Collection
  148.     {
  149.         return $this->stores;
  150.     }
  151.     public function addStore(Store $store): self
  152.     {
  153.         if (!$this->stores->contains($store)) {
  154.             $this->stores[] = $store;
  155.             $store->setAdministrator($this);
  156.         }
  157.         return $this;
  158.     }
  159.     public function removeStore(Store $store): self
  160.     {
  161.         if ($this->stores->contains($store)) {
  162.             $this->stores->removeElement($store);
  163.             // set the owning side to null (unless already changed)
  164.             if ($store->getAdministrator() === $this) {
  165.                 $store->setAdministrator(null);
  166.             }
  167.         }
  168.         return $this;
  169.     }
  170.     /**
  171.      * Does this admin ca buy credit.
  172.      * he can if he is NOT "perf" business model
  173.      * @return bool
  174.      */
  175.     public function canBuyCredit(): bool
  176.     {
  177.         return $this->getBusinessModel() !== BusinessModelEnum::PERFORMANCE;
  178.     }
  179.     /**
  180.      * Indicate if the administrator (freelance or parnter is a customer of MCA)
  181.      * @return bool|null
  182.      */
  183.     public function isCustomer(): ?bool
  184.     {
  185.         return $this->isCustomer;
  186.     }
  187.     public function getDailyCapping(): ?int
  188.     {
  189.         return $this->dailyCapping;
  190.     }
  191.     public function setDailyCapping(int $dailyCapping): self
  192.     {
  193.         $this->dailyCapping $dailyCapping;
  194.         return $this;
  195.     }
  196.     public function getMonthlyCapping(): ?int
  197.     {
  198.         return $this->monthlyCapping;
  199.     }
  200.     public function setMonthlyCapping(int $monthlyCapping): self
  201.     {
  202.         $this->monthlyCapping $monthlyCapping;
  203.         return $this;
  204.     }
  205.     public function getLeadCost(): ?float
  206.     {
  207.         return $this->leadCost;
  208.     }
  209.     public function setLeadCost(float $leadCost): self
  210.     {
  211.         $this->leadCost $leadCost;
  212.         return $this;
  213.     }
  214.     /**
  215.      * Est-ce que cet Administrateur est un partenaire
  216.      * @return bool
  217.      */
  218.     public function isPartner()
  219.     {
  220.         return $this instanceof Partner;
  221.     }
  222.     /**
  223.      * Est-ce que cet Administrateur est un freelance
  224.      * @return bool
  225.      */
  226.     public function isFreelancer()
  227.     {
  228.         return $this instanceof Freelancer;
  229.     }
  230.     /**
  231.      * @return bool|null
  232.      * @deprecated use IsCustomer instead
  233.      */
  234.     public function getIsCustomer(): bool
  235.     {
  236.         return $this->isCustomer;
  237.     }
  238.     public function setIsCustomer(bool $isCustomer): self
  239.     {
  240.         $this->isCustomer $isCustomer;
  241.         return $this;
  242.     }
  243.     public function getNumberOfLeadMonthly(): ?int
  244.     {
  245.         return $this->numberOfLeadMonthly;
  246.     }
  247.     public function setNumberOfLeadMonthly(?int $numberOfLeadMonthly): self
  248.     {
  249.         $this->numberOfLeadMonthly $numberOfLeadMonthly;
  250.         return $this;
  251.     }
  252.     public function getRegistrationDate(): ?DateTime
  253.     {
  254.         return $this->registrationDate;
  255.     }
  256.     public function setRegistrationDate(?DateTime $registrationDate): void
  257.     {
  258.         $this->registrationDate $registrationDate;
  259.     }
  260.     public function getBusinessModel(): ?int
  261.     {
  262.         return $this->businessModel;
  263.     }
  264.     public function hasBusinessModel(): bool
  265.     {
  266.         return $this->businessModel !== BusinessModelEnum::NONE;
  267.     }
  268.     public function getBusinessModelLabel(): string
  269.     {
  270.         return 'business_model.' $this->businessModel;
  271.     }
  272.     public function getBusinessModelName(): string
  273.     {
  274.         return BusinessModelEnum::toString($this->businessModel);
  275.     }
  276.     public function setBusinessModel(int $businessModel): void
  277.     {
  278.         if ($this->businessModel !== $businessModel) {
  279.             $this->setBusinessModelSince(new DateTime());
  280.         }
  281.         $this->businessModel $businessModel;
  282.     }
  283.     public function isPayAsYouGo(): ?bool
  284.     {
  285.         return $this->businessModel === BusinessModelEnum::PAY_AS_YOU_GO;
  286.     }
  287.     public function isCredit(): ?bool
  288.     {
  289.         return $this->businessModel === BusinessModelEnum::CREDIT;
  290.     }
  291.     public function isPerformance(): ?bool
  292.     {
  293.         return $this->businessModel === BusinessModelEnum::PERFORMANCE;
  294.     }
  295.     public function getBusinessModelSince(): ?DateTimeInterface
  296.     {
  297.         return $this->businessModelSince;
  298.     }
  299.     public function setBusinessModelSince(?DateTimeInterface $businessModelSince): self
  300.     {
  301.         $this->businessModelSince $businessModelSince;
  302.         return $this;
  303.     }
  304.     public function getBusinessModelDeadline(): ?DateTime
  305.     {
  306.         return $this->businessModelDeadline;
  307.     }
  308.     public function setBusinessModelDeadline(?DateTime $businessModelDeadline): void
  309.     {
  310.         $this->businessModelDeadline $businessModelDeadline;
  311.     }
  312.     public function hasBusinessModelDeadline(): bool
  313.     {
  314.         return $this->businessModelDeadline !== null;
  315.     }
  316.     public function hasFakeBusinessModelDeadline(): bool
  317.     {
  318.         //compare businessModelDeadline with BUSINESS_MODEL_FAKE_DEADLINE
  319.         return $this->businessModelDeadline && $this->businessModelDeadline->format('Y-m-d H:i:s') === Freelancer::BUSINESS_MODEL_FAKE_DEADLINE;
  320.     }
  321.     public function getAgeCapping(): ?int
  322.     {
  323.         return $this->ageCapping;
  324.     }
  325.     public function setAgeCapping(?int $ageCapping): void
  326.     {
  327.         $this->ageCapping $ageCapping;
  328.     }
  329. }