src/Entity/CompanyAssociation.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\CompanyAssociationRepository")
  8.  * @ORM\HasLifecycleCallbacks()
  9.  */
  10. class CompanyAssociation
  11. {
  12.     /**
  13.      * @ORM\Id()
  14.      * @ORM\GeneratedValue()
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="datetime")
  20.      */
  21.     private $dateCreated;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\OneToOne(targetEntity="App\Entity\Image", cascade={"persist", "remove"})
  28.      */
  29.     private $logo;
  30.     /**
  31.      * @ORM\ManyToMany(targetEntity="App\Entity\Company", inversedBy="associations", cascade={"persist"})
  32.      */
  33.     private $companies;
  34.     /**
  35.      * @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="AdminOfCompanyAssociations")
  36.      */
  37.     private $adminUsers;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity="App\Entity\User", mappedBy="makeCompanyForAssociation")
  40.      */
  41.     private $usersAddingCompanies;
  42.     /**
  43.      * @ORM\Column(type="string", length=255)
  44.      */
  45.     private $urlName;
  46.     /**
  47.      * @ORM\Column(type="text", nullable=true)
  48.      */
  49.     private $description;
  50.     /**
  51.      * @ORM\OneToOne(targetEntity="App\Entity\Image", cascade={"persist", "remove"})
  52.      */
  53.     private $banner;
  54.     /**
  55.      * @ORM\ManyToMany(targetEntity="App\Entity\Variable", inversedBy="companyAssociations")
  56.      */
  57.     private $variables;
  58.     /**
  59.      * @ORM\OneToMany(targetEntity="App\Entity\CartProduct", mappedBy="addedWhenBeingInAssociation")
  60.      */
  61.     private $cartProducts;
  62.     public function __construct()
  63.     {
  64.         $this->companies = new ArrayCollection();
  65.         $this->dateCreated = new \DateTime();
  66.         $this->adminUsers = new ArrayCollection();
  67.         $this->usersAddingCompanies = new ArrayCollection();
  68.         $this->variables = new ArrayCollection();
  69.         $this->cartProducts = new ArrayCollection();
  70.     }
  71.     /**
  72.      * @ORM\PrePersist
  73.      */
  74.     public function doActionsOnPrePersist(){
  75.     }
  76.     /**
  77.      * @ORM\PreUpdate
  78.      */
  79.     public function doActionsOnPreUpdate(){
  80.     }
  81.     /*
  82.         Do what's needed to be a public market
  83.     */
  84.     public function doActionsToBeAPublicMarket(){
  85.     }
  86.     /*
  87.         Do what's needed to be a out of a public market
  88.     */
  89.     public function doActionsToBeRemovedFromAPublicMarket(){
  90.     }
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     public function getDateCreated(): ?\DateTimeInterface
  96.     {
  97.         return $this->dateCreated;
  98.     }
  99.     public function setDateCreated(\DateTimeInterface $dateCreated): self
  100.     {
  101.         $this->dateCreated $dateCreated;
  102.         return $this;
  103.     }
  104.     public function getName(): ?string
  105.     {
  106.         return $this->name;
  107.     }
  108.     public function setName(string $name): self
  109.     {
  110.         $this->name $name;
  111.         return $this;
  112.     }
  113.     public function getLogo(): ?Image
  114.     {
  115.         return $this->logo;
  116.     }
  117.     public function setLogo(?Image $logo): self
  118.     {
  119.         if(!empty($logo))
  120.             $this->logo $logo;
  121.         return $this;
  122.     }
  123.     /**
  124.      * @return Collection|Company[]
  125.      */
  126.     public function getCompanies(): Collection
  127.     {
  128.         return $this->companies;
  129.     }
  130.     public function addCompany(Company $company): self
  131.     {
  132.         if (!$this->companies->contains($company)) {
  133.             $this->companies[] = $company;
  134.         }
  135.         //We need to add for the market too
  136.         $company->doActionsToBeAPublicMarket();
  137.         return $this;
  138.     }
  139.     public function removeCompany(Company $company): self
  140.     {
  141.         if ($this->companies->contains($company)) {
  142.             $this->companies->removeElement($company);
  143.         }
  144.         //We need to reset for the market too
  145.         $company->doActionsToBeRemovedFromAPublicMarket();
  146.         return $this;
  147.     }
  148.     public function __toString()
  149.     {
  150.         return $this->getName();
  151.     }
  152.     /**
  153.      * @return Collection|User[]
  154.      */
  155.     public function getAdminUsers(): Collection
  156.     {
  157.         return $this->adminUsers;
  158.     }
  159.     public function addAdminUser(User $adminUser): self
  160.     {
  161.         if (!$this->adminUsers->contains($adminUser)) {
  162.             $this->adminUsers[] = $adminUser;
  163.             $adminUser->addMakeGroupOfAssociation($this);
  164.         }
  165.         return $this;
  166.     }
  167.     public function removeAdminUser(User $adminUser): self
  168.     {
  169.         if ($this->adminUsers->contains($adminUser)) {
  170.             $this->adminUsers->removeElement($adminUser);
  171.             $adminUser->removeMakeGroupOfAssociation($this);
  172.         }
  173.         return $this;
  174.     }
  175.     /**
  176.      * @return Collection|User[]
  177.      */
  178.     public function getUsers(): Collection
  179.     {
  180.         return $this->users;
  181.     }
  182.     public function addUser(User $user): self
  183.     {
  184.         if (!$this->users->contains($user)) {
  185.             $this->users[] = $user;
  186.             $user->addAdminOfCompanyAssociation($this);
  187.         }
  188.         return $this;
  189.     }
  190.     public function removeUser(User $user): self
  191.     {
  192.         if ($this->users->contains($user)) {
  193.             $this->users->removeElement($user);
  194.             $user->removeAdminOfCompanyAssociation($this);
  195.         }
  196.         return $this;
  197.     }
  198.     /**
  199.      * @return Collection|User[]
  200.      */
  201.     public function getUsersAddingCompanies(): Collection
  202.     {
  203.         return $this->usersAddingCompanies;
  204.     }
  205.     public function addUsersAddingCompany(User $usersAddingCompany): self
  206.     {
  207.         if (!$this->usersAddingCompanies->contains($usersAddingCompany)) {
  208.             $this->usersAddingCompanies[] = $usersAddingCompany;
  209.             $usersAddingCompany->setMakeCompanyForAssociation($this);
  210.         }
  211.         return $this;
  212.     }
  213.     public function removeUsersAddingCompany(User $usersAddingCompany): self
  214.     {
  215.         if ($this->usersAddingCompanies->contains($usersAddingCompany)) {
  216.             $this->usersAddingCompanies->removeElement($usersAddingCompany);
  217.             // set the owning side to null (unless already changed)
  218.             if ($usersAddingCompany->getMakeCompanyForAssociation() === $this) {
  219.                 $usersAddingCompany->setMakeCompanyForAssociation(null);
  220.             }
  221.         }
  222.         return $this;
  223.     }
  224.     public function getUrlName(): ?string
  225.     {
  226.         return $this->urlName;
  227.     }
  228.     public function setUrlName(string $urlName): self
  229.     {
  230.         $this->urlName $urlName;
  231.         return $this;
  232.     }
  233.     public function getDescription(): ?string
  234.     {
  235.         return $this->description;
  236.     }
  237.     public function setDescription(?string $description): self
  238.     {
  239.         $this->description $description;
  240.         return $this;
  241.     }
  242.     public function getBanner(): ?Image
  243.     {
  244.         return $this->banner;
  245.     }
  246.     public function setBanner(?Image $banner): self
  247.     {
  248.         if(!empty($banner))
  249.             $this->banner $banner;
  250.         return $this;
  251.     }
  252.     /**
  253.      * @return Collection|Variable[]
  254.      */
  255.     public function getVariables(): Collection
  256.     {
  257.         return $this->variables;
  258.     }
  259.     public function addVariable(Variable $variable): self
  260.     {
  261.         if (!$this->variables->contains($variable)) {
  262.             $this->variables[] = $variable;
  263.         }
  264.         return $this;
  265.     }
  266.     public function removeVariable(Variable $variable): self
  267.     {
  268.         if ($this->variables->contains($variable)) {
  269.             $this->variables->removeElement($variable);
  270.         }
  271.         return $this;
  272.     }
  273.     public function getVariableByCodeName($codeName){
  274.         foreach($this->getVariables() as $v){
  275.             if($v->getCodeName() == $codeName)
  276.                 return $v;
  277.         }
  278.         return false;
  279.     }
  280.     public function getVariableValueByCodeName($codeName){
  281.         $test $this->getVariableByCodeName($codeName);
  282.         if($test && !$test->isExpired())
  283.             return $test->getValue();
  284.         return false;
  285.     }
  286.     /**
  287.      * @return Collection|CartProduct[]
  288.      */
  289.     public function getCartProducts(): Collection
  290.     {
  291.         return $this->cartProducts;
  292.     }
  293.     public function addCartProduct(CartProduct $cartProduct): self
  294.     {
  295.         if (!$this->cartProducts->contains($cartProduct)) {
  296.             $this->cartProducts[] = $cartProduct;
  297.             $cartProduct->setAddedWhenBeingInAssociation($this);
  298.         }
  299.         return $this;
  300.     }
  301.     public function removeCartProduct(CartProduct $cartProduct): self
  302.     {
  303.         if ($this->cartProducts->contains($cartProduct)) {
  304.             $this->cartProducts->removeElement($cartProduct);
  305.             // set the owning side to null (unless already changed)
  306.             if ($cartProduct->getAddedWhenBeingInAssociation() === $this) {
  307.                 $cartProduct->setAddedWhenBeingInAssociation(null);
  308.             }
  309.         }
  310.         return $this;
  311.     }
  312.     public function getDefaultDeliveryIsPickup(): bool {
  313.         return (bool) $this->getVariableValueByCodeName('orders.canPickUp');
  314.     }
  315.     public function canPackUp(): int {
  316.         return $this->getVariableValueByCodeName('orders.canPackUp');
  317.     }
  318. }