src/Entity/Company.php line 98

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use App\Filter\RestrictedGroupFilter;
  10. use App\Entity\Traits\Address;
  11. use App\Repository\CompanyRepository;
  12. use App\Security\UserChecker;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\ORM\Mapping as ORM;
  16. use Gedmo\Mapping\Annotation as Gedmo;
  17. use Symfony\Component\HttpFoundation\File\File;
  18. use Symfony\Component\HttpFoundation\File\UploadedFile;
  19. use Symfony\Component\Serializer\Annotation\Groups;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  22. /**
  23.  * @ORM\InheritanceType("SINGLE_TABLE")
  24.  * @ORM\Entity(repositoryClass=CompanyRepository::class)
  25.  * @ApiResource(
  26.  *      normalizationContext={
  27.  *          "groups"={"company:read"}
  28.  *      },
  29.  *      denormalizationContext={
  30.  *          "groups"={"company:write"}
  31.  *      },
  32.  *      itemOperations={
  33.  *          "get"={
  34.  *              "security"="is_granted('ROLE_ADMIN') or (is_granted('ROLE_COMPANY') and user.getCompany() == object)"
  35.  *          },
  36.  *          "patch"={
  37.  *              "security"="is_granted('ROLE_ADMIN') or (is_granted('ROLE_COMPANY') and user.getCompany() == object)"
  38.  *          },
  39.  *          "delete"={
  40.  *              "security"="is_granted('ROLE_ADMIN')"
  41.  *          }
  42.  *      },
  43.  *      collectionOperations={
  44.  *          "get"={
  45.  *              "security"="is_granted('ROLE_ADMIN')"
  46.  *          }, 
  47.  *          "post"={
  48.  *              "security"="is_granted('ROLE_ADMIN')"
  49.  *          },
  50.  *          "export"={
  51.  *              "security"="is_granted('ROLE_ADMIN')",
  52.  *              "method"="GET",
  53.  *              "controller"="App\Controller\Api\CompanyController::extractCsv",
  54.  *              "path"="/companies/export",
  55.  *              "formats"={"csv"={"text/csv"}},
  56.  *              "pagination_enabled"=false,
  57.  *              "output"=Company::class,
  58.  *              "normalization_context"={"groups"={"company:export_csv:read"}}
  59.  *          },
  60.  *          "post_update"={
  61.  *              "security"="is_granted('ROLE_ADMIN')",
  62.  *              "path"="/companies/{id}",
  63.  *              "description"="Update a Company with method POST (using content-type: 'multipart')",
  64.  *              "method"="POST",
  65.  *              "controller"="App\Controller\Api\CompanyController::update"
  66.  *          }
  67.  *      }
  68.  * )
  69.  * @ApiFilter(SearchFilter::class, 
  70.  *      properties={
  71.  *          "name":"partial"
  72.  *      }
  73.  * )
  74.  * @ApiFilter(OrderFilter::class, 
  75.  *      properties={
  76.  *          "id", "name", "user.lastName", "status", "subscriptionEnd", "subscriptionStart", "clientsCount"
  77.  *      } 
  78.  * )
  79.  * @ApiFilter(RestrictedGroupFilter::class,
  80.  *      arguments={
  81.  *          "overrideDefaultGroups": true,
  82.  *          "whitelist": {"company:read", "company:read:id", "company:read:name", "company:read:status", "company:read:siren", "company:read:logo", "company:read:subscriptionStart", "company:read:subscriptionEnd", "company:read:user", "media_object:read:contentUrl", "address:read:street", "address:read:zipCode", "address:read:town", "address:read:country", "user:read:id", "user:read:lastName", "user:read:firstName", "user:read:function"},
  83.  *          "companyGroups": {"user:read:phone", "user:read:email"}
  84.  *      }
  85.  * )
  86.  * @ApiFilter(PropertyFilter::class, 
  87.  *      arguments={
  88.  *          "parameterName"="fields", 
  89.  *          "overrideDefaultProperties"=true
  90.  *     }
  91.  * )
  92.  * @ORM\HasLifecycleCallbacks
  93.  * @Vich\Uploadable
  94.  */
  95. class Company
  96. {
  97.     const STATUS_ACTIVE = 'active';
  98.     const STATUS_EXPIRED = 'expired';
  99.     const STATUS_SUSPENDED = 'suspended';
  100.     const STATUS_INACTIVE = 'deactivated';
  101.     const MESSAGE_RESTRICTION = 'restricted_msg';
  102.     const MESSAGE_QUOTAS = 'restricted_msg';
  103.     const MESSAGE_DEFAULT = 'default';
  104.     const STATUSES = [
  105.         self::STATUS_INACTIVE,
  106.         self::STATUS_EXPIRED,
  107.         self::STATUS_SUSPENDED,
  108.         self::STATUS_ACTIVE,
  109.     ];
  110.     use Address;
  111.     /**
  112.      * @ORM\Id
  113.      * @ORM\GeneratedValue
  114.      * @ORM\Column(type="integer")
  115.      * @Groups({"company:read", "team:read", "company:read:id", "client:read", "company_form", "teamplay:read", "video:read", "exclusion_video:read", "exclusion_category:read", "category:read", "program:read", "message:read"})
  116.      */
  117.     private $id;
  118.     /**
  119.      * @ORM\Column(type="string", length=255)
  120.      * @Assert\NotBlank
  121.      * @Groups({"company:read", "team:read", "company:read:name", "client:read", "company_form", "teamplay:read", "video:read", "exclusion_video:read", "exclusion_category:read", "category:read", "program:read", "message:read"})
  122.      */
  123.     private $name;
  124.     /**
  125.      * @ORM\Column(type="string", length=255, nullable=true)
  126.      * @Groups({"company:read:image", "client:read"})
  127.      */
  128.     private $image;
  129.     /**
  130.      * @Groups({"company:read", "company:read:imageUrl", "client:read", "user:read"})
  131.      * @var ?string
  132.      */
  133.     private $imageUrl = "https://placehold.co/600x300";
  134.     /**
  135.      * @ORM\Column(type="datetime", nullable=true)
  136.      * @Gedmo\Timestampable(on="update")
  137.      */
  138.     private $updatedAt;
  139.     /**
  140.      * @ORM\OneToOne(targetEntity=User::class, inversedBy="company", cascade={"persist", "refresh", "remove"})
  141.      * @ORM\JoinColumn(nullable=false)
  142.      * @Assert\Valid()
  143.      * @Groups({"company:read", "company:read:user"})
  144.      */
  145.     private $user;
  146.     /**
  147.      * @Vich\UploadableField(mapping="specialists_images", fileNameProperty="image")
  148.      * @Assert\File(
  149.      *     mimeTypes={"image/jpeg", "image/gif", "image/png"},
  150.      *     maxSize="700Ki",
  151.      * )
  152.      * @var File
  153.      */
  154.     private $imageFile;
  155.     /**
  156.      * @ORM\OneToMany(targetEntity=Room::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"}) 
  157.      * @Groups({"company:read", "company:read:rooms"})
  158.      */
  159.     private $rooms;
  160.     /**
  161.      * @ORM\OneToMany(targetEntity=Workshop::class, mappedBy="company", cascade={"persist", "refresh", "remove"})      
  162.      * @Groups({"company:read", "company:read:workshop"})   
  163.      */
  164.     private $workshops;
  165.     /**
  166.      * @ORM\OneToMany(targetEntity=Client::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  167.      * @Groups({"company:read", "company:read:clients"})
  168.      * @ApiSubresource(maxDepth=1)
  169.      */
  170.     private $clients;
  171.     /**
  172.      * @ORM\OneToMany(targetEntity=Event::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  173.      * @Groups({"company:read", "company:read:events"})
  174.      */
  175.     private $events;
  176.     /**
  177.      * @ORM\OneToMany(targetEntity=CompanyTag::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  178.      */
  179.     private $companyTags;
  180.     /**
  181.      * @ORM\Column(type="text", nullable=true)
  182.      * @Groups({"company:read", "company:read:presentation"})
  183.      */
  184.     private $presentation;
  185.     /**
  186.      * @ORM\Column(type="string", length=255, nullable=true)
  187.      * @Groups({"company:read", "company:read:presentationTitle"})
  188.      */
  189.     private $presentationTitle;
  190.     /**
  191.      * @ORM\Column(type="string", length=255, nullable=true)
  192.      * @Groups({"company:read", "company:read:siret"})
  193.      */
  194.     private $siret;
  195.     /**
  196.      * @ORM\Column(type="string", length=255, nullable=true)
  197.      * @Groups({"company:read", "company:read:phone"})
  198.      */
  199.     private $phone;
  200.     /**
  201.      * @ORM\Column(type="datetime", options={"default": "CURRENT_TIMESTAMP"})
  202.      * @Gedmo\Timestampable(on="create")
  203.      * @Groups({"company:read", "company:read:createdAt"})
  204.      */
  205.     private $createdAt;
  206.     /**
  207.      * @ORM\Column(type="string", length=255, nullable=true)
  208.      * @Groups({"company:read", "company:read:companyCode"})
  209.      */
  210.     private $companyCode;
  211.     /**
  212.      * @ORM\OneToMany(targetEntity=VisioEventPromotion::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  213.      */
  214.     private $visioEventPromotions;
  215.     /**
  216.      * @ORM\Column(type="boolean", options={"default": "1"})
  217.      * @Groups({"company:read", "company:read:visioAllowed"})
  218.      */
  219.     private $visioAllowed = true;
  220.     /**
  221.      * @ORM\Column(type="boolean", options={"default": "1"})
  222.      * @Groups({"company:read", "company:read:visioPaymentAllowed"})
  223.      */
  224.     private $visioPaymentAllowed = true;
  225.     /**
  226.      * @ORM\OneToMany(targetEntity=Specialist::class, mappedBy="affiliatedCompany", orphanRemoval=false)
  227.      */
  228.     private $affiliatedSpecialists;
  229.     /**
  230.      * @ORM\ManyToMany(targetEntity=Specialist::class, mappedBy="companies")
  231.      * @Groups({"company:read", "company:read:specialists"})
  232.      */
  233.     private $specialists;
  234.     /**
  235.      * @ORM\OneToMany(targetEntity=AffiliatedEventApplication::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  236.      */
  237.     private $affiliatedEventApplications;
  238.     /**
  239.      * @ORM\OneToMany(targetEntity=Segmentation::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  240.      * @Groups({"company:read", "company:read:segmentations"})
  241.      * @ApiSubresource(maxDepth=1)
  242.      */
  243.     private $segmentations;
  244.     /**
  245.      * @ORM\Column(type="boolean", options={"default": "0"})
  246.      * @Groups({"company:read", "client:read"})
  247.      */
  248.     private $forceSegmentation = false;
  249.     /**
  250.      * @ORM\OneToMany(targetEntity=Configuration::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  251.      * @Groups({"company:read", "company:read:configurations"})
  252.      */
  253.     private $configurations;
  254.     // TV FIELDS
  255.     /**
  256.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  257.      * @Groups({"company:read", "company:write", "company:read:logo", "client:read"})
  258.      */
  259.     private $logo;
  260.     /**
  261.      * @ORM\Column(type="string", length=255, nullable=true)
  262.      * @Groups({"company:read", "company:write", "company:read:siren"})
  263.      */
  264.     private $siren;
  265.     /**
  266.      * @ORM\Column(type="string", length=255, options={"default": "active"})
  267.      * @Groups({"company:read", "company:write", "company:read:status"})
  268.      */
  269.     private $status = self::STATUS_ACTIVE;
  270.     /**
  271.      * @ORM\Column(type="boolean", options={"default": "1"})
  272.      * @Groups({"company:read", "company:read:active"})
  273.      */
  274.     private $active = true;
  275.     /**
  276.      * @ORM\Column(type="datetime", nullable=true)
  277.      * @Groups({"company:read", "company:write", "company:read:subscriptionStart"})
  278.      */
  279.     private $subscriptionStart;
  280.     /**
  281.      * @ORM\Column(type="datetime", nullable=true)
  282.      * @Groups({"company:read", "company:write", "company:read:subscriptionEnd"})
  283.      */
  284.     private $subscriptionEnd;
  285.     /**
  286.      * @ORM\Column(type="integer")
  287.      * @Groups({"company:read", "company:read:clientsCount"})
  288.      */
  289.     private $clientsCount = 0;
  290.     /**
  291.      * Restriction messages if an User bypasses any restrictions
  292.      * A 'default' message key will be used if the message has not been customized
  293.      * @ORM\Column(type="array")
  294.      * @Groups({"company:read", "company:write"})
  295.      */
  296.     private $messages = [self::MESSAGE_DEFAULT => UserChecker::QUOTAS_MESSAGE];
  297.     /**
  298.      * Maximum users allowed for the company
  299.      * @ORM\Column(type="integer", nullable=true)
  300.      * @Groups({"company:read", "company:write", "company:read:maxClients"})
  301.      */
  302.     private $maxClients;
  303.     /**
  304.      * Forfait heure / forfait visionnage
  305.      * @ORM\Column(type="string", length=255, nullable=true)
  306.      * @Groups({"company:read", "company:write"})
  307.      */
  308.     private $plan;
  309.     /**
  310.      * Domain corresponding to this company ex:
  311.      * "orange.ulteam-tv.fr" will match company "Orange"
  312.      * @ORM\Column(type="string", length=255, nullable=true)
  313.      * @Groups({"company:read", "company:write"})
  314.      */
  315.     private $slug;
  316.     /**
  317.      * Restriction par IP
  318.      * @ORM\Column(type="array", nullable=true)
  319.      * @Groups({"company:read", "company:write"})
  320.      */
  321.     private $ips = [];
  322.     /**
  323.      * Restriction par domaine mail
  324.      * @ORM\Column(type="array", nullable=true)
  325.      * @Groups({"company:read", "company:write"})
  326.      */
  327.     private $domain = [];
  328.     /**
  329.      * Restriction heure de visionnage par utilisateur (5h)
  330.      * @ORM\Column(type="integer", nullable=true)
  331.      * @Groups({"company:read", "company:write"})
  332.      */
  333.     private $hourlyRestriction;
  334.     /**
  335.      * @ORM\Column(type="boolean", options={"default": "0"})
  336.      */
  337.     private $customizable = false;
  338.     /**
  339.      * @ORM\Column(type="text", nullable=true)
  340.      * @Groups({"company:read", "company:write", "company:read:cms"})
  341.      */
  342.     private $cms;
  343.     /**
  344.      * @ORM\Column(type="string", length=255, nullable=true)
  345.      * @Groups({"company:read", "company:write", "company:read:cmsTitle"})
  346.      */
  347.     private $cmsTitle;
  348.     /**
  349.      * @ORM\ManyToOne(targetEntity=MediaObject::class)
  350.      * @Groups({"company:read", "company:write", "company:read:cmsImg"})
  351.      */
  352.     private $cmsImg;
  353.     /**
  354.      * @ORM\Column(type="text", nullable=true)
  355.      * @Groups({"company:read", "company:write", "company:read:cmsText"})
  356.      */
  357.     private $cmsText;
  358.     /**
  359.      * @ORM\Column(type="string", length=255, nullable=true)
  360.      * @Groups({"company:read", "company:write", "company:read:cmsCtaText"})
  361.      */
  362.     private $cmsCtaText;
  363.     /**
  364.      * @ORM\Column(type="string", length=255, nullable=true)
  365.      * @Groups({"company:read", "company:write", "company:read:cmsCtaUrl"})
  366.      */
  367.     private $cmsCtaUrl;
  368.     /**
  369.      * @ORM\Column(type="boolean", nullable=true)
  370.      * @Groups({"company:read", "company:write", "company:read:resaLinkActive"})
  371.      */
  372.     private $resaLinkActive;
  373.     /**
  374.      * @ORM\Column(type="string", length=255, nullable=true)
  375.      * @Groups({"company:read", "company:write", "company:read:email"})
  376.      */
  377.     private $email;
  378.     /**
  379.      * @ORM\OneToMany(targetEntity=Restriction::class, mappedBy="company", orphanRemoval=true, cascade={"remove"})
  380.      * @Groups({"company:read"})
  381.      */
  382.     private $restrictions;
  383.     /**
  384.      * @ORM\OneToMany(targetEntity=Order::class, mappedBy="company", cascade={"remove"})
  385.      * @Groups({"company:read"})
  386.      */
  387.     private $orders;
  388.     /**
  389.      * @ORM\OneToMany(targetEntity=Category::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  390.      */
  391.     private $categories;
  392.     /**
  393.      * @ORM\OneToMany(targetEntity=Channel::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  394.      */
  395.     private $channels;
  396.     /**
  397.      * @ORM\OneToMany(targetEntity=ExclusionsChannel::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  398.      */
  399.     private $exclusionsChannels;
  400.     /**
  401.      * @ORM\OneToMany(targetEntity=ExclusionsCategory::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  402.      */
  403.     private $exclusionsCategories;
  404.     /**
  405.      * @ORM\OneToMany(targetEntity=ExclusionsVideo::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  406.      */
  407.     private $exclusionsVideos;
  408.     /**
  409.      * @ORM\OneToMany(targetEntity=LogEmail::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  410.      */
  411.     private $logEmails;
  412.     /**
  413.      * @ORM\ManyToMany(targetEntity=Association::class)
  414.      * @Groups({"company:read", "company:write"})
  415.      * @ApiSubresource(maxDepth=1)
  416.      */
  417.     private $associations;
  418.     /**
  419.      * @ORM\OneToMany(targetEntity=Program::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  420.      */
  421.     private $programs;
  422.     /**
  423.      * @ORM\OneToMany(targetEntity=Team::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  424.      * @Groups({"company:read"})
  425.      * @ApiSubresource(maxDepth=1)
  426.      */
  427.     private $teams;
  428.     /**
  429.      * @ORM\OneToMany(targetEntity=Teamplay::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  430.      * @Groups({"company:read"})
  431.      */
  432.     private $teamplays;
  433.     /**
  434.      * @ORM\OneToMany(targetEntity=TeamplayChallenge::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  435.      * @Groups({"company:read"})
  436.      */
  437.     private $teamplayChallenges;
  438.     /**
  439.      * @ORM\OneToMany(targetEntity=TeamplayLog::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  440.      */
  441.     private $teamplayLogs;
  442.     /**
  443.      * @ORM\OneToMany(targetEntity=PedometerLog::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  444.      */
  445.     private $pedometerLogs;
  446.     /**
  447.      * @ORM\OneToMany(targetEntity=Log::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  448.      */
  449.     private $logs;
  450.     /**
  451.      * @ORM\OneToMany(targetEntity=UserNotification::class, mappedBy="company", cascade={"persist", "refresh", "remove"})
  452.      */
  453.     private $userNotifications;
  454.     
  455.     /**
  456.      * @ORM\OneToMany(targetEntity=Slide::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  457.      * @Groups({"company:read"})
  458.      */
  459.     private $slides;
  460.     /**
  461.      * @ORM\ManyToMany(targetEntity=Award::class, mappedBy="companies")
  462.      */
  463.     private $awards;
  464.     /**
  465.      * @ORM\OneToMany(targetEntity=AwardConfig::class, mappedBy="company", orphanRemoval=true, cascade={"persist", "refresh", "remove"})
  466.      */
  467.     private $awardConfigs;
  468.     /**
  469.      * @ORM\OneToOne(targetEntity=TvCompany::class, mappedBy="company", cascade={"persist", "refresh","remove"})
  470.      */
  471.     private $tvCompany;
  472.     /**
  473.      * @ORM\Column(type="boolean", options={"default": "1"})
  474.      * @Groups({"company:write",  "company:read", "company:read:live", "client:read"})
  475.      */
  476.     private $live = true;
  477.     /**
  478.      * @ORM\Column(type="boolean", options={"default": "1"})
  479.      * @Groups({"company:write",  "company:read", "company:read:tv", "client:read"})
  480.      */
  481.     private $tv = true;
  482.     /**
  483.      * @ORM\Column(type="string", length=255, nullable=true)
  484.      * @Groups({"company:read", "company:write", "company:read:consultLink", "client:read"})
  485.      */
  486.     private $consultLink;
  487.     public function __construct()
  488.     {
  489.         $this->rooms = new ArrayCollection();
  490.         $this->workshops = new ArrayCollection();
  491.         $this->clients = new ArrayCollection();
  492.         $this->events = new ArrayCollection();
  493.         $this->companyTags = new ArrayCollection();
  494.         $this->createdAt = new \DateTime();
  495.         $this->visioEventPromotions = new ArrayCollection();
  496.         $this->affiliatedSpecialists = new ArrayCollection();
  497.         $this->specialists = new ArrayCollection();
  498.         $this->affiliatedEventApplications = new ArrayCollection();
  499.         $this->segmentations = new ArrayCollection();
  500.         $this->configurations = new ArrayCollection();
  501.         $this->restrictions = new ArrayCollection();
  502.         $this->orders = new ArrayCollection();
  503.         $this->categories = new ArrayCollection();
  504.         $this->channels = new ArrayCollection();
  505.         $this->exclusionsChannels = new ArrayCollection();
  506.         $this->exclusionsCategories = new ArrayCollection();
  507.         $this->exclusionsVideos = new ArrayCollection();
  508.         $this->logEmails = new ArrayCollection();
  509.         $this->associations = new ArrayCollection();
  510.         $this->programs = new ArrayCollection();
  511.         $this->teams = new ArrayCollection();
  512.         $this->teamplays = new ArrayCollection();
  513.         $this->teamplayChallenges = new ArrayCollection();
  514.         $this->teamplayLogs = new ArrayCollection();
  515.         $this->pedometerLogs = new ArrayCollection();
  516.         $this->logs = new ArrayCollection();
  517.         $this->userNotifications = new ArrayCollection();
  518.         $this->slides = new ArrayCollection();
  519.         $this->awards = new ArrayCollection();
  520.         $this->awardConfigs = new ArrayCollection();
  521.     }
  522.     public function getId(): ?int
  523.     {
  524.         return $this->id;
  525.     }
  526.     public function getName(): ?string
  527.     {
  528.         return $this->name;
  529.     }
  530.     public function setName(?string $name): self
  531.     {
  532.         $this->name = $name;
  533.         if ($this->user instanceof User){
  534.             $this->user->setName($name);
  535.         }
  536.         return $this;
  537.     }
  538.     public function getImage(): ?string
  539.     {
  540.         return $this->image;
  541.     }
  542.     public function setImage(?string $image): self
  543.     {
  544.         $this->image = $image;
  545.         return $this;
  546.     }
  547.     public function getUpdatedAt(): ?\DateTime
  548.     {
  549.         return $this->updatedAt;
  550.     }
  551.     public function setUpdatedAt(?\DateTime $updatedAt): self
  552.     {
  553.         $this->updatedAt = $updatedAt;
  554.         return $this;
  555.     }
  556.     public function getUser(): ?User
  557.     {
  558.         return $this->user;
  559.     }
  560.     public function setUser(?User $user): self
  561.     {
  562.         $this->user = $user;
  563.         $this->setName($this->getName());
  564.         return $this;
  565.     }
  566.     /**
  567.      * @return File|null
  568.      */
  569.     public function getImageFile(): ?File
  570.     {
  571.         return $this->imageFile;
  572.     }
  573.     /**
  574.      * @param File|null $imageFile
  575.      * @return Company
  576.      */
  577.     public function setImageFile(?File $imageFile = null): self
  578.     {
  579.         $this->imageFile = $imageFile;
  580.         if ($imageFile) {
  581.             // if 'updatedAt' is not defined in your entity, use another property
  582.             $this->updatedAt = new \DateTime('now');
  583.         }
  584.         return $this;
  585.     }
  586.     /**
  587.      * @return Collection|Room[]
  588.      */
  589.     public function getRooms(): Collection
  590.     {
  591.         return $this->rooms;
  592.     }
  593.     public function addRoom(Room $room): self
  594.     {
  595.         if (!$this->rooms->contains($room)) {
  596.             $this->rooms[] = $room;
  597.             $room->setCompany($this);
  598.         }
  599.         return $this;
  600.     }
  601.     public function removeRoom(Room $room): self
  602.     {
  603.         if ($this->rooms->removeElement($room)) {
  604.             // set the owning side to null (unless already changed)
  605.             if ($room->getCompany() === $this) {
  606.                 $room->setCompany(null);
  607.             }
  608.         }
  609.         return $this;
  610.     }
  611.     /**
  612.      * @return Collection|Workshop[]
  613.      */
  614.     public function getWorkshops(): Collection
  615.     {
  616.         return $this->workshops;
  617.     }
  618.     public function addWorkshop(Workshop $workshop): self
  619.     {
  620.         if (!$this->workshops->contains($workshop)) {
  621.             $this->workshops[] = $workshop;
  622.             $workshop->setCompany($this);
  623.         }
  624.         return $this;
  625.     }
  626.     public function removeWorkshop(Workshop $workshop): self
  627.     {
  628.         if ($this->workshops->removeElement($workshop)) {
  629.             // set the owning side to null (unless already changed)
  630.             if ($workshop->getCompany() === $this) {
  631.                 $workshop->setCompany(null);
  632.             }
  633.         }
  634.         return $this;
  635.     }
  636.     /**
  637.      * @ORM\PrePersist()
  638.      */
  639.     public function prePersist()
  640.     {
  641.         $this->user->setCategory(User::GROUP_COMPANY);
  642.         $this->user->addRole(User::ROLE_COMPANY);
  643.     }
  644.     public function __toString()
  645.     {
  646.         return $this->name??'';
  647.     }
  648.     /**
  649.      * @return Collection|Client[]
  650.      */
  651.     public function getClients(): Collection
  652.     {
  653.         return $this->clients;
  654.     }
  655.     public function addClient(Client $client): self
  656.     {
  657.         if (!$this->clients->contains($client)) {
  658.             $this->clients[] = $client;
  659.             $client->setCompany($this);
  660.         }
  661.         return $this;
  662.     }
  663.     public function removeClient(Client $client): self
  664.     {
  665.         if ($this->clients->removeElement($client)) {
  666.             // set the owning side to null (unless already changed)
  667.             if ($client->getCompany() === $this) {
  668.                 $client->setCompany(null);
  669.             }
  670.         }
  671.         return $this;
  672.     }
  673.     /**
  674.      * @return Collection|Event[]
  675.      */
  676.     public function getEvents(): Collection
  677.     {
  678.         return $this->events;
  679.     }
  680.     public function addEvent(Event $event): self
  681.     {
  682.         if (!$this->events->contains($event)) {
  683.             $this->events[] = $event;
  684.             $event->setCompany($this);
  685.         }
  686.         return $this;
  687.     }
  688.     public function removeEvent(Event $event): self
  689.     {
  690.         if ($this->events->removeElement($event)) {
  691.             // set the owning side to null (unless already changed)
  692.             if ($event->getCompany() === $this) {
  693.                 $event->setCompany(null);
  694.             }
  695.         }
  696.         return $this;
  697.     }
  698.     /**
  699.      * @return Collection|CompanyTag[]
  700.      */
  701.     public function getCompanyTags(): Collection
  702.     {
  703.         return $this->companyTags;
  704.     }
  705.     public function setCompanyTags(array $companyTags): self
  706.     {
  707.         $this->companyTags = new ArrayCollection();
  708.         if (is_array($companyTags)){
  709.             $this->companyTags = new ArrayCollection($companyTags);
  710.         }
  711.         return $this;
  712.     }
  713.     public function addCompanyTag(CompanyTag $companyTag): self
  714.     {
  715.         if (!$this->companyTags->contains($companyTag)) {
  716.             $this->companyTags[] = $companyTag;
  717.             $companyTag->setCompany($this);
  718.         }
  719.         return $this;
  720.     }
  721.     public function removeCompanyTag(CompanyTag $companyTag): self
  722.     {
  723.         if ($this->companyTags->removeElement($companyTag)) {
  724.             // set the owning side to null (unless already changed)
  725.             if ($companyTag->getCompany() === $this) {
  726.                 $companyTag->setCompany(null);
  727.             }
  728.         }
  729.         return $this;
  730.     }
  731.     public function getPresentation(): ?string
  732.     {
  733.         return $this->presentation;
  734.     }
  735.     public function setPresentation(?string $presentation): self
  736.     {
  737.         $this->presentation = $presentation;
  738.         return $this;
  739.     }
  740.     public function getPresentationTitle(): ?string
  741.     {
  742.         return $this->presentationTitle;
  743.     }
  744.     public function setPresentationTitle(?string $presentationTitle): self
  745.     {
  746.         $this->presentationTitle = $presentationTitle;
  747.         return $this;
  748.     }
  749.     public function getSiret(): ?string
  750.     {
  751.         return $this->siret;
  752.     }
  753.     public function setSiret(?string $siret): self
  754.     {
  755.         $this->siret = $siret;
  756.         return $this;
  757.     }
  758.     public function getPhone(): ?string
  759.     {
  760.         return $this->phone;
  761.     }
  762.     public function setPhone(?string $phone): self
  763.     {
  764.         $this->phone = $phone;
  765.         return $this;
  766.     }
  767.     public function getCreatedAt(): ?\DateTime
  768.     {
  769.         return $this->createdAt;
  770.     }
  771.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  772.     {
  773.         $this->createdAt = $createdAt;
  774.         return $this;
  775.     }
  776.     public function getCompanyCode(): ?string
  777.     {
  778.         return $this->companyCode;
  779.     }
  780.     public function setCompanyCode(?string $companyCode): self
  781.     {
  782.         $this->companyCode = $companyCode;
  783.         return $this;
  784.     }
  785.     /**
  786.      * @return Collection<int, VisioEventPromotion>
  787.      */
  788.     public function getVisioEventPromotions(): Collection
  789.     {
  790.         return $this->visioEventPromotions;
  791.     }
  792.     public function addVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
  793.     {
  794.         if (!$this->visioEventPromotions->contains($visioEventPromotion)) {
  795.             $this->visioEventPromotions[] = $visioEventPromotion;
  796.             $visioEventPromotion->setCompany($this);
  797.         }
  798.         return $this;
  799.     }
  800.     public function removeVisioEventPromotion(VisioEventPromotion $visioEventPromotion): self
  801.     {
  802.         if ($this->visioEventPromotions->removeElement($visioEventPromotion)) {
  803.             // set the owning side to null (unless already changed)
  804.             if ($visioEventPromotion->getCompany() === $this) {
  805.                 $visioEventPromotion->setCompany(null);
  806.             }
  807.         }
  808.         return $this;
  809.     }
  810.     public function getVisioAllowed(): ?bool
  811.     {
  812.         return $this->visioAllowed;
  813.     }
  814.     public function setVisioAllowed(?bool $visioAllowed): self
  815.     {
  816.         $this->visioAllowed = $visioAllowed;
  817.         return $this;
  818.     }
  819.     public function getVisioPaymentAllowed(): ?bool
  820.     {
  821.         return $this->visioPaymentAllowed;
  822.     }
  823.     public function setVisioPaymentAllowed(bool $visioPaymentAllowed): self
  824.     {
  825.         $this->visioPaymentAllowed = $visioPaymentAllowed;
  826.         return $this;
  827.     }
  828.     /**
  829.      * @return Collection<int, Specialist>
  830.      */
  831.     public function getAffiliatedSpecialists(): Collection
  832.     {
  833.         return $this->affiliatedSpecialists;
  834.     }
  835.     public function addAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
  836.     {
  837.         if (!$this->affiliatedSpecialists->contains($affiliatedSpecialist)) {
  838.             $this->affiliatedSpecialists[] = $affiliatedSpecialist;
  839.             $affiliatedSpecialist->setAffiliatedCompany($this);
  840.         }
  841.         return $this;
  842.     }
  843.     public function removeAffiliatedSpecialist(Specialist $affiliatedSpecialist): self
  844.     {
  845.         if ($this->affiliatedSpecialists->removeElement($affiliatedSpecialist)) {
  846.             // set the owning side to null (unless already changed)
  847.             if ($affiliatedSpecialist->getAffiliatedCompany() === $this) {
  848.                 $affiliatedSpecialist->setAffiliatedCompany(null);
  849.             }
  850.         }
  851.         return $this;
  852.     }
  853.     /**
  854.      * @return Collection<int, Specialist>
  855.      */
  856.     public function getSpecialists(): Collection
  857.     {
  858.         return $this->specialists;
  859.     }
  860.     public function addSpecialist(Specialist $specialist): self
  861.     {
  862.         if (!$this->specialists->contains($specialist)) {
  863.             $this->specialists[] = $specialist;
  864.             $specialist->addCompany($this);
  865.         }
  866.         return $this;
  867.     }
  868.     public function removeSpecialist(Specialist $specialist): self
  869.     {
  870.         if ($this->specialists->removeElement($specialist)) {
  871.             $specialist->removeCompany($this);
  872.         }
  873.         return $this;
  874.     }
  875.     /**
  876.      * @return Collection<int, AffiliatedEventApplication>
  877.      */
  878.     public function getAffiliatedEventApplications(): Collection
  879.     {
  880.         return $this->affiliatedEventApplications;
  881.     }
  882.     public function addAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
  883.     {
  884.         if (!$this->affiliatedEventApplications->contains($affiliatedEventApplication)) {
  885.             $this->affiliatedEventApplications[] = $affiliatedEventApplication;
  886.             $affiliatedEventApplication->setCompany($this);
  887.         }
  888.         return $this;
  889.     }
  890.     public function removeAffiliatedEventApplication(AffiliatedEventApplication $affiliatedEventApplication): self
  891.     {
  892.         if ($this->affiliatedEventApplications->removeElement($affiliatedEventApplication)) {
  893.             // set the owning side to null (unless already changed)
  894.             if ($affiliatedEventApplication->getCompany() === $this) {
  895.                 $affiliatedEventApplication->setCompany(null);
  896.             }
  897.         }
  898.         return $this;
  899.     }
  900.     /**
  901.      * @return Collection<int, Segmentation>
  902.      */
  903.     public function getSegmentations(): Collection
  904.     {
  905.         return $this->segmentations;
  906.     }
  907.     public function addSegmentation(Segmentation $segmentation): self
  908.     {
  909.         if (!$this->segmentations->contains($segmentation)) {
  910.             $this->segmentations[] = $segmentation;
  911.             $segmentation->setCompany($this);
  912.         }
  913.         return $this;
  914.     }
  915.     public function removeSegmentation(Segmentation $segmentation): self
  916.     {
  917.         if ($this->segmentations->removeElement($segmentation)) {
  918.             // set the owning side to null (unless already changed)
  919.             if ($segmentation->getCompany() === $this) {
  920.                 $segmentation->setCompany(null);
  921.             }
  922.         }
  923.         return $this;
  924.     }
  925.     public function getForceSegmentation(): ?bool
  926.     {
  927.         return $this->forceSegmentation;
  928.     }
  929.     public function setForceSegmentation(?bool $forceSegmentation): self
  930.     {
  931.         $this->forceSegmentation = $forceSegmentation;
  932.         return $this;
  933.     }
  934.     /**
  935.      * @return Collection<int, Configuration>
  936.      */
  937.     public function getConfigurations(): Collection
  938.     {
  939.         return $this->configurations;
  940.     }
  941.     public function addConfiguration(Configuration $configuration): self
  942.     {
  943.         if (!$this->configurations->contains($configuration)) {
  944.             $this->configurations[] = $configuration;
  945.             $configuration->setCompany($this);
  946.         }
  947.         return $this;
  948.     }
  949.     public function removeConfiguration(Configuration $configuration): self
  950.     {
  951.         if ($this->configurations->removeElement($configuration)) {
  952.             // set the owning side to null (unless already changed)
  953.             if ($configuration->getCompany() === $this) {
  954.                 $configuration->setCompany(null);
  955.             }
  956.         }
  957.         return $this;
  958.     }
  959.     public function getLogo(): ?MediaObject
  960.     {
  961.         return $this->logo;
  962.     }
  963.     public function setLogo(?MediaObject $logo): self
  964.     {
  965.         $this->logo = $logo;
  966.         return $this;
  967.     }
  968.     /**
  969.      * @Groups({"company:write"})
  970.      */
  971.     public function setLogoFile($file = null): self
  972.     {
  973.         if($file instanceof UploadedFile) {
  974.             $logo = empty($this->logo) ? new MediaObject : $this->logo;
  975.             $logo->setFile($file);
  976.             $this->setLogo($logo);
  977.         }
  978.         return $this;
  979.     }
  980.     public function getSiren(): ?string
  981.     {
  982.         return $this->siren;
  983.     }
  984.     public function setSiren(?string $siren): self
  985.     {
  986.         $this->siren = $siren;
  987.         return $this;
  988.     }
  989.     public function setStatus(?string $status): self
  990.     {
  991.         $this->status = $status;
  992.         if (in_array($this->status, [self::STATUS_SUSPENDED, self::STATUS_EXPIRED, self::STATUS_INACTIVE])) {
  993.             $this->active = false;
  994.         } else {
  995.             $this->active = true;
  996.         }
  997.         return $this;
  998.     }
  999.     /**
  1000.      * @return string
  1001.      */
  1002.     public function getStatus(): string
  1003.     {
  1004.         return $this->status;
  1005.     }
  1006.     public function getActive(): ?bool
  1007.     {
  1008.         return $this->active;
  1009.     }
  1010.     public function isActive(): ?bool
  1011.     {
  1012.         return $this->active;
  1013.     }
  1014.     public function setActive(?bool $active): self
  1015.     {
  1016.         $this->active = $active;
  1017.         return $this;
  1018.     }
  1019.     public function getSubscriptionStart(): ?\DateTimeInterface
  1020.     {
  1021.         return $this->subscriptionStart;
  1022.     }
  1023.     public function setSubscriptionStart(?\DateTimeInterface $subscriptionStart): self
  1024.     {
  1025.         $this->subscriptionStart = $subscriptionStart;
  1026.         return $this;
  1027.     }
  1028.     public function getSubscriptionEnd(): ?\DateTimeInterface
  1029.     {
  1030.         return $this->subscriptionEnd;
  1031.     }
  1032.     public function setSubscriptionEnd(?\DateTimeInterface $subscriptionEnd): self
  1033.     {
  1034.         $this->subscriptionEnd = $subscriptionEnd;
  1035.         return $this;
  1036.     }
  1037.     /**
  1038.      * Gets the active order no more than an order can be active at a time for a company
  1039.      * @return Order|null
  1040.      */
  1041.     public function getActiveOrder(): ?Order
  1042.     {
  1043.         foreach ($this->orders as $order) {
  1044.             if ($order instanceof Order && $order->getActive()) {
  1045.                 return $order;
  1046.             }
  1047.         }
  1048.         return null;
  1049.     }
  1050.     /**
  1051.      * Updates the entity including users count, created at and updated at elements
  1052.      * and the start and the end of the subscription
  1053.      * @return company
  1054.      * @ORM\PrePersist
  1055.      */
  1056.     public function updateEntity(): self
  1057.     {
  1058.         $this->updateSubscription();
  1059.         $this->updateStatus();
  1060.         $this->updateClientsCount();
  1061.         $this->updatedAt = new \DateTime();
  1062.         return $this;
  1063.     }
  1064.     /**
  1065.      * Updates the count of the company users
  1066.      */
  1067.     private function updateClientsCount()
  1068.     {
  1069.         $this->clientsCount = $this->clients->count();
  1070.     }
  1071.     /**
  1072.      * Updates subscription dates
  1073.      */
  1074.     private function updateSubscription()
  1075.     {
  1076.         $order = $this->getActiveOrder();
  1077.         if ($order instanceof Order) {
  1078.             $this->subscriptionEnd = $order->getEnd();
  1079.             $this->subscriptionStart = $order->getStart();
  1080.         }
  1081.     }
  1082.     /**
  1083.      * Updates the status of the company
  1084.      */
  1085.     private function updateStatus()
  1086.     {
  1087.         $ret = self::STATUS_ACTIVE;
  1088.         if ($this->subscriptionEnd < (new \DateTime())) {
  1089.             $ret = self::STATUS_EXPIRED;
  1090.         }
  1091.         if (!$this->active) {
  1092.             $ret = self::STATUS_SUSPENDED;
  1093.         }
  1094.         $this->status = $ret;
  1095.     }
  1096.     public function getMessages(): ?array
  1097.     {
  1098.         if (!is_array($this->messages)) {
  1099.             $this->messages = [];
  1100.         }
  1101.         return $this->messages;
  1102.     }
  1103.     /**
  1104.      * Gets a message if it exists
  1105.      * @param string $key
  1106.      * @return string|null
  1107.      */
  1108.     public function getMessage(string $key): ?string
  1109.     {
  1110.         $_messages = $this->getMessages();
  1111.         return (!empty($_messages[$key])) ? $_messages[$key] : null;
  1112.     }
  1113.     public function setMessages(?array $messages): self
  1114.     {
  1115.         $this->messages = $messages;
  1116.         return $this;
  1117.     }
  1118.     public function getMaxClients(): ?int
  1119.     {
  1120.         return $this->maxClients;
  1121.     }
  1122.     public function setMaxClients(?int $maxClients): self
  1123.     {
  1124.         $this->maxClients = $maxClients;
  1125.         return $this;
  1126.     }
  1127.     public function getPlan(): ?string
  1128.     {
  1129.         return $this->plan;
  1130.     }
  1131.     public function setPlan(?string $plan): self
  1132.     {
  1133.         $this->plan = $plan;
  1134.         return $this;
  1135.     }
  1136.     public function getSlug(): ?string
  1137.     {
  1138.         return $this->slug;
  1139.     }
  1140.     public function setSlug(?string $slug): self
  1141.     {
  1142.         $this->slug = $slug;
  1143.         return $this;
  1144.     }
  1145.     public function getIps(): ?array
  1146.     {
  1147.         return $this->ips;
  1148.     }
  1149.     public function setIps(?array $ips): self
  1150.     {
  1151.         $this->ips = $ips;
  1152.         return $this;
  1153.     }
  1154.     public function getDomain(): ?array
  1155.     {
  1156.         return $this->domain;
  1157.     }
  1158.     public function setDomain(?array $domain): self
  1159.     {
  1160.         $this->domain = $domain;
  1161.         return $this;
  1162.     }
  1163.     public function getHourlyRestriction(): ?int
  1164.     {
  1165.         return $this->hourlyRestriction;
  1166.     }
  1167.     public function setHourlyRestriction($hourlyRestriction): self
  1168.     {
  1169.         if (is_bool($hourlyRestriction)) {
  1170.             if ($hourlyRestriction) {
  1171.                 $hourlyRestriction = 5;
  1172.             } else {
  1173.                 $hourlyRestriction = 0;
  1174.             }
  1175.         }
  1176.         $this->hourlyRestriction = $hourlyRestriction;
  1177.         return $this;
  1178.     }
  1179.     public function getCustomizable(): ?bool
  1180.     {
  1181.         return $this->customizable;
  1182.     }
  1183.     public function isCustomizable(): bool
  1184.     {
  1185.         return boolval($this->customizable);
  1186.     }
  1187.     public function setCustomizable(bool $customizable): self
  1188.     {
  1189.         $this->customizable = $customizable;
  1190.         return $this;
  1191.     }
  1192.     public function getCms(): ?string
  1193.     {
  1194.         return $this->cms;
  1195.     }
  1196.     public function setCms(?string $cms): self
  1197.     {
  1198.         $this->cms = $cms;
  1199.         return $this;
  1200.     }
  1201.     public function getCmsTitle(): ?string
  1202.     {
  1203.         return $this->cmsTitle;
  1204.     }
  1205.     public function setCmsTitle(?string $cmsTitle): self
  1206.     {
  1207.         $this->cmsTitle = $cmsTitle;
  1208.         return $this;
  1209.     }
  1210.     public function getCmsImg(): ?MediaObject
  1211.     {
  1212.         return $this->cmsImg;
  1213.     }
  1214.     public function setCmsImg(?MediaObject $cmsImg): self
  1215.     {
  1216.         $this->cmsImg = $cmsImg;
  1217.         return $this;
  1218.     }
  1219.     /**
  1220.      * @Groups({"company:write"})
  1221.      */
  1222.     public function setCmsImgFile($file = null): self
  1223.     {
  1224.         if($file instanceof UploadedFile) {
  1225.             $cmsImg = empty($this->cmsImg) ? new MediaObject : $this->cmsImg;
  1226.             $cmsImg->setFile($file);
  1227.             $this->setCmsImg($cmsImg);
  1228.         }
  1229.         return $this;
  1230.     }
  1231.     public function getCmsText(): ?string
  1232.     {
  1233.         return $this->cmsText;
  1234.     }
  1235.     public function setCmsText(?string $cmsText): self
  1236.     {
  1237.         $this->cmsText = $cmsText;
  1238.         return $this;
  1239.     }
  1240.     public function getCmsCtaText(): ?string
  1241.     {
  1242.         return $this->cmsCtaText;
  1243.     }
  1244.     public function setCmsCtaText(?string $cmsCtaText): self
  1245.     {
  1246.         $this->cmsCtaText = $cmsCtaText;
  1247.         return $this;
  1248.     }
  1249.     public function getCmsCtaUrl(): ?string
  1250.     {
  1251.         return $this->cmsCtaUrl;
  1252.     }
  1253.     public function setCmsCtaUrl(?string $cmsCtaUrl): self
  1254.     {
  1255.         $this->cmsCtaUrl = $cmsCtaUrl;
  1256.         return $this;
  1257.     }
  1258.     public function getResaLinkActive(): ?bool
  1259.     {
  1260.         return $this->resaLinkActive;
  1261.     }
  1262.     public function setResaLinkActive(?bool $resaLinkActive): self
  1263.     {
  1264.         $this->resaLinkActive = $resaLinkActive;
  1265.         return $this;
  1266.     }
  1267.     public function getEmail(): ?string
  1268.     {
  1269.         return $this->email;
  1270.     }
  1271.     public function setEmail(?string $email): self
  1272.     {
  1273.         $this->email = $email;
  1274.         return $this;
  1275.     }
  1276.     /**
  1277.      * @return Collection|Restriction[]
  1278.      */
  1279.     public function getRestrictions(): Collection
  1280.     {
  1281.         return $this->restrictions;
  1282.     }
  1283.     public function addRestriction(Restriction $restriction): self
  1284.     {
  1285.         if (!$this->restrictions->contains($restriction)) {
  1286.             $this->restrictions[] = $restriction;
  1287.             $restriction->setCompany($this);
  1288.         }
  1289.         return $this;
  1290.     }
  1291.     public function removeRestriction(Restriction $restriction): self
  1292.     {
  1293.         if ($this->restrictions->removeElement($restriction)) {
  1294.             // set the owning side to null (unless already changed)
  1295.             if ($restriction->getCompany() === $this) {
  1296.                 $restriction->setCompany(null);
  1297.             }
  1298.         }
  1299.         return $this;
  1300.     }
  1301.     /**
  1302.      * @return Collection|Order[]
  1303.      */
  1304.     public function getOrders(): Collection
  1305.     {
  1306.         return $this->orders;
  1307.     }
  1308.     public function addOrder(Order $order): self
  1309.     {
  1310.         if (!$this->orders->contains($order)) {
  1311.             $this->orders[] = $order;
  1312.             $order->setCompany($this);
  1313.         }
  1314.         return $this;
  1315.     }
  1316.     public function removeOrder(Order $order): self
  1317.     {
  1318.         if ($this->orders->removeElement($order)) {
  1319.             // set the owning side to null (unless already changed)
  1320.             if ($order->getCompany() === $this) {
  1321.                 $order->setCompany(null);
  1322.             }
  1323.         }
  1324.         return $this;
  1325.     }
  1326.     /**
  1327.      * @return Collection|Category[]
  1328.      */
  1329.     public function getCategories(): Collection
  1330.     {
  1331.         return $this->categories;
  1332.     }
  1333.     public function addCategory(Category $category): self
  1334.     {
  1335.         if (!$this->categories->contains($category)) {
  1336.             $this->categories[] = $category;
  1337.             $category->setCompany($this);
  1338.         }
  1339.         return $this;
  1340.     }
  1341.     public function removeCategory(Category $category): self
  1342.     {
  1343.         if ($this->categories->removeElement($category)) {
  1344.             // set the owning side to null (unless already changed)
  1345.             if ($category->getCompany() === $this) {
  1346.                 $category->setCompany(null);
  1347.             }
  1348.         }
  1349.         return $this;
  1350.     }
  1351.     /**
  1352.      * @return Collection|Channel[]
  1353.      */
  1354.     public function getChannels(): Collection
  1355.     {
  1356.         return $this->channels;
  1357.     }
  1358.     public function addChannel(Channel $channel): self
  1359.     {
  1360.         if (!$this->channels->contains($channel)) {
  1361.             $this->channels[] = $channel;
  1362.             $channel->setCompany($this);
  1363.         }
  1364.         return $this;
  1365.     }
  1366.     public function removeChannel(Channel $channel): self
  1367.     {
  1368.         if ($this->channels->removeElement($channel)) {
  1369.             // set the owning side to null (unless already changed)
  1370.             if ($channel->getCompany() === $this) {
  1371.                 $channel->setCompany(null);
  1372.             }
  1373.         }
  1374.         return $this;
  1375.     }
  1376.     /**
  1377.      * @return Collection|ExclusionsChannel[]
  1378.      */
  1379.     public function getExclusionsChannels(): Collection
  1380.     {
  1381.         return $this->exclusionsChannels;
  1382.     }
  1383.     public function addExclusionsChannel(ExclusionsChannel $exclusionsChannel): self
  1384.     {
  1385.         if (!$this->exclusionsChannels->contains($exclusionsChannel)) {
  1386.             $this->exclusionsChannels[] = $exclusionsChannel;
  1387.             $exclusionsChannel->setCompany($this);
  1388.         }
  1389.         return $this;
  1390.     }
  1391.     public function removeExclusionsChannel(ExclusionsChannel $exclusionsChannel): self
  1392.     {
  1393.         if ($this->exclusionsChannels->removeElement($exclusionsChannel)) {
  1394.             // set the owning side to null (unless already changed)
  1395.             if ($exclusionsChannel->getCompany() === $this) {
  1396.                 $exclusionsChannel->setCompany(null);
  1397.             }
  1398.         }
  1399.         return $this;
  1400.     }
  1401.     /**
  1402.      * @return Collection|ExclusionsCategory[]
  1403.      */
  1404.     public function getExclusionsCategories(): Collection
  1405.     {
  1406.         return $this->exclusionsCategories;
  1407.     }
  1408.     public function addExclusionsCategory(ExclusionsCategory $exclusionsCategory): self
  1409.     {
  1410.         if (!$this->exclusionsCategories->contains($exclusionsCategory)) {
  1411.             $this->exclusionsCategories[] = $exclusionsCategory;
  1412.             $exclusionsCategory->setCompany($this);
  1413.         }
  1414.         return $this;
  1415.     }
  1416.     public function removeExclusionsCategory(ExclusionsCategory $exclusionsCategory): self
  1417.     {
  1418.         if ($this->exclusionsCategories->removeElement($exclusionsCategory)) {
  1419.             // set the owning side to null (unless already changed)
  1420.             if ($exclusionsCategory->getCompany() === $this) {
  1421.                 $exclusionsCategory->setCompany(null);
  1422.             }
  1423.         }
  1424.         return $this;
  1425.     }
  1426.     /**
  1427.      * @return Collection|ExclusionsVideo[]
  1428.      */
  1429.     public function getExclusionsVideos(): Collection
  1430.     {
  1431.         return $this->exclusionsVideos;
  1432.     }
  1433.     public function addExclusionsVideo(ExclusionsVideo $exclusionsVideo): self
  1434.     {
  1435.         if (!$this->exclusionsVideos->contains($exclusionsVideo)) {
  1436.             $this->exclusionsVideos[] = $exclusionsVideo;
  1437.             $exclusionsVideo->setCompany($this);
  1438.         }
  1439.         return $this;
  1440.     }
  1441.     public function removeExclusionsVideo(ExclusionsVideo $exclusionsVideo): self
  1442.     {
  1443.         if ($this->exclusionsVideos->removeElement($exclusionsVideo)) {
  1444.             // set the owning side to null (unless already changed)
  1445.             if ($exclusionsVideo->getCompany() === $this) {
  1446.                 $exclusionsVideo->setCompany(null);
  1447.             }
  1448.         }
  1449.         return $this;
  1450.     }
  1451.     /**
  1452.      * Permet de savoir si l'abonnement est actif ou non.
  1453.      * @return bool
  1454.      */
  1455.     public function hasCurrentSubscription(): bool
  1456.     {
  1457.         $hasCurrentSubscription = false;
  1458.         if($this->checkSubscriptionsDates(new \DateTime("now"))) {
  1459.             $hasCurrentSubscription = true;
  1460.         }
  1461.         return $hasCurrentSubscription;
  1462.     }
  1463.     public function checkSubscriptionsDates(\DateTime $today)
  1464.     {
  1465.         return $today >= $this->subscriptionStart && $today <= $this->subscriptionEnd;
  1466.     }
  1467.     /**
  1468.      * @return Collection|LogEmail[]
  1469.      */
  1470.     public function getLogEmails(): Collection
  1471.     {
  1472.         return $this->logEmails;
  1473.     }
  1474.     public function addLogEmail(LogEmail $logEmail): self
  1475.     {
  1476.         if (!$this->logEmails->contains($logEmail)) {
  1477.             $this->logEmails[] = $logEmail;
  1478.             $logEmail->setCompany($this);
  1479.         }
  1480.         return $this;
  1481.     }
  1482.     public function removeLogEmail(LogEmail $logEmail): self
  1483.     {
  1484.         if ($this->logEmails->removeElement($logEmail)) {
  1485.             // set the owning side to null (unless already changed)
  1486.             if ($logEmail->getCompany() === $this) {
  1487.                 $logEmail->setCompany(null);
  1488.             }
  1489.         }
  1490.         return $this;
  1491.     }
  1492.     /**
  1493.      * @return Collection|Association[]
  1494.      */
  1495.     public function getAssociations(): Collection
  1496.     {
  1497.         return $this->associations;
  1498.     }
  1499.     public function addAssociation(Association $association): self
  1500.     {
  1501.         if (!$this->associations->contains($association)) {
  1502.             $this->associations[] = $association;
  1503.         }
  1504.         return $this;
  1505.     }
  1506.     public function removeAssociation(Association $association): self
  1507.     {
  1508.         $this->associations->removeElement($association);
  1509.         return $this;
  1510.     }
  1511.     /**
  1512.      * @return Collection|Program[]
  1513.      */
  1514.     public function getPrograms(): Collection
  1515.     {
  1516.         return $this->programs;
  1517.     }
  1518.     public function addProgram(Program $program): self
  1519.     {
  1520.         if (!$this->programs->contains($program)) {
  1521.             $this->programs[] = $program;
  1522.             $program->setCompany($this);
  1523.         }
  1524.         return $this;
  1525.     }
  1526.     public function removeProgram(Program $program): self
  1527.     {
  1528.         if ($this->programs->removeElement($program)) {
  1529.             // set the owning side to null (unless already changed)
  1530.             if ($program->getCompany() === $this) {
  1531.                 $program->setCompany(null);
  1532.             }
  1533.         }
  1534.         return $this;
  1535.     }
  1536.     /**
  1537.      * @return Collection|Team[]
  1538.      */
  1539.     public function getTeams(): Collection
  1540.     {
  1541.         return $this->teams;
  1542.     }
  1543.     public function addTeam(Team $team): self
  1544.     {
  1545.         if (!$this->teams->contains($team)) {
  1546.             $this->teams[] = $team;
  1547.             $team->setCompany($this);
  1548.         }
  1549.         return $this;
  1550.     }
  1551.     public function removeTeam(Team $team): self
  1552.     {
  1553.         if ($this->teams->removeElement($team)) {
  1554.             // set the owning side to null (unless already changed)
  1555.             if ($team->getCompany() === $this) {
  1556.                 $team->setCompany(null);
  1557.             }
  1558.         }
  1559.         return $this;
  1560.     }
  1561.     /**
  1562.      * RĂ©cupère un array de team de type = "teamplay"
  1563.      * @return Team[]|null
  1564.      */
  1565.     public function getTeamplayTeams(): ?array
  1566.     {
  1567.         $teamplayTeams = null;
  1568.         if (!empty($this->teams->toArray())) {
  1569.             $teamplayTeams = [];
  1570.             foreach ($this->teams->toArray() as $team) {
  1571.                 if ($team->isTeamplay()) $teamplayTeams[] = $team;
  1572.             }
  1573.         }
  1574.         return $teamplayTeams;
  1575.     }
  1576.     /**
  1577.      * @return Collection|Teamplay[]
  1578.      */
  1579.     public function getTeamplays(): Collection
  1580.     {
  1581.         return $this->teamplays;
  1582.     }
  1583.     public function addTeamplay(Teamplay $teamplay): self
  1584.     {
  1585.         if (!$this->teamplays->contains($teamplay)) {
  1586.             $this->teamplays[] = $teamplay;
  1587.             $teamplay->setCompany($this);
  1588.         }
  1589.         return $this;
  1590.     }
  1591.     public function removeTeamplay(Teamplay $teamplay): self
  1592.     {
  1593.         if ($this->teamplays->removeElement($teamplay)) {
  1594.             // set the owning side to null (unless already changed)
  1595.             if ($teamplay->getCompany() === $this) {
  1596.                 $teamplay->setCompany(null);
  1597.             }
  1598.         }
  1599.         return $this;
  1600.     }
  1601.     /**
  1602.      * @return Collection|TeamplayChallenge[]
  1603.      */
  1604.     public function getTeamplayChallenges(): Collection
  1605.     {
  1606.         return $this->teamplayChallenges;
  1607.     }
  1608.     public function addTeamplayChallenge(TeamplayChallenge $teamplayChallenge): self
  1609.     {
  1610.         if (!$this->teamplayChallenges->contains($teamplayChallenge)) {
  1611.             $this->teamplayChallenges[] = $teamplayChallenge;
  1612.             $teamplayChallenge->setCompany($this);
  1613.         }
  1614.         return $this;
  1615.     }
  1616.     public function removeTeamplayChallenge(TeamplayChallenge $teamplayChallenge): self
  1617.     {
  1618.         if ($this->teamplayChallenges->removeElement($teamplayChallenge)) {
  1619.             // set the owning side to null (unless already changed)
  1620.             if ($teamplayChallenge->getCompany() === $this) {
  1621.                 $teamplayChallenge->setCompany(null);
  1622.             }
  1623.         }
  1624.         return $this;
  1625.     }
  1626.     
  1627.     /**
  1628.      * @return Collection|TeamplayLog[]
  1629.      */
  1630.     public function getTeamplayLogs(): Collection
  1631.     {
  1632.         return $this->teamplayLogs;
  1633.     }
  1634.     public function addTeamplayLog(TeamplayLog $teamplayLog): self
  1635.     {
  1636.         if (!$this->teamplayLogs->contains($teamplayLog)) {
  1637.             $this->teamplayLogs[] = $teamplayLog;
  1638.             $teamplayLog->setCompany($this);
  1639.         }
  1640.         return $this;
  1641.     }
  1642.     public function removeTeamplayLog(TeamplayLog $teamplayLog): self
  1643.     {
  1644.         if ($this->teamplayLogs->removeElement($teamplayLog)) {
  1645.             // set the owning side to null (unless already changed)
  1646.             if ($teamplayLog->getCompany() === $this) {
  1647.                 $teamplayLog->setCompany(null);
  1648.             }
  1649.         }
  1650.         return $this;
  1651.     }
  1652.     /**
  1653.      * @return Collection|PedometerLog[]
  1654.      */
  1655.     public function getPedometerLogs(): Collection
  1656.     {
  1657.         return $this->pedometerLogs;
  1658.     }
  1659.     public function addPedometerLog(PedometerLog $pedometerLog): self
  1660.     {
  1661.         if (!$this->pedometerLogs->contains($pedometerLog)) {
  1662.             $this->pedometerLogs[] = $pedometerLog;
  1663.             $pedometerLog->setCompany($this);
  1664.         }
  1665.         return $this;
  1666.     }
  1667.     public function removePedometerLog(PedometerLog $pedometerLog): self
  1668.     {
  1669.         if ($this->pedometerLogs->removeElement($pedometerLog)) {
  1670.             // set the owning side to null (unless already changed)
  1671.             if ($pedometerLog->getCompany() === $this) {
  1672.                 $pedometerLog->setCompany(null);
  1673.             }
  1674.         }
  1675.         return $this;
  1676.     }
  1677.     /**
  1678.      * @return Collection|Log[]
  1679.      */
  1680.     public function getLogs(): Collection
  1681.     {
  1682.         return $this->logs;
  1683.     }
  1684.     public function addLog(Log $log): self
  1685.     {
  1686.         if (!$this->logs->contains($log)) {
  1687.             $this->logs[] = $log;
  1688.             $log->setCompany($this);
  1689.         }
  1690.         return $this;
  1691.     }
  1692.     public function removeLog(Log $log): self
  1693.     {
  1694.         if ($this->logs->removeElement($log)) {
  1695.             // set the owning side to null (unless already changed)
  1696.             if ($log->getCompany() === $this) {
  1697.                 $log->setCompany(null);
  1698.             }
  1699.         }
  1700.         return $this;
  1701.     }
  1702.     /**
  1703.      * @return Collection<int, UserNotification>
  1704.      */
  1705.     public function getUserNotifications(): Collection
  1706.     {
  1707.         return $this->userNotifications;
  1708.     }
  1709.     public function addUserNotification(UserNotification $userNotification): self
  1710.     {
  1711.         if (!$this->userNotifications->contains($userNotification)) {
  1712.             $this->userNotifications[] = $userNotification;
  1713.             $userNotification->setCompany($this);
  1714.         }
  1715.         return $this;
  1716.     }
  1717.     public function removeUserNotification(UserNotification $userNotification): self
  1718.     {
  1719.         if ($this->userNotifications->removeElement($userNotification)) {
  1720.             // set the owning side to null (unless already changed)
  1721.             if ($userNotification->getCompany() === $this) {
  1722.                 $userNotification->setCompany(null);
  1723.             }
  1724.         }
  1725.         return $this;
  1726.     }
  1727.     /**
  1728.      * @return Collection<int, Slide>
  1729.      */
  1730.     public function getSlides(): Collection
  1731.     {
  1732.         return $this->slides;
  1733.     }
  1734.     public function addSlide(Slide $slide): self
  1735.     {
  1736.         if (!$this->slides->contains($slide)) {
  1737.             $this->slides[] = $slide;
  1738.             $slide->setCompany($this);
  1739.         }
  1740.         return $this;
  1741.     }
  1742.     public function removeSlide(Slide $slide): self
  1743.     {
  1744.         if ($this->slides->removeElement($slide)) {
  1745.             // set the owning side to null (unless already changed)
  1746.             if ($slide->getCompany() === $this) {
  1747.                 $slide->setCompany(null);
  1748.             }
  1749.         }
  1750.         return $this;
  1751.     }
  1752.     /**
  1753.      * @return Collection|Award[]
  1754.      */
  1755.     public function getAwards(): Collection
  1756.     {
  1757.         return $this->awards;
  1758.     }
  1759.     public function addAward(Award $award): self
  1760.     {
  1761.         if (!$this->awards->contains($award)) {
  1762.             $this->awards[] = $award;
  1763.             $award->addCompany($this);
  1764.         }
  1765.         return $this;
  1766.     }
  1767.     public function removeAward(Award $award): self
  1768.     {
  1769.         if ($this->awards->removeElement($award)) {
  1770.             $award->removeCompany($this);
  1771.         }
  1772.         return $this;
  1773.     }
  1774.     /**
  1775.      * @Groups({"company:read", "compny:read:activeAward"})
  1776.      */
  1777.     public function getActiveAward()
  1778.     {
  1779.         $award = null;
  1780.         $today = (new \DateTime("now"))->setTime(0, 0, 0);
  1781.         foreach ($this->awards->toArray() as $value) {
  1782.             if ($value->getActive() && $value->getDateStart() <= $today  && $value->getDateEnd() >= $today) {
  1783.                 $award = $value;
  1784.             }
  1785.         }
  1786.         return $award;
  1787.     }
  1788.     /**
  1789.      * @return Collection<int, AwardConfig>
  1790.      */
  1791.     public function getAwardConfigs(): Collection
  1792.     {
  1793.         return $this->awardConfigs;
  1794.     }
  1795.     public function addAwardConfig(AwardConfig $awardConfig): self
  1796.     {
  1797.         if (!$this->awardConfigs->contains($awardConfig)) {
  1798.             $this->awardConfigs[] = $awardConfig;
  1799.             $awardConfig->setCompany($this);
  1800.         }
  1801.         return $this;
  1802.     }
  1803.     public function removeAwardConfig(AwardConfig $awardConfig): self
  1804.     {
  1805.         if ($this->awardConfigs->removeElement($awardConfig)) {
  1806.             // set the owning side to null (unless already changed)
  1807.             if ($awardConfig->getCompany() === $this) {
  1808.                 $awardConfig->setCompany(null);
  1809.             }
  1810.         }
  1811.         return $this;
  1812.     }
  1813.     
  1814.     public function getClientsCount(): ?int
  1815.     {
  1816.         return $this->clientsCount;
  1817.     }
  1818.     public function setClientsCount(int $clientsCount): self
  1819.     {
  1820.         $this->clientsCount = $clientsCount;
  1821.         return $this;
  1822.     }
  1823.     public function getTvCompany(): ?TvCompany
  1824.     {
  1825.         return $this->tvCompany;
  1826.     }
  1827.     public function setTvCompany(?TvCompany $tvCompany): self
  1828.     {
  1829.         $this->tvCompany = $tvCompany;
  1830.         return $this;
  1831.     }
  1832.     public function isLive(): ?bool
  1833.     {
  1834.         return $this->live;
  1835.     }
  1836.     public function setLive(bool $isLive): self
  1837.     {
  1838.         $this->live = $isLive;
  1839.         $this->getUser()->setLive($isLive);
  1840.         $this->getUser()->setUpdatedAt(new \DateTime("now"));
  1841.         // if(!$this->getClients()->isEmpty()) {
  1842.         //     foreach($this->getClients()->toArray() as  $client) {
  1843.         //         if($client instanceof Client && $client->getUser() instanceof User) {
  1844.         //             $user = $client->getUser();
  1845.         //             $user->setLive($isLive);
  1846.         //             $user->setUpdatedAt(new \DateTime("now"));
  1847.         //         }
  1848.         //     }
  1849.         // }
  1850.         return $this;
  1851.     }
  1852.     public function isTv(): ?bool
  1853.     {
  1854.         return $this->tv;
  1855.     }
  1856.     public function setTv(bool $isTv): self
  1857.     {
  1858.         $this->tv = $isTv;
  1859.         $this->getUser()->setTv($isTv);
  1860.         $this->getUser()->setUpdatedAt(new \DateTime("now"));
  1861.         // if(!$this->getClients()->isEmpty()) {
  1862.         //     foreach($this->getClients()->toArray() as  $client) {
  1863.         //         if($client instanceof Client && $client->getUser() instanceof User) {
  1864.         //             $user = $client->getUser();
  1865.         //             $user->setTv($isTv);
  1866.         //             $user->setUpdatedAt(new \DateTime("now"));
  1867.         //         }
  1868.         //     }
  1869.         // }
  1870.         return $this;
  1871.     }
  1872.     /**
  1873.      *  VĂ©rifie si les associations sont actives
  1874.      */
  1875.     public function isActiveAssociation(): bool
  1876.     {
  1877.         $isActiveAssociation = false;
  1878.         
  1879.         if(!empty($this->getAssociations()->toArray())) {
  1880.             foreach ($this->getAssociations()->toArray() as $association) {
  1881.                 if($association->getActive() == 1) {
  1882.                     $isActiveAssociation = true;
  1883.                     break;
  1884.                 }
  1885.             }
  1886.         }
  1887.         return $isActiveAssociation;
  1888.     }
  1889.     /**
  1890.      * Indicates if a user is restricted according to general company restrictions
  1891.      *
  1892.      * @param \DateTime $time
  1893.      * @return bool
  1894.      */
  1895.     public function isRestricted(\DateTime $time): bool
  1896.     {
  1897.         foreach ($this->restrictions as $restriction) {
  1898.             if ($restriction instanceof Restriction && $restriction->isRestricted($time)) {
  1899.                 return true;
  1900.             }
  1901.         }
  1902.         return false;
  1903.     }
  1904.     /**
  1905.      * Gets the start of the next restriction on a given interval
  1906.      * @param \DateTime $start
  1907.      * @param \DateTime $end
  1908.      * @return \DateTime|null
  1909.      */
  1910.     public function getNextRestriction(\DateTime $start, \DateTime $end): ?\DateTime
  1911.     {
  1912.         foreach ($this->restrictions as $restriction) {
  1913.             if ($restriction instanceof Restriction) {
  1914.                 $startRestriction = $restriction->getStart($start);
  1915.                 if ($startRestriction <= $end) {
  1916.                     return $startRestriction;
  1917.                 }
  1918.             }
  1919.         }
  1920.         return null;
  1921.     }
  1922.     /**
  1923.      * Gets the end of a restriction
  1924.      * @return string
  1925.      */
  1926.     public function getEndRestriction(\DateTime $day): string
  1927.     {
  1928.         foreach ($this->restrictions as $restriction) {
  1929.             if (
  1930.                 $restriction instanceof Restriction && $restriction->isRestricted($day)
  1931.                 && $restriction->getCode() == Restriction::WEEKLY
  1932.             ) {
  1933.                 return $restriction->getEnd($day)->format('H:i');
  1934.             }
  1935.         }
  1936.         return '';
  1937.     }
  1938.     /**
  1939.      * Gets the end of a restriction
  1940.      * @return string
  1941.      */
  1942.     public function getStartRestriction(\DateTime $day): string
  1943.     {
  1944.         foreach ($this->restrictions as $restriction) {
  1945.             if (
  1946.                 $restriction instanceof Restriction && $restriction->isRestricted($day)
  1947.                 && $restriction->getCode() == Restriction::WEEKLY
  1948.             ) {
  1949.                 return $restriction->getStart($day)->format('H:i');
  1950.             }
  1951.         }
  1952.         return '';
  1953.     }
  1954.     public function getImageUrl(): ?string
  1955.     {
  1956.         return $this->imageUrl;
  1957.     }
  1958.     public function setImageUrl(string $imageUrl): self
  1959.     {
  1960.         $this->imageUrl = $imageUrl;
  1961.         return $this;
  1962.     }
  1963.     public function getConsultLink(): ?string
  1964.     {
  1965.         return $this->consultLink;
  1966.     }
  1967.     public function setConsultLink(?string $consultLink): self
  1968.     {
  1969.         $this->consultLink = $consultLink;
  1970.         
  1971.         return $this;
  1972.     }
  1973. }