classes/XLite/Model/OrderHistoryEvents.php line 61

Open in your IDE?
  1. <?php
  2. /**
  3.  * Copyright (c) 2011-present Qualiteam software Ltd. All rights reserved.
  4.  * See https://www.x-cart.com/license-agreement.html for license details.
  5.  */
  6. namespace XLite\Model;
  7. use ApiPlatform\Core\Annotation as ApiPlatform;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use XLite\API\Endpoint\OrderHistory\DTO\OrderHistoryOutput as Output;
  11. /**
  12.  * Order history events
  13.  * todo: rename to OrderHistoryEvent
  14.  *
  15.  * @ORM\Entity
  16.  * @ORM\Table (name="order_history_events")
  17.  * @ApiPlatform\ApiResource(
  18.  *     shortName="History Event",
  19.  *     output=Output::class,
  20.  *     itemOperations={},
  21.  *     collectionOperations={
  22.  *          "get"={
  23.  *              "method"="GET",
  24.  *              "path"="/orders/{id}/history.{_format}",
  25.  *              "requirements"={"id"="\d+"},
  26.  *              "openapi_context"={
  27.  *                  "summary"="Retrieve a list of order history events",
  28.  *                  "responses"={
  29.  *                      "404"={
  30.  *                          "description"="Resource not found"
  31.  *                      }
  32.  *                  },
  33.  *                  "parameters"={
  34.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  35.  *                  }
  36.  *              }
  37.  *          },
  38.  *          "get_cart_history_events"={
  39.  *              "method"="GET",
  40.  *              "path"="/carts/{id}/history.{_format}",
  41.  *              "requirements"={"id"="\d+"},
  42.  *              "openapi_context"={
  43.  *                  "summary"="Retrieve a list of cart history events",
  44.  *                  "responses"={
  45.  *                      "404"={
  46.  *                          "description"="Resource not found"
  47.  *                      }
  48.  *                  },
  49.  *                  "parameters"={
  50.  *                      {"name"="id", "in"="path", "required"=true, "schema"={"type"="integer"}}
  51.  *                  }
  52.  *              }
  53.  *          }
  54.  *     }
  55.  * )
  56.  */
  57. class OrderHistoryEvents extends \XLite\Model\AEntity
  58. {
  59.     /**
  60.      * Order history event unique id
  61.      *
  62.      * @var mixed
  63.      *
  64.      * @ORM\Id
  65.      * @ORM\GeneratedValue (strategy="AUTO")
  66.      * @ORM\Column         (type="integer")
  67.      */
  68.     protected $event_id;
  69.     /**
  70.      * Event creation timestamp
  71.      *
  72.      * @var integer
  73.      *
  74.      * @ORM\Column (type="integer")
  75.      */
  76.     protected $date;
  77.     /**
  78.      * Code of event
  79.      *
  80.      * @var string
  81.      *
  82.      * @ORM\Column (type="string", length=255)
  83.      */
  84.     protected $code;
  85.     /**
  86.      * Human-readable description of event
  87.      *
  88.      * @var string
  89.      *
  90.      * @ORM\Column (type="string", length=1024, nullable=true)
  91.      */
  92.     protected $description;
  93.     /**
  94.      * Data for human-readable description
  95.      *
  96.      * @var string
  97.      *
  98.      * @ORM\Column (type="array")
  99.      */
  100.     protected $data;
  101.     /**
  102.      * Event comment
  103.      *
  104.      * @var string
  105.      *
  106.      * @ORM\Column (type="text")
  107.      */
  108.     protected $comment '';
  109.     /**
  110.      * Event details
  111.      *
  112.      * @var \XLite\Model\OrderHistoryEventsData[]
  113.      *
  114.      * @ORM\OneToMany (targetEntity="XLite\Model\OrderHistoryEventsData", mappedBy="event", cascade={"all"})
  115.      */
  116.     protected $details;
  117.     /**
  118.      * Relation to a order entity
  119.      *
  120.      * @var \XLite\Model\Order
  121.      *
  122.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Order", inversedBy="events", fetch="LAZY")
  123.      * @ORM\JoinColumn (name="order_id", referencedColumnName="order_id", onDelete="CASCADE")
  124.      */
  125.     protected $order;
  126.     /**
  127.      * Author profile of the event
  128.      *
  129.      * @var \XLite\Model\Profile
  130.      *
  131.      * @ORM\ManyToOne   (targetEntity="XLite\Model\Profile", inversedBy="event", cascade={"merge","detach","persist"})
  132.      * @ORM\JoinColumn (name="author_id", referencedColumnName="profile_id", onDelete="SET NULL")
  133.      */
  134.     protected $author;
  135.     /**
  136.      * Author name
  137.      *
  138.      * @var string
  139.      *
  140.      * @ORM\Column (type="string", length=255, nullable=true)
  141.      */
  142.     protected $authorName;
  143.     /**
  144.      * Author IP
  145.      *
  146.      * @var string
  147.      *
  148.      * @ORM\Column (type="string", length=255, nullable=true)
  149.      */
  150.     protected $authorIp '';
  151.     public function __construct(array $data = [])
  152.     {
  153.         parent::__construct($data);
  154.         $this->details = new ArrayCollection();
  155.     }
  156.     /**
  157.      * Description getter
  158.      *
  159.      * @return string
  160.      */
  161.     public function getDescription()
  162.     {
  163.         return static::t($this->description, (array)$this->getData());
  164.     }
  165.     /**
  166.      * Details setter
  167.      *
  168.      * @param array $details Array of event details array($name => $value)
  169.      *
  170.      * @return void
  171.      */
  172.     public function setDetails(array $details)
  173.     {
  174.         foreach ($details as $detail) {
  175.             $data = new \XLite\Model\OrderHistoryEventsData();
  176.             $data->setName($detail['name']);
  177.             $data->setValue($detail['value']);
  178.             $this->addDetails($data);
  179.             $data->setEvent($this);
  180.         }
  181.     }
  182.     /**
  183.      * Clone order and all related data
  184.      *
  185.      * @return \XLite\Model\OrderHistoryEvents
  186.      */
  187.     public function cloneEntity()
  188.     {
  189.         $entity parent::cloneEntity();
  190.         // Clone order details
  191.         if ($this->getDetails()) {
  192.             foreach ($this->getDetails() as $detail) {
  193.                 $cloned $detail->cloneEntity();
  194.                 $entity->addDetails($cloned);
  195.                 $cloned->setEvent($entity);
  196.             }
  197.         }
  198.         return $entity;
  199.     }
  200.     /**
  201.      * Get event_id
  202.      *
  203.      * @return integer
  204.      */
  205.     public function getEventId()
  206.     {
  207.         return $this->event_id;
  208.     }
  209.     /**
  210.      * Set date
  211.      *
  212.      * @param integer $date
  213.      * @return OrderHistoryEvents
  214.      */
  215.     public function setDate($date)
  216.     {
  217.         $this->date $date;
  218.         return $this;
  219.     }
  220.     /**
  221.      * Get date
  222.      *
  223.      * @return integer
  224.      */
  225.     public function getDate()
  226.     {
  227.         return $this->date;
  228.     }
  229.     /**
  230.      * Set code
  231.      *
  232.      * @param string $code
  233.      * @return OrderHistoryEvents
  234.      */
  235.     public function setCode($code)
  236.     {
  237.         $this->code $code;
  238.         return $this;
  239.     }
  240.     /**
  241.      * Get code
  242.      *
  243.      * @return string
  244.      */
  245.     public function getCode()
  246.     {
  247.         return $this->code;
  248.     }
  249.     /**
  250.      * Set description
  251.      *
  252.      * @param string $description
  253.      * @return OrderHistoryEvents
  254.      */
  255.     public function setDescription($description)
  256.     {
  257.         $this->description $description;
  258.         return $this;
  259.     }
  260.     /**
  261.      * Set data
  262.      *
  263.      * @param array $data
  264.      * @return OrderHistoryEvents
  265.      */
  266.     public function setData($data)
  267.     {
  268.         $this->data $data;
  269.         return $this;
  270.     }
  271.     /**
  272.      * Get data
  273.      *
  274.      * @return array
  275.      */
  276.     public function getData()
  277.     {
  278.         return $this->data;
  279.     }
  280.     /**
  281.      * Set comment
  282.      *
  283.      * @param string $comment
  284.      * @return OrderHistoryEvents
  285.      */
  286.     public function setComment($comment)
  287.     {
  288.         $this->comment $comment;
  289.         return $this;
  290.     }
  291.     /**
  292.      * Get comment
  293.      *
  294.      * @return string
  295.      */
  296.     public function getComment()
  297.     {
  298.         return $this->comment;
  299.     }
  300.     /**
  301.      * Add details
  302.      *
  303.      * @param \XLite\Model\OrderHistoryEventsData $details
  304.      * @return OrderHistoryEvents
  305.      */
  306.     public function addDetails(\XLite\Model\OrderHistoryEventsData $details)
  307.     {
  308.         $this->details[] = $details;
  309.         return $this;
  310.     }
  311.     /**
  312.      * Get details
  313.      *
  314.      * @return \Doctrine\Common\Collections\Collection
  315.      */
  316.     public function getDetails()
  317.     {
  318.         return $this->details;
  319.     }
  320.     /**
  321.      * Set order
  322.      *
  323.      * @param \XLite\Model\Order $order
  324.      * @return OrderHistoryEvents
  325.      */
  326.     public function setOrder(\XLite\Model\Order $order null)
  327.     {
  328.         $this->order $order;
  329.         return $this;
  330.     }
  331.     /**
  332.      * Get order
  333.      *
  334.      * @return \XLite\Model\Order
  335.      */
  336.     public function getOrder()
  337.     {
  338.         return $this->order;
  339.     }
  340.     /**
  341.      * Set author
  342.      *
  343.      * @param \XLite\Model\Profile $author
  344.      * @return OrderHistoryEvents
  345.      */
  346.     public function setAuthor(\XLite\Model\Profile $author null)
  347.     {
  348.         $this->author $author;
  349.         if ($author && $author->isAdmin()) {
  350.             $this->setAuthorName($author->getLogin());
  351.         }
  352.         return $this;
  353.     }
  354.     /**
  355.      * Get author
  356.      *
  357.      * @return \XLite\Model\Profile
  358.      */
  359.     public function getAuthor()
  360.     {
  361.         return $this->author;
  362.     }
  363.     /**
  364.      * @return string
  365.      */
  366.     public function getAuthorIp()
  367.     {
  368.         return $this->authorIp;
  369.     }
  370.     /**
  371.      * @param string $authorIp
  372.      *
  373.      * @return $this
  374.      */
  375.     public function setAuthorIp($authorIp)
  376.     {
  377.         $this->authorIp $authorIp;
  378.         return $this;
  379.     }
  380.     /**
  381.      * @return string
  382.      */
  383.     public function getAuthorName()
  384.     {
  385.         return $this->authorName;
  386.     }
  387.     /**
  388.      * @param string $authorName
  389.      *
  390.      * @return $this
  391.      */
  392.     public function setAuthorName($authorName)
  393.     {
  394.         $this->authorName $authorName;
  395.         return $this;
  396.     }
  397.     public function showAuthor()
  398.     {
  399.         return ($this->getAuthor() && $this->getAuthor()->isAdmin())
  400.             || $this->getAuthorName()
  401.             || $this->getAuthorIp();
  402.     }
  403. }