src/FMT/Data/Entity/CampaignBook.php line 25

Open in your IDE?
  1. <?php
  2. namespace FMT\Data\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use FMT\Data\Traits\EnumTrait;
  5. use Gedmo\Timestampable\Traits\TimestampableEntity;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. /**
  8.  * CampaignBook
  9.  *
  10.  * @ORM\Table(
  11.  *     name="campaign_book",
  12.  *     indexes={
  13.  *          @ORM\Index(name="IX_book_status", columns={"status"}),
  14.  *          @ORM\Index(name="IX_book_campaign", columns={"campaign_id"})
  15.  *     }
  16.  * )
  17.  * @ORM\Entity
  18.  * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  19.  * @ORM\HasLifecycleCallbacks()
  20.  * @UniqueEntity(fields={"productFamilyId", "sku", "campaignId"})
  21.  */
  22. class CampaignBook implements EntityInterfaceCampaignProductInterface
  23. {
  24.     use TimestampableEntity;
  25.     use EnumTrait;
  26.     // TODO: Combine with ProductInterface constants
  27.     const STATUS_AVAILABLE 0;
  28.     const STATUS_OUT_OF_STOCK 1;
  29.     const STATUS_ORDERED 2;
  30.     const STATUS_UNAVAILABLE 3;
  31.     const STATUS_RETURNED 4;
  32.     // TODO: added new status? Check messages.en.yml!
  33.     const STATE_UNKNOWN 0;
  34.     const STATE_NEW 1;
  35.     const STATE_USED 2;
  36.     // TODO: added new state? Check messages.en.yml!
  37.     /**
  38.      * @var integer
  39.      *
  40.      * @ORM\Column(name="id", type="integer")
  41.      * @ORM\Id
  42.      * @ORM\GeneratedValue(strategy="IDENTITY")
  43.      */
  44.     private $id;
  45.     /**
  46.      * @var \FMT\Data\Entity\Campaign
  47.      *
  48.      * @ORM\ManyToOne(targetEntity="FMT\Data\Entity\Campaign", inversedBy="books")
  49.      * @ORM\JoinColumns({
  50.      *   @ORM\JoinColumn(name="campaign_id", referencedColumnName="id")
  51.      * })
  52.      */
  53.     private $campaign;
  54.     /**
  55.      * @var string
  56.      *
  57.      * @ORM\Column(name="product_family_id", type="string", length=255, nullable=false)
  58.      */
  59.     private $productFamilyId;
  60.     /**
  61.      * @var string
  62.      *
  63.      * @ORM\Column(name="sku", type="string", length=255, nullable=false)
  64.      */
  65.     private $sku;
  66.     /**
  67.      * @var string
  68.      *
  69.      * @ORM\Column(name="title", type="string", length=255, nullable=false)
  70.      */
  71.     private $title;
  72.     /**
  73.      * @var string
  74.      *
  75.      * @ORM\Column(name="author", type="string", length=255, nullable=true)
  76.      */
  77.     private $author;
  78.     /**
  79.      * @var string
  80.      *
  81.      * @ORM\Column(name="class", type="string", length=255, nullable=true)
  82.      */
  83.     private $class;
  84.     /**
  85.      * @var string
  86.      *
  87.      * @ORM\Column(name="isbn", type="string", length=15, nullable=true)
  88.      */
  89.     private $isbn;
  90.     /**
  91.      * @var integer
  92.      *
  93.      * @ORM\Column(name="price", type="integer", nullable=false)
  94.      */
  95.     private $price;
  96.      /**
  97.      * @var integer
  98.      *
  99.      * @ORM\Column(name="fee", type="integer", nullable=false)
  100.      */
  101.     private $fee;
  102.     /**
  103.      * @var integer
  104.      *
  105.      * @ORM\Column(name="quantity", type="integer", nullable=false)
  106.      */
  107.     private $quantity 1;
  108.     /**
  109.      * @var integer
  110.      *
  111.      * @ORM\Column(name="status", type="smallint", nullable=false)
  112.      */
  113.     private $status self::STATUS_AVAILABLE;
  114.     /**
  115.      * @var integer
  116.      *
  117.      * @ORM\Column(name="state", type="smallint", nullable=false)
  118.      */
  119.     private $state self::STATE_UNKNOWN;
  120.     /**
  121.      * @var int
  122.      *
  123.      * @ORM\Column(name="tax", type="integer", nullable=false)
  124.      */
  125.     private $tax;
  126.     /**
  127.      * @var int
  128.      *
  129.      * @ORM\Column(name="net", type="integer", nullable=false)
  130.      */
  131.     private $net;
  132.     /**
  133.      * @return int
  134.      */
  135.     public function getId()
  136.     {
  137.         return $this->id;
  138.     }
  139.     /**
  140.      * @return Campaign
  141.      */
  142.     public function getCampaign(): Campaign
  143.     {
  144.         return $this->campaign;
  145.     }
  146.     /**
  147.      * @param Campaign $campaign
  148.      * @return $this
  149.      */
  150.     public function setCampaign($campaign)
  151.     {
  152.         $this->campaign $campaign;
  153.         return $this;
  154.     }
  155.     /**
  156.      * @return string
  157.      */
  158.     public function getProductFamilyId()
  159.     {
  160.         return $this->productFamilyId;
  161.     }
  162.     /**
  163.      * @param string $productFamilyId
  164.      * @return $this
  165.      */
  166.     public function setProductFamilyId($productFamilyId)
  167.     {
  168.         $this->productFamilyId $productFamilyId;
  169.         return $this;
  170.     }
  171.     /**
  172.      * @return string
  173.      */
  174.     public function getSku()
  175.     {
  176.         return $this->sku;
  177.     }
  178.     /**
  179.      * @param string $sku
  180.      * @return $this
  181.      */
  182.     public function setSku($sku)
  183.     {
  184.         $this->sku $sku;
  185.         return $this;
  186.     }
  187.     /**
  188.      * @return string
  189.      */
  190.     public function getTitle()
  191.     {
  192.         return $this->title;
  193.     }
  194.     /**
  195.      * @param string $title
  196.      * @return $this
  197.      */
  198.     public function setTitle($title)
  199.     {
  200.         $this->title $title;
  201.         return $this;
  202.     }
  203.     /**
  204.      * @return string
  205.      */
  206.     public function getAuthor()
  207.     {
  208.         return $this->author;
  209.     }
  210.     /**
  211.      * @param string $author
  212.      * @return $this
  213.      */
  214.     public function setAuthor($author)
  215.     {
  216.         $this->author $author;
  217.         return $this;
  218.     }
  219.     /**
  220.      * @return string
  221.      */
  222.     public function getClass()
  223.     {
  224.         return $this->class;
  225.     }
  226.     /**
  227.      * @param string $class
  228.      * @return $this
  229.      */
  230.     public function setClass($class)
  231.     {
  232.         $this->class $class;
  233.         return $this;
  234.     }
  235.     /**
  236.      * @return string
  237.      */
  238.     public function getIsbn()
  239.     {
  240.         return $this->isbn;
  241.     }
  242.     /**
  243.      * @param string $isbn
  244.      * @return $this
  245.      */
  246.     public function setIsbn($isbn)
  247.     {
  248.         $this->isbn $isbn;
  249.         return $this;
  250.     }
  251.     /**
  252.      * @return int
  253.      */
  254.     public function getPrice()
  255.     {
  256.         return $this->price;
  257.     }
  258.      /**
  259.      * @return int
  260.      */
  261.     public function getTotalPrice()
  262.     {
  263.         return $this->price $this->fee $this->tax;
  264.     }
  265.     /**
  266.      * @param int $price
  267.      * @return $this
  268.      */
  269.     public function setPrice($price)
  270.     {
  271.         $this->price $price;
  272.         return $this;
  273.     }
  274.     /**
  275.      * @return int
  276.      */
  277.     public function getFee()
  278.     {
  279.         return $this->fee;
  280.     }
  281.     /**
  282.      * @param int $fee
  283.      * @return $this
  284.      */
  285.     public function setFee($fee)
  286.     {
  287.         $this->fee $fee;
  288.         return $this;
  289.     }
  290.     /**
  291.      * @return int
  292.      */
  293.     public function getNet()
  294.     {
  295.         return $this->net;
  296.     }
  297.     /**
  298.      * @param $net
  299.      * @return $this
  300.      */
  301.     public function setNet($net)
  302.     {
  303.         $this->net $net;
  304.         return $this;
  305.     }
  306.     /**
  307.      * @return int
  308.      */
  309.     public function getTax()
  310.     {
  311.         // Equitable Access = No Tax
  312.         if($this->sku == "2079144"){
  313.             $this->setTax(0);
  314.         }
  315.         return $this->tax;
  316.     }
  317.     /**
  318.      * @param $tax
  319.      * @return $this
  320.      */
  321.     public function setTax($tax)
  322.     {
  323.         $this->tax $tax;
  324.         return $this;
  325.     }
  326.     /**
  327.      * @return int
  328.      */
  329.     public function getQuantity()
  330.     {
  331.         return $this->quantity;
  332.     }
  333.     /**
  334.      * @param int $quantity
  335.      * @return $this
  336.      */
  337.     public function setQuantity($quantity)
  338.     {
  339.         $this->quantity $quantity;
  340.         return $this;
  341.     }
  342.     /**
  343.      * @return int
  344.      */
  345.     public function getStatus()
  346.     {
  347.         return $this->status;
  348.     }
  349.     /**
  350.      * @param int $status
  351.      * @return $this
  352.      */
  353.     public function setStatus($status)
  354.     {
  355.         $this->status $status;
  356.         return $this;
  357.     }
  358.     /**
  359.      * @return string
  360.      */
  361.     public function getStatusName()
  362.     {
  363.         return array_search($this->statusself::getAllowedStatuses());
  364.     }
  365.     /**
  366.      * @return int
  367.      */
  368.     public function getState()
  369.     {
  370.         return $this->state;
  371.     }
  372.     /**
  373.      * @param int $state
  374.      * @return $this
  375.      */
  376.     public function setState($state)
  377.     {
  378.         $this->state $state;
  379.         return $this;
  380.     }
  381.     /**
  382.      * @return string
  383.      */
  384.     public function getStateName()
  385.     {
  386.         if (!is_numeric($this->state)) {
  387.             return sprintf('STATE_%s'strtoupper($this->state));
  388.         }
  389.         return array_search($this->stateself::getConstants('STATE_'));
  390.     }
  391.     /**
  392.      * @return bool
  393.      */
  394.     public function isAvailable()
  395.     {
  396.         return $this->status == CampaignBook::STATUS_AVAILABLE;
  397.     }
  398.     /**
  399.      * @return bool
  400.      */
  401.     public function isOrdered()
  402.     {
  403.         return $this->status == CampaignBook::STATUS_ORDERED;
  404.     }
  405. }