modules/QSL/LoyaltyProgram/src/Model/RewardHistoryEvent.php line 18

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 QSL\LoyaltyProgram\Model;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * Reward History event.
  10.  *
  11.  * @ORM\Entity
  12.  * @ORM\Table (name="reward_history_events")
  13.  */
  14. class RewardHistoryEvent extends \XLite\Model\AEntity
  15. {
  16.     /**
  17.      * Event reasons.
  18.      */
  19.     public const EVENT_REASON_ORDER_REWARD    'order';
  20.     public const EVENT_REASON_CANCELED_REWARD 'refund';
  21.     public const EVENT_REASON_REDEEMED_POINTS 'redeem';
  22.     public const EVENT_REASON_RETURNED_POINTS 'unredeem';
  23.     public const EVENT_REASON_CUSTOM          'custom';
  24.     public const EVENT_REASON_IMPORT          'import';
  25.     public const EVENT_REASON_SIGNUP_REWARD   'signup';
  26.     public const EVENT_REASON_REVIEW_REWARD   'review';
  27.     public const EVENT_REASON_RATING_REWARD   'rating';
  28.     public const EVENT_REASON_CANCELED_REVIEW '-review';
  29.     public const EVENT_REASON_CANCELED_RATING '-rating';
  30.     /**
  31.      * User-friendly descriptions of event reasons.
  32.      *
  33.      * @var array
  34.      */
  35.     protected static $reasonDescriptions = [
  36.         self::EVENT_REASON_ORDER_REWARD    => 'Reward for purchasing products in order {{order}}',
  37.         self::EVENT_REASON_CANCELED_REWARD => 'Cancel reward for not finished order {{order}}',
  38.         self::EVENT_REASON_REDEEMED_POINTS => 'Use to checkout order {{order}}',
  39.         self::EVENT_REASON_RETURNED_POINTS => 'Return reward points redeemed for not finished order {{order}}',
  40.         self::EVENT_REASON_CUSTOM          => 'Reward points adjusted by the store administrator',
  41.         self::EVENT_REASON_IMPORT          => 'Reward points adjusted by a store administration script',
  42.         self::EVENT_REASON_SIGNUP_REWARD   => 'Reward for creating a store account',
  43.         self::EVENT_REASON_REVIEW_REWARD   => 'Reward for reviewing a product',
  44.         self::EVENT_REASON_RATING_REWARD   => 'Reward for rating a product',
  45.         self::EVENT_REASON_CANCELED_REVIEW => 'Canceled reward for reviewing a product',
  46.         self::EVENT_REASON_CANCELED_RATING => 'Canceled reward for rating a product',
  47.     ];
  48.     /**
  49.      * Event unique ID.
  50.      *
  51.      * @var mixed
  52.      *
  53.      * @ORM\Id
  54.      * @ORM\GeneratedValue (strategy="AUTO")
  55.      * @ORM\Column         (type="integer")
  56.      */
  57.     protected $event_id;
  58.     /**
  59.      * Event creation timestamp.
  60.      *
  61.      * @var integer
  62.      *
  63.      * @ORM\Column (type="integer")
  64.      */
  65.     protected $date;
  66.     /**
  67.      * Reward points awarded to the user.
  68.      *
  69.      * @var integer
  70.      *
  71.      * @ORM\Column (type="integer")
  72.      */
  73.     protected $points;
  74.     /**
  75.      * Reason for the event.
  76.      *
  77.      * @var string
  78.      *
  79.      * @ORM\Column (type="string", length=255)
  80.      */
  81.     protected $reason;
  82.     /**
  83.      * Event comment.
  84.      *
  85.      * @var string
  86.      *
  87.      * @ORM\Column (type="text")
  88.      */
  89.     protected $comment '';
  90.     /**
  91.      * User that the event happened for.
  92.      *
  93.      * @var \XLite\Model\Profile
  94.      *
  95.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Profile", inversedBy="rewardEvents", cascade={"merge", "detach"})
  96.      * @ORM\JoinColumn (name="user_id", referencedColumnName="profile_id", nullable=true, onDelete="CASCADE")
  97.      */
  98.     protected $user;
  99.     /**
  100.      * User that initiated the event.
  101.      *
  102.      * @var \XLite\Model\Profile
  103.      *
  104.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Profile", inversedBy="initiatedRewardEvents", cascade={"merge", "detach"})
  105.      * @ORM\JoinColumn (name="initiator_id", referencedColumnName="profile_id", nullable=true, onDelete="CASCADE")
  106.      */
  107.     protected $initiator;
  108.     /**
  109.      * Relation to a order entity.
  110.      *
  111.      * @var \XLite\Model\Order
  112.      *
  113.      * @ORM\ManyToOne  (targetEntity="XLite\Model\Order", inversedBy="rewardEvents", cascade={"merge", "detach"})
  114.      * @ORM\JoinColumn (name="order_id", referencedColumnName="order_id", nullable=true, onDelete="CASCADE")
  115.      */
  116.     protected $order null;
  117.     /**
  118.      * Get public notes for the event (either the admin's comments, or the event reason explained).
  119.      *
  120.      * @return string
  121.      */
  122.     public function getNotes()
  123.     {
  124.         $comment $this->getComment();
  125.         $notes   $comment ?: $this->getReasonDescription();
  126.         $orderNumber $this->getOrder() ? ('#' $this->getOrder()->getOrderNumber()) : '';
  127.         return $this->t($notes, ['order' => $orderNumber]);
  128.     }
  129.     /**
  130.      * Return a user-friendly description of the event reason.
  131.      *
  132.      * @return string
  133.      */
  134.     public function getReasonDescription()
  135.     {
  136.         return static::$reasonDescriptions[$this->getReason()] ?? '';
  137.     }
  138.     /**
  139.      * Returns the event identifier.
  140.      *
  141.      * @return integer
  142.      */
  143.     public function getEventId()
  144.     {
  145.         return $this->event_id;
  146.     }
  147.     /**
  148.      * Returns the event date.
  149.      *
  150.      * @return integer
  151.      */
  152.     public function getDate()
  153.     {
  154.         return $this->date;
  155.     }
  156.     /**
  157.      * Sets the event date.
  158.      *
  159.      * @param integer $date Timestamp
  160.      *
  161.      * @return RewardHistoryEvent
  162.      */
  163.     public function setDate($date)
  164.     {
  165.         $this->date $date;
  166.         return $this;
  167.     }
  168.     /**
  169.      * Returns the number of points for the event.
  170.      *
  171.      * @return integer
  172.      */
  173.     public function getPoints()
  174.     {
  175.         return $this->points;
  176.     }
  177.     /**
  178.      * Sets the number of reward points for the event.
  179.      *
  180.      * @param integer $points Number of points
  181.      *
  182.      * @return RewardHistoryEvent
  183.      */
  184.     public function setPoints($points)
  185.     {
  186.         $this->points $points;
  187.         return $this;
  188.     }
  189.     /**
  190.      * Returns the event reason.
  191.      *
  192.      * @return string
  193.      */
  194.     public function getReason()
  195.     {
  196.         return $this->reason;
  197.     }
  198.     /**
  199.      * Sets the event reason.
  200.      *
  201.      * @param string $reason Short description
  202.      *
  203.      * @return RewardHistoryEvent
  204.      */
  205.     public function setReason($reason)
  206.     {
  207.         $this->reason $reason;
  208.         return $this;
  209.     }
  210.     /**
  211.      * Returns the event comment.
  212.      *
  213.      * @return string
  214.      */
  215.     public function getComment()
  216.     {
  217.         return $this->comment;
  218.     }
  219.     /**
  220.      * Sets comments for the event.
  221.      *
  222.      * @param string $comment Short text
  223.      *
  224.      * @return RewardHistoryEvent
  225.      */
  226.     public function setComment($comment)
  227.     {
  228.         $this->comment $comment;
  229.         return $this;
  230.     }
  231.     /**
  232.      * Returns the user profile associated with the event.
  233.      *
  234.      * @return \XLite\Model\Profile
  235.      */
  236.     public function getUser()
  237.     {
  238.         return $this->user;
  239.     }
  240.     /**
  241.      * Associates a user profile with the event.
  242.      *
  243.      * @param \XLite\Model\Profile $user User profile
  244.      *
  245.      * @return RewardHistoryEvent
  246.      */
  247.     public function setUser(\XLite\Model\Profile $user null)
  248.     {
  249.         $this->user $user;
  250.         return $this;
  251.     }
  252.     /**
  253.      * Returns the profile for the user who initiated the event.
  254.      *
  255.      * @return \XLite\Model\Profile
  256.      */
  257.     public function getInitiator()
  258.     {
  259.         return $this->initiator;
  260.     }
  261.     /**
  262.      * Associates the event with the user who initiated the event.
  263.      *
  264.      * @param \XLite\Model\Profile $initiator User profile
  265.      *
  266.      * @return RewardHistoryEvent
  267.      */
  268.     public function setInitiator(\XLite\Model\Profile $initiator null)
  269.     {
  270.         $this->initiator $initiator;
  271.         return $this;
  272.     }
  273.     /**
  274.      * Returns the order for the event.
  275.      *
  276.      * @return \XLite\Model\Order
  277.      */
  278.     public function getOrder()
  279.     {
  280.         return $this->order;
  281.     }
  282.     /**
  283.      * Associates an order with the event.
  284.      *
  285.      * @param \XLite\Model\Order $order Order
  286.      *
  287.      * @return RewardHistoryEvent
  288.      */
  289.     public function setOrder(\XLite\Model\Order $order null)
  290.     {
  291.         $this->order $order;
  292.         return $this;
  293.     }
  294. }