<?php
namespace App\Entity\Management\Subscription;
use App\Model\TimestampableTrait;
use Bo\SubscriptionBundle\Model\ApiPayment;
use Bo\TrainningBundle\Entity\Pack;
use Bo\TrainningBundle\Entity\Trainning;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Validator\Constraints as Assert;
use App\Repository\Management\Subscription\OfferRepository;
//implements ApiPayment
/**
* Offer
*
* @ORM\Table(name="new_offer")
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorColumn(name="discr", type="string")
* @ORM\DiscriminatorMap({"trainning"="Training","formule"="Formule","mission"="Mission","declic"="Declic","purchase"="Purchase"})
* @ORM\Entity(repositoryClass=OfferRepository::class)
* @ORM\HasLifecycleCallbacks
*/
abstract class Offer
{
const ID_OFFER_NEW_OFFER = 40;
const OFFER_FREE = "offer-free";
const OFFER_TEST = "offer-test";
use TimestampableTrait;
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=255)
*/
protected $title;
/**
* @var $slug
* @Gedmo\Slug(fields={"title"})
* @ORM\Column(name="slug",type="string",length=255)
*/
protected $slug;
/**
* @ORM\Column(name="price",type="float")
* @Assert\Positive
*/
protected $price;
/**
* @ORM\Column(name="oldprice",type="float",nullable=true)
*
*/
protected $oldprice;
/**
* @ORM\Column(name="description",type="text",nullable=true)
*/
protected $description;
/**
* @ORM\Column(name="text_paid",type="text",nullable=true)
*/
protected $textPaid;
/**
* @ORM\Column(name="charge",type="boolean",nullable=true)
*/
protected $charge;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
protected $profexpress;
/**
* @ORM\Column(name="full_description",type="text",nullable=true)
*/
protected $fullDescription;
/**
* @ORM\Column(name="accroche",type="text",nullable=true)
*/
protected $accroche;
/**
* @var string
*
* @ORM\Column(name="filename", type="string", length=255,nullable=true)
*/
protected $picture;
/**
* @var string
* @ORM\Column(name="stripe_id",type="string",nullable=true)
*/
protected $stripeId;
/**
* @var string
* @ORM\Column(name="code_mailjet",type="string",nullable=true)
*/
protected $codeMailjet;
/**
* @var string
* @ORM\Column(name="code_mailjet_trial_list",type="string",nullable=true)
*/
protected $codeMailjetTrialList;
/**
* @ORM\Column(name="online",type="boolean",nullable=true)
*/
protected $online;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
protected $isDelete;
/**
* @ORM\Column(name="position",type="integer",nullable=true)
*/
protected $position;
private $file;
/***************** Association ***********************/
/*
* @ORM\ManyToMany(targetEntity="Options",inversedBy="offers")
* @ORM\JoinTable(name="lnk_offer_options")
*/
protected $options;
/*
* @ORM\OneToMany(targetEntity="\Bo\StudentBundle\Entity\OfferStudent",mappedBy="offer")
*
*/
private $students;
/*
* @ORM\ManyToMany(targetEntity="Bo\MediaBundle\Entity\Slideshow", mappedBy="offers")
*/
private $slideshows;
/**
* @ORM\ManyToOne(targetEntity=TypeOffer::class, inversedBy="offer")
*/
private $typeOffer;
/******************** Fin ****************************/
public function __construct()
{
$this->options = new ArrayCollection();
$this->students = new ArrayCollection();
$this->slideshows = new ArrayCollection();
$this->profexpress = false;
$this->online = true;
$this->position = 0;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set title
*
* @param string $title
* @return Offer
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* Get title
*
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @return mixed
*/
public function getSlug()
{
return $this->slug;
}
/**
* @param mixed $slug
*/
public function setSlug($slug)
{
$this->slug = $slug;
}
/**
* @return mixed
*/
public function getPrice()
{
return $this->price;
}
/**
* @param mixed $price
*/
public function setPrice($price)
{
$this->price = $price;
}
/**
* @return mixed
*/
public function getDescription()
{
return $this->description;
}
/**
* @param mixed $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return mixed
*/
public function getOptions()
{
return $this->options;
}
/**
* @param mixed $options
*/
public function addOptions($options)
{
$this->options[] = $options;
}
public function hasOptions()
{
return !empty($this->options);
}
/**
* @return mixed
*/
public function getDiscount()
{
return $this->discount;
}
/**
* @param mixed $discount
*/
public function setDiscount($discount)
{
$this->discount = $discount;
}
/**
* @return mixed
*/
public function getReduce()
{
return $this->reduce;
}
/**
* @param mixed $reduce
*/
public function setReduce($reduce)
{
$this->reduce = $reduce;
}
/**
* @return mixed
*/
public function getStudents()
{
return $this->students;
}
/**
* @param mixed $students
*/
public function addStudents($students)
{
$this->students[] = $students;
}
public function __toString()
{
return $this->title;
}
/**
* @return mixed
*/
public function getTextPaid()
{
return $this->textPaid;
}
/**
* @param mixed $textPaid
*/
public function setTextPaid($textPaid)
{
$this->textPaid = $textPaid;
}
/**
* @return mixed
*/
public function getCharge()
{
return $this->charge;
}
public function isCharge()
{
return $this->charge;
}
/**
* @param mixed $charge
*/
public function setCharge($charge)
{
$this->charge = $charge;
}
/**
* @return mixed
*/
public function getFullDescription()
{
return $this->fullDescription;
}
/**
* @param mixed $fullDescription
*/
public function setFullDescription($fullDescription)
{
$this->fullDescription = $fullDescription;
}
public function isPack()
{
if($this instanceof Pack){
return true;
}
return false;
}
public function isTrainning()
{
if($this instanceof Trainning){
return true;
}
return false;
}
public function textInvoice(){
if($this->isPack())
{
return "Votre facture s'élève à";
}
return "Votre facture mensuelle s'élève à";
}
public function getSlugApi()
{
return $this->slug;
}
/**
* @return string
*/
public function getPicture()
{
return $this->picture;
}
/**
* @param string $picture
*/
public function setPicture($picture)
{
$this->picture = $picture;
}
/**
* @return mixed
*/
public function getFile()
{
return $this->file;
}
/**
* @param mixed $file
*/
public function setFile($file)
{
$this->file = $file;
}
public function getAbsolutePath()
{
return null === $this->picture ? null : sprintf("%s/%s",$this->getUploadRootDir(),$this->picture);
}
public function getWebPath()
{
return null === $this->picture ? null : sprintf("/%s/%s",$this->getUploadDir(),$this->picture);
}
protected function getUploadRootDir()
{
// le chemin absolu du répertoire où les documents uploadés doivent être sauvegardés
return __DIR__.'/../../../../web/'.$this->getUploadDir();
}
protected function getUploadDir()
{
// on se débarrasse de « __DIR__ » afin de ne pas avoir de problème lorsqu'on affiche
// le document/image dans la vue.
return sprintf('ressources/offres/');
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function PreUpdate()
{
if (null !== $this->file) {
$this->removeUpload();
$this->picture = sha1(uniqid(mt_rand(), true)).'.'.$this->file->guessExtension();
}
}
/**
* @ORM\PostPersist
* @ORM\PostUpdate
*/
public function PostUpdate()
{
if (null === $this->file) {
return;
}
// s'il y a une erreur lors du déplacement du fichier, une exception
// va automatiquement être lancée par la méthode move(). Cela va empêcher
// proprement l'entité d'être persistée dans la base de données si
// erreur il y a
if(!is_dir($this->getUploadRootDir()))
{
mkdir($this->getUploadRootDir(),'0755',true);
}
$this->file->move($this->getUploadRootDir(), $this->picture);
unset($this->file);
$tmp = $this->getAbsolutePath();
unset($tmp);
}
/**
* @ORM\PostRemove()
*/
public function removeUpload()
{
$file = $this->getAbsolutePath();
if (is_file($file)) {
unlink($file);
}
}
/**
* @return mixed
*/
public function getAccroche()
{
return $this->accroche;
}
/**
* @param mixed $accroche
*/
public function setAccroche($accroche)
{
$this->accroche = $accroche;
}
/**
* @return mixed
*/
public function getRecap()
{
return $this->recap;
}
/**
* @param mixed $recap
*/
public function setRecap($recap)
{
$this->recap = $recap;
}
/**
* @return mixed
*/
public function getOldprice()
{
return $this->oldprice;
}
/**
* @param mixed $oldprice
*/
public function setOldprice($oldprice)
{
$this->oldprice = $oldprice;
}
/**
* Add options
*
* @param \Bo\SubscriptionBundle\Entity\Options $options
* @return Offer
*/
public function addOption($options)
{
$this->options[] = $options;
return $this;
}
/**
* Remove options
*
* @param \Bo\SubscriptionBundle\Entity\Options $options
*/
public function removeOption($options)
{
$this->options->removeElement($options);
}
/**
* Add students
*
* @param \Bo\StudentBundle\Entity\OfferStudent $students
* @return Offer
*/
public function addStudent($students)
{
$this->students[] = $students;
return $this;
}
/**
* Remove students
*
* @param \Bo\StudentBundle\Entity\OfferStudent $students
*/
public function removeStudent($students)
{
$this->students->removeElement($students);
}
/**
* Add slideshows
*
* @param \Bo\MediaBundle\Entity\Slideshow $slideshows
* @return Offer
*/
public function addSlideshow($slideshows)
{
$this->slideshows[] = $slideshows;
return $this;
}
/**
* Remove slideshows
*
* @param \Bo\MediaBundle\Entity\Slideshow $slideshows
*/
public function removeSlideshow($slideshows)
{
$this->slideshows->removeElement($slideshows);
}
/**
* Get slideshows
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getSlideshows()
{
return $this->slideshows;
}
/**
* @return string
*/
public function getStripeId()
{
return $this->stripeId;
}
/**
* @param string $stripeId
*/
public function setStripeId($stripeId)
{
$this->stripeId = $stripeId;
}
/**
* @return false
*/
public function getProfexpress(): bool
{
return $this->profexpress;
}
/**
* @param false $profexpress
*/
public function setProfexpress(bool $profexpress): void
{
$this->profexpress = $profexpress;
}
public function getTypeOffer(): ?TypeOffer
{
return $this->typeOffer;
}
public function setTypeOffer(?TypeOffer $typeOffer): self
{
$this->typeOffer = $typeOffer;
return $this;
}
/**
* @return bool
*/
public function isOnline(): ?bool
{
return $this->online;
}
/**
* @param bool $online
*/
public function setOnline(bool $online): void
{
$this->online = $online;
}
/**
* @return int
*/
public function getPosition(): int
{
return $this->position;
}
/**
* @param int $position
*/
public function setPosition(int $position): void
{
$this->position = $position;
}
/**
* @return mixed
*/
public function getIsDelete()
{
return $this->isDelete;
}
/**
* @param mixed $isDelete
*/
public function setIsDelete($isDelete): void
{
$this->isDelete = $isDelete;
}
public function getCodeMailjet(): ?string
{
return $this->codeMailjet;
}
public function setCodeMailjet(string $codeMailjet): void
{
$this->codeMailjet = $codeMailjet;
}
public function getCodeMailjetTrialList(): ?string
{
return $this->codeMailjetTrialList;
}
public function setCodeMailjetTrialList(string $codeMailjetTrialList): void
{
$this->codeMailjetTrialList = $codeMailjetTrialList;
}
}