src/Entity/Management/Subscription/Offer.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Management\Subscription;
  3. use App\Model\TimestampableTrait;
  4. use Bo\SubscriptionBundle\Model\ApiPayment;
  5. use Bo\TrainningBundle\Entity\Pack;
  6. use Bo\TrainningBundle\Entity\Trainning;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use App\Repository\Management\Subscription\OfferRepository;
  12. //implements ApiPayment
  13. /**
  14.  * Offer
  15.  *
  16.  * @ORM\Table(name="new_offer")
  17.  * @ORM\InheritanceType("JOINED")
  18.  * @ORM\DiscriminatorColumn(name="discr", type="string")
  19.  * @ORM\DiscriminatorMap({"trainning"="Training","formule"="Formule","mission"="Mission","declic"="Declic","purchase"="Purchase"})
  20.  * @ORM\Entity(repositoryClass=OfferRepository::class)
  21.  * @ORM\HasLifecycleCallbacks
  22.  */
  23. abstract class Offer
  24. {
  25.     const ID_OFFER_NEW_OFFER = 40;
  26.     const OFFER_FREE = "offer-free";
  27.     const OFFER_TEST = "offer-test";
  28.     use TimestampableTrait;
  29.     /**
  30.      * @var integer
  31.      *
  32.      * @ORM\Column(name="id", type="integer")
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue(strategy="AUTO")
  35.      */
  36.     protected $id;
  37.     /**
  38.      * @var string
  39.      *
  40.      * @ORM\Column(name="title", type="string", length=255)
  41.      */
  42.     protected $title;
  43.     /**
  44.      * @var $slug
  45.      * @Gedmo\Slug(fields={"title"})
  46.      * @ORM\Column(name="slug",type="string",length=255)
  47.      */
  48.     protected $slug;
  49.     /**
  50.      * @ORM\Column(name="price",type="float")
  51.      * @Assert\Positive
  52.      */
  53.     protected $price;
  54.     /**
  55.      * @ORM\Column(name="oldprice",type="float",nullable=true)
  56.      *
  57.      */
  58.     protected $oldprice;
  59.     /**
  60.      * @ORM\Column(name="description",type="text",nullable=true)
  61.      */
  62.     protected $description;
  63.     /**
  64.      * @ORM\Column(name="text_paid",type="text",nullable=true)
  65.      */
  66.     protected $textPaid;
  67.     /**
  68.      * @ORM\Column(name="charge",type="boolean",nullable=true)
  69.      */
  70.     protected $charge;
  71.     /**
  72.      * @ORM\Column(type="boolean",nullable=true)
  73.      */
  74.     protected $profexpress;
  75.     /**
  76.      * @ORM\Column(name="full_description",type="text",nullable=true)
  77.      */
  78.     protected $fullDescription;
  79.     /**
  80.      * @ORM\Column(name="accroche",type="text",nullable=true)
  81.      */
  82.     protected $accroche;
  83.     /**
  84.      * @var string
  85.      *
  86.      * @ORM\Column(name="filename", type="string", length=255,nullable=true)
  87.      */
  88.     protected $picture;
  89.     /**
  90.      * @var string
  91.      * @ORM\Column(name="stripe_id",type="string",nullable=true)
  92.      */
  93.     protected $stripeId;
  94.     /**
  95.      * @var string
  96.      * @ORM\Column(name="code_mailjet",type="string",nullable=true)
  97.      */
  98.     protected $codeMailjet;
  99.     /**
  100.      * @var string
  101.      * @ORM\Column(name="code_mailjet_trial_list",type="string",nullable=true)
  102.      */
  103.     protected $codeMailjetTrialList;
  104.     /**
  105.      * @ORM\Column(name="online",type="boolean",nullable=true)
  106.      */
  107.     protected $online;
  108.     /**
  109.      * @ORM\Column(type="boolean",nullable=true)
  110.      */
  111.     protected $isDelete;
  112.     /**
  113.      * @ORM\Column(name="position",type="integer",nullable=true)
  114.      */
  115.     protected $position;
  116.     private $file;
  117.     /***************** Association ***********************/
  118.     /*
  119.      * @ORM\ManyToMany(targetEntity="Options",inversedBy="offers")
  120.      * @ORM\JoinTable(name="lnk_offer_options")
  121.      */
  122.     protected $options;
  123.     /*
  124.      * @ORM\OneToMany(targetEntity="\Bo\StudentBundle\Entity\OfferStudent",mappedBy="offer")
  125.      *
  126.      */
  127.     private $students;
  128.     /*
  129.      * @ORM\ManyToMany(targetEntity="Bo\MediaBundle\Entity\Slideshow", mappedBy="offers")
  130.      */
  131.     private $slideshows;
  132.     /**
  133.      * @ORM\ManyToOne(targetEntity=TypeOffer::class, inversedBy="offer")
  134.      */
  135.     private $typeOffer;
  136.     /******************** Fin ****************************/
  137.     public function __construct()
  138.     {
  139.         $this->options = new ArrayCollection();
  140.         $this->students = new ArrayCollection();
  141.         $this->slideshows = new ArrayCollection();
  142.         $this->profexpress = false;
  143.         $this->online = true;
  144.         $this->position = 0;
  145.     }
  146.     /**
  147.      * Get id
  148.      *
  149.      * @return integer
  150.      */
  151.     public function getId()
  152.     {
  153.         return $this->id;
  154.     }
  155.     /**
  156.      * Set title
  157.      *
  158.      * @param string $title
  159.      * @return Offer
  160.      */
  161.     public function setTitle($title)
  162.     {
  163.         $this->title = $title;
  164.         return $this;
  165.     }
  166.     /**
  167.      * Get title
  168.      *
  169.      * @return string
  170.      */
  171.     public function getTitle()
  172.     {
  173.         return $this->title;
  174.     }
  175.     /**
  176.      * @return mixed
  177.      */
  178.     public function getSlug()
  179.     {
  180.         return $this->slug;
  181.     }
  182.     /**
  183.      * @param mixed $slug
  184.      */
  185.     public function setSlug($slug)
  186.     {
  187.         $this->slug = $slug;
  188.     }
  189.     /**
  190.      * @return mixed
  191.      */
  192.     public function getPrice()
  193.     {
  194.         return $this->price;
  195.     }
  196.     /**
  197.      * @param mixed $price
  198.      */
  199.     public function setPrice($price)
  200.     {
  201.         $this->price = $price;
  202.     }
  203.     /**
  204.      * @return mixed
  205.      */
  206.     public function getDescription()
  207.     {
  208.         return $this->description;
  209.     }
  210.     /**
  211.      * @param mixed $description
  212.      */
  213.     public function setDescription($description)
  214.     {
  215.         $this->description = $description;
  216.     }
  217.     /**
  218.      * @return mixed
  219.      */
  220.     public function getOptions()
  221.     {
  222.         return $this->options;
  223.     }
  224.     /**
  225.      * @param mixed $options
  226.      */
  227.     public function addOptions($options)
  228.     {
  229.         $this->options[] = $options;
  230.     }
  231.     public function hasOptions()
  232.     {
  233.         return !empty($this->options);
  234.     }
  235.     /**
  236.      * @return mixed
  237.      */
  238.     public function getDiscount()
  239.     {
  240.         return $this->discount;
  241.     }
  242.     /**
  243.      * @param mixed $discount
  244.      */
  245.     public function setDiscount($discount)
  246.     {
  247.         $this->discount = $discount;
  248.     }
  249.     /**
  250.      * @return mixed
  251.      */
  252.     public function getReduce()
  253.     {
  254.         return $this->reduce;
  255.     }
  256.     /**
  257.      * @param mixed $reduce
  258.      */
  259.     public function setReduce($reduce)
  260.     {
  261.         $this->reduce = $reduce;
  262.     }
  263.     /**
  264.      * @return mixed
  265.      */
  266.     public function getStudents()
  267.     {
  268.         return $this->students;
  269.     }
  270.     /**
  271.      * @param mixed $students
  272.      */
  273.     public function addStudents($students)
  274.     {
  275.         $this->students[] = $students;
  276.     }
  277.     public function __toString()
  278.     {
  279.         return $this->title;
  280.     }
  281.     /**
  282.      * @return mixed
  283.      */
  284.     public function getTextPaid()
  285.     {
  286.         return $this->textPaid;
  287.     }
  288.     /**
  289.      * @param mixed $textPaid
  290.      */
  291.     public function setTextPaid($textPaid)
  292.     {
  293.         $this->textPaid = $textPaid;
  294.     }
  295.     /**
  296.      * @return mixed
  297.      */
  298.     public function getCharge()
  299.     {
  300.         return $this->charge;
  301.     }
  302.     public function isCharge()
  303.     {
  304.         return $this->charge;
  305.     }
  306.     /**
  307.      * @param mixed $charge
  308.      */
  309.     public function setCharge($charge)
  310.     {
  311.         $this->charge = $charge;
  312.     }
  313.     /**
  314.      * @return mixed
  315.      */
  316.     public function getFullDescription()
  317.     {
  318.         return $this->fullDescription;
  319.     }
  320.     /**
  321.      * @param mixed $fullDescription
  322.      */
  323.     public function setFullDescription($fullDescription)
  324.     {
  325.         $this->fullDescription = $fullDescription;
  326.     }
  327.     public function isPack()
  328.     {
  329.         if($this instanceof Pack){
  330.             return true;
  331.         }
  332.         return false;
  333.     }
  334.     public function isTrainning()
  335.     {
  336.         if($this instanceof Trainning){
  337.             return true;
  338.         }
  339.         return false;
  340.     }
  341.     public function textInvoice(){
  342.         if($this->isPack())
  343.         {
  344.             return "Votre facture s'élève à";
  345.         }
  346.         return "Votre facture mensuelle s'élève à";
  347.     }
  348.     public function getSlugApi()
  349.     {
  350.         return $this->slug;
  351.     }
  352.     /**
  353.      * @return string
  354.      */
  355.     public function getPicture()
  356.     {
  357.         return $this->picture;
  358.     }
  359.     /**
  360.      * @param string $picture
  361.      */
  362.     public function setPicture($picture)
  363.     {
  364.         $this->picture = $picture;
  365.     }
  366.     /**
  367.      * @return mixed
  368.      */
  369.     public function getFile()
  370.     {
  371.         return $this->file;
  372.     }
  373.     /**
  374.      * @param mixed $file
  375.      */
  376.     public function setFile($file)
  377.     {
  378.         $this->file = $file;
  379.     }
  380.     public function getAbsolutePath()
  381.     {
  382.         return null === $this->picture ? null : sprintf("%s/%s",$this->getUploadRootDir(),$this->picture);
  383.     }
  384.     public function getWebPath()
  385.     {
  386.         return null === $this->picture ? null : sprintf("/%s/%s",$this->getUploadDir(),$this->picture);
  387.     }
  388.     protected function getUploadRootDir()
  389.     {
  390.         // le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
  391.         return __DIR__.'/../../../../web/'.$this->getUploadDir();
  392.     }
  393.     protected function getUploadDir()
  394.     {
  395.         // on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
  396.         // le document/image dans la vue.
  397.         return sprintf('ressources/offres/');
  398.     }
  399.     /**
  400.      * @ORM\PrePersist
  401.      * @ORM\PreUpdate
  402.      */
  403.     public function PreUpdate()
  404.     {
  405.         if (null !== $this->file) {
  406.             $this->removeUpload();
  407.             $this->picture = sha1(uniqid(mt_rand(), true)).'.'.$this->file->guessExtension();
  408.         }
  409.     }
  410.     /**
  411.      * @ORM\PostPersist
  412.      * @ORM\PostUpdate
  413.      */
  414.     public function PostUpdate()
  415.     {
  416.         if (null === $this->file) {
  417.             return;
  418.         }
  419.         // s'il y a une erreur lors du déplacement du fichier, une exception
  420.         // va automatiquement être lancée par la méthode move(). Cela va empêcher
  421.         // proprement l'entité d'être persistée dans la base de données si
  422.         // erreur il y a
  423.         if(!is_dir($this->getUploadRootDir()))
  424.         {
  425.             mkdir($this->getUploadRootDir(),'0755',true);
  426.         }
  427.         $this->file->move($this->getUploadRootDir(), $this->picture);
  428.         unset($this->file);
  429.         $tmp = $this->getAbsolutePath();
  430.         unset($tmp);
  431.     }
  432.     /**
  433.      * @ORM\PostRemove()
  434.      */
  435.     public function removeUpload()
  436.     {
  437.         $file = $this->getAbsolutePath();
  438.         if (is_file($file)) {
  439.             unlink($file);
  440.         }
  441.     }
  442.     /**
  443.      * @return mixed
  444.      */
  445.     public function getAccroche()
  446.     {
  447.         return $this->accroche;
  448.     }
  449.     /**
  450.      * @param mixed $accroche
  451.      */
  452.     public function setAccroche($accroche)
  453.     {
  454.         $this->accroche = $accroche;
  455.     }
  456.     /**
  457.      * @return mixed
  458.      */
  459.     public function getRecap()
  460.     {
  461.         return $this->recap;
  462.     }
  463.     /**
  464.      * @param mixed $recap
  465.      */
  466.     public function setRecap($recap)
  467.     {
  468.         $this->recap = $recap;
  469.     }
  470.     /**
  471.      * @return mixed
  472.      */
  473.     public function getOldprice()
  474.     {
  475.         return $this->oldprice;
  476.     }
  477.     /**
  478.      * @param mixed $oldprice
  479.      */
  480.     public function setOldprice($oldprice)
  481.     {
  482.         $this->oldprice = $oldprice;
  483.     }
  484.     /**
  485.      * Add options
  486.      *
  487.      * @param \Bo\SubscriptionBundle\Entity\Options $options
  488.      * @return Offer
  489.      */
  490.     public function addOption($options)
  491.     {
  492.         $this->options[] = $options;
  493.         return $this;
  494.     }
  495.     /**
  496.      * Remove options
  497.      *
  498.      * @param \Bo\SubscriptionBundle\Entity\Options $options
  499.      */
  500.     public function removeOption($options)
  501.     {
  502.         $this->options->removeElement($options);
  503.     }
  504.     /**
  505.      * Add students
  506.      *
  507.      * @param \Bo\StudentBundle\Entity\OfferStudent $students
  508.      * @return Offer
  509.      */
  510.     public function addStudent($students)
  511.     {
  512.         $this->students[] = $students;
  513.         return $this;
  514.     }
  515.     /**
  516.      * Remove students
  517.      *
  518.      * @param \Bo\StudentBundle\Entity\OfferStudent $students
  519.      */
  520.     public function removeStudent($students)
  521.     {
  522.         $this->students->removeElement($students);
  523.     }
  524.     /**
  525.      * Add slideshows
  526.      *
  527.      * @param \Bo\MediaBundle\Entity\Slideshow $slideshows
  528.      * @return Offer
  529.      */
  530.     public function addSlideshow($slideshows)
  531.     {
  532.         $this->slideshows[] = $slideshows;
  533.         return $this;
  534.     }
  535.     /**
  536.      * Remove slideshows
  537.      *
  538.      * @param \Bo\MediaBundle\Entity\Slideshow $slideshows
  539.      */
  540.     public function removeSlideshow($slideshows)
  541.     {
  542.         $this->slideshows->removeElement($slideshows);
  543.     }
  544.     /**
  545.      * Get slideshows
  546.      *
  547.      * @return \Doctrine\Common\Collections\Collection
  548.      */
  549.     public function getSlideshows()
  550.     {
  551.         return $this->slideshows;
  552.     }
  553.     /**
  554.      * @return string
  555.      */
  556.     public function getStripeId()
  557.     {
  558.         return $this->stripeId;
  559.     }
  560.     /**
  561.      * @param string $stripeId
  562.      */
  563.     public function setStripeId($stripeId)
  564.     {
  565.         $this->stripeId = $stripeId;
  566.     }
  567.     /**
  568.      * @return false
  569.      */
  570.     public function getProfexpress(): bool
  571.     {
  572.         return $this->profexpress;
  573.     }
  574.     /**
  575.      * @param false $profexpress
  576.      */
  577.     public function setProfexpress(bool $profexpress): void
  578.     {
  579.         $this->profexpress = $profexpress;
  580.     }
  581.     public function getTypeOffer(): ?TypeOffer
  582.     {
  583.         return $this->typeOffer;
  584.     }
  585.     public function setTypeOffer(?TypeOffer $typeOffer): self
  586.     {
  587.         $this->typeOffer = $typeOffer;
  588.         return $this;
  589.     }
  590.     /**
  591.      * @return bool
  592.      */
  593.     public function isOnline(): ?bool
  594.     {
  595.         return $this->online;
  596.     }
  597.     /**
  598.      * @param bool $online
  599.      */
  600.     public function setOnline(bool $online): void
  601.     {
  602.         $this->online = $online;
  603.     }
  604.     /**
  605.      * @return int
  606.      */
  607.     public function getPosition(): int
  608.     {
  609.         return $this->position;
  610.     }
  611.     /**
  612.      * @param int $position
  613.      */
  614.     public function setPosition(int $position): void
  615.     {
  616.         $this->position = $position;
  617.     }
  618.     /**
  619.      * @return mixed
  620.      */
  621.     public function getIsDelete()
  622.     {
  623.         return $this->isDelete;
  624.     }
  625.     /**
  626.      * @param mixed $isDelete
  627.      */
  628.     public function setIsDelete($isDelete): void
  629.     {
  630.         $this->isDelete = $isDelete;
  631.     }
  632.     public function getCodeMailjet(): ?string
  633.     {
  634.         return $this->codeMailjet;
  635.     }
  636.     public function setCodeMailjet(string $codeMailjet): void
  637.     {
  638.         $this->codeMailjet = $codeMailjet;
  639.     }
  640.     public function getCodeMailjetTrialList(): ?string
  641.     {
  642.         return $this->codeMailjetTrialList;
  643.     }
  644.     public function setCodeMailjetTrialList(string $codeMailjetTrialList): void
  645.     {
  646.         $this->codeMailjetTrialList = $codeMailjetTrialList;
  647.     }
  648. }